李志伟 3 years ago
parent
commit
fe9778f004

+ 1
- 1
src/pages/index/components/User/index.jsx View File

42
   }
42
   }
43
   const signOut = () => {
43
   const signOut = () => {
44
     setPhone()
44
     setPhone()
45
-    Taro.reLaunch({ url: '/pages/index/index?tab=2' });
45
+    Taro.reLaunch({ url: '/pages/login/index' });
46
   }
46
   }
47
   return (
47
   return (
48
     <ScrollView scrollY style={{ height: '100%' }}>
48
     <ScrollView scrollY style={{ height: '100%' }}>

+ 13
- 7
src/pages/index/index.jsx View File

8
 import user from "@/assets/comm/user.png";
8
 import user from "@/assets/comm/user.png";
9
 import userActive from "@/assets/comm/userActive.png";
9
 import userActive from "@/assets/comm/userActive.png";
10
 import CustomNav from "@/components/CustomNav";
10
 import CustomNav from "@/components/CustomNav";
11
+import {setAmap} from '@/services/amap'
11
 import withLayout from '@/layouts'
12
 import withLayout from '@/layouts'
12
 import { useModel } from "@/store";
13
 import { useModel } from "@/store";
13
 import Order from './components/Order'
14
 import Order from './components/Order'
18
 export default withLayout((props) => {
19
 export default withLayout((props) => {
19
   const { router } = props
20
   const { router } = props
20
   let { tab, isLogin } = router.params
21
   let { tab, isLogin } = router.params
21
-  const { phone } = useModel('phone')
22
+  const { location,setLocation } = useModel('location')
22
   const [currentTab, setCurrentTab] = useState(0);
23
   const [currentTab, setCurrentTab] = useState(0);
23
   const handleClick = (val) => {
24
   const handleClick = (val) => {
24
     setCurrentTab(val);
25
     setCurrentTab(val);
25
   };
26
   };
26
-  useEffect(() => {    
27
+  useEffect(() => {  
28
+    if(!location){
29
+      Taro.getLocation({
30
+        type:'gcj02',
31
+        success:function(res){
32
+          setLocation(res.longitude+','+res.latitude)
33
+          setAmap({params:'location='+res.longitude+','+res.latitude,path: '/v3/geocode/regeo'})
34
+        }})
35
+    } else {
36
+      setAmap({params:'location='+location,path: '/v3/geocode/regeo'})
37
+    }
27
     if (tab) {      
38
     if (tab) {      
28
       setCurrentTab(tab - 0)
39
       setCurrentTab(tab - 0)
29
     }
40
     }
30
   }, [tab])
41
   }, [tab])
31
-  useEffect(()=>{
32
-    if (currentTab!==0&&!phone) {
33
-      Taro.reLaunch({ url: '/pages/login/index' });
34
-    }
35
-  },[currentTab])
36
   return (
42
   return (
37
     <View className='page-index'>
43
     <View className='page-index'>
38
       <View className='index-navbar'>
44
       <View className='index-navbar'>

+ 10
- 0
src/pages/machineryList/index.jsx View File

1
+import { useEffect } from "react"
1
 import Taro from "@tarojs/taro"
2
 import Taro from "@tarojs/taro"
2
 import { View, ScrollView } from "@tarojs/components"
3
 import { View, ScrollView } from "@tarojs/components"
3
 import CustomNav from "@/components/CustomNav"
4
 import CustomNav from "@/components/CustomNav"
4
 import withLayout from '@/layouts'
5
 import withLayout from '@/layouts'
6
+import {getMachineryList} from '@/services/machinery'
7
+import { useModel } from "@/store"
5
 import MachineryCard from './Card'
8
 import MachineryCard from './Card'
6
 import './style.less'
9
 import './style.less'
7
 
10
 
8
 export default withLayout((props) => {
11
 export default withLayout((props) => {
12
+  const { location } = useModel('location')
13
+
9
   const goDetail=()=>{
14
   const goDetail=()=>{
10
     Taro.navigateTo({ url: '/pages/machineryDetail/index' });
15
     Taro.navigateTo({ url: '/pages/machineryDetail/index' });
11
   }
16
   }
12
   const goMap=()=>{
17
   const goMap=()=>{
13
     Taro.navigateTo({ url: '/pages/machineryMap/index' });
18
     Taro.navigateTo({ url: '/pages/machineryMap/index' });
14
   }
19
   }
20
+  useEffect(()=>{
21
+    getMachineryList({location:location}).then((res)=>{
22
+      
23
+    })
24
+  },[])
15
   return (
25
   return (
16
     <View className='page-index'>
26
     <View className='page-index'>
17
       <View className='index-navbar'>
27
       <View className='index-navbar'>

+ 2
- 2
src/pages/machineryMap/index.jsx View File

45
       </View>
45
       </View>
46
       <View className='index-container machineryMap'>
46
       <View className='index-container machineryMap'>
47
         <Map
47
         <Map
48
-          longitude={112.116846}
49
-          latitude={32.688935}
48
+          longitude={112.092716}
49
+          latitude={32.681642}
50
           markers={markers}
50
           markers={markers}
51
           className='map'
51
           className='map'
52
           onMarkerTap={handleClick}
52
           onMarkerTap={handleClick}

+ 8
- 0
src/services/amap.js View File

1
+import request from '@/utils/request'
2
+
3
+/**
4
+ * 高德地图接口
5
+ * @param {*} data 
6
+ * @returns 
7
+ */
8
+ export const setAmap = (params) => request('/amap', { method: 'post', params })

+ 3
- 1
src/store/index.js View File

1
 import { createStore, createStoreRoot, createModelHook } from '@zjxpcyc/react-tiny-store'
1
 import { createStore, createStoreRoot, createModelHook } from '@zjxpcyc/react-tiny-store'
2
 import phone from './models/phone'
2
 import phone from './models/phone'
3
 import person from './models/person'
3
 import person from './models/person'
4
+import location from './models/location'
4
 
5
 
5
 const store = createStore()
6
 const store = createStore()
6
 const models = {
7
 const models = {
7
   phone,
8
   phone,
8
-  person
9
+  person,
10
+  location
9
 }
11
 }
10
 
12
 
11
 const useModel = createModelHook(store)
13
 const useModel = createModelHook(store)

+ 10
- 0
src/store/models/location.js View File

1
+import { useState } from "react";
2
+
3
+export default function useHotel() {
4
+  const [location, setLocation] = useState()
5
+
6
+  return {
7
+    location,
8
+    setLocation,
9
+  }
10
+}