李志伟 3 年前
父节点
当前提交
eb371998a8
共有 2 个文件被更改,包括 15 次插入5 次删除
  1. 10
    1
      src/layouts/index.jsx
  2. 5
    4
      src/pages/index/index.jsx

+ 10
- 1
src/layouts/index.jsx 查看文件

@@ -1,10 +1,19 @@
1 1
 
2 2
 import Taro from '@tarojs/taro'
3
+import { useEffect } from 'react'
3 4
 import useRouter from '@/utils/hooks/useRouter'
5
+import { useModel } from '@/store'
6
+
4 7
 
5 8
 export default (Child) => (props) => {
9
+  const {person}=useModel('person')
6 10
   const router = useRouter()
11
+  
7 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 18
   return <Child {...props} router={router} location={location} />
10 19
 }

+ 5
- 4
src/pages/index/index.jsx 查看文件

@@ -23,6 +23,9 @@ export default withLayout((props) => {
23 23
   const { location,setLocation } = useModel('location')
24 24
   const [currentTab, setCurrentTab] = useState(0);
25 25
   const handleClick = (val) => {
26
+    if (!person.phone) {
27
+      Taro.reLaunch({ url: '/pages/login/index' });
28
+    }      
26 29
     setCurrentTab(val);
27 30
   };
28 31
   useEffect(() => {  
@@ -36,10 +39,8 @@ export default withLayout((props) => {
36 39
     } else {
37 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 44
       setCurrentTab(tab - 0)
44 45
     }
45 46
   }, [tab])