李志伟 3 年前
父节点
当前提交
fe9778f004

+ 1
- 1
src/pages/index/components/User/index.jsx 查看文件

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

+ 13
- 7
src/pages/index/index.jsx 查看文件

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

+ 10
- 0
src/pages/machineryList/index.jsx 查看文件

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

+ 2
- 2
src/pages/machineryMap/index.jsx 查看文件

@@ -45,8 +45,8 @@ export default withLayout((props) => {
45 45
       </View>
46 46
       <View className='index-container machineryMap'>
47 47
         <Map
48
-          longitude={112.116846}
49
-          latitude={32.688935}
48
+          longitude={112.092716}
49
+          latitude={32.681642}
50 50
           markers={markers}
51 51
           className='map'
52 52
           onMarkerTap={handleClick}

+ 8
- 0
src/services/amap.js 查看文件

@@ -0,0 +1,8 @@
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 查看文件

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

+ 10
- 0
src/store/models/location.js 查看文件

@@ -0,0 +1,10 @@
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
+}