李志伟 3 years ago
parent
commit
eb371998a8
2 changed files with 15 additions and 5 deletions
  1. 10
    1
      src/layouts/index.jsx
  2. 5
    4
      src/pages/index/index.jsx

+ 10
- 1
src/layouts/index.jsx View File

1
 
1
 
2
 import Taro from '@tarojs/taro'
2
 import Taro from '@tarojs/taro'
3
+import { useEffect } from 'react'
3
 import useRouter from '@/utils/hooks/useRouter'
4
 import useRouter from '@/utils/hooks/useRouter'
5
+import { useModel } from '@/store'
6
+
4
 
7
 
5
 export default (Child) => (props) => {
8
 export default (Child) => (props) => {
9
+  const {person}=useModel('person')
6
   const router = useRouter()
10
   const router = useRouter()
11
+  
7
   const location = Taro.getStorageSync('location')
12
   const location = Taro.getStorageSync('location')
8
-
13
+  useEffect(()=>{
14
+    if (router.path!=='/pages/index/index'&&!person?.phone) {
15
+      Taro.reLaunch({ url: '/pages/login/index' });
16
+    }
17
+  },[router.path])
9
   return <Child {...props} router={router} location={location} />
18
   return <Child {...props} router={router} location={location} />
10
 }
19
 }

+ 5
- 4
src/pages/index/index.jsx View File

23
   const { location,setLocation } = useModel('location')
23
   const { location,setLocation } = useModel('location')
24
   const [currentTab, setCurrentTab] = useState(0);
24
   const [currentTab, setCurrentTab] = useState(0);
25
   const handleClick = (val) => {
25
   const handleClick = (val) => {
26
+    if (!person.phone) {
27
+      Taro.reLaunch({ url: '/pages/login/index' });
28
+    }      
26
     setCurrentTab(val);
29
     setCurrentTab(val);
27
   };
30
   };
28
   useEffect(() => {  
31
   useEffect(() => {  
36
     } else {
39
     } else {
37
       setAmap({params:'location='+location,path: '/v3/geocode/regeo'})
40
       setAmap({params:'location='+location,path: '/v3/geocode/regeo'})
38
     }
41
     }
39
-    if (currentTab!==0&& person.phone) {
40
-      Taro.reLaunch({ url: '/pages/login/index' });
41
-    }
42
-    if (tab) {      
42
+    
43
+    if (tab) {
43
       setCurrentTab(tab - 0)
44
       setCurrentTab(tab - 0)
44
     }
45
     }
45
   }, [tab])
46
   }, [tab])