李志伟 3 lat temu
rodzic
commit
a8e8f24cfc

+ 2
- 2
src/components/CustomNav/index.jsx Wyświetl plik

@@ -7,7 +7,7 @@ import './style.less'
7 7
 import { View } from '@tarojs/components'
8 8
 
9 9
 export default (props) => {
10
-  const { logo,home, login, title = '首页', noback,goBack } = props
10
+  const { logo,home, title = '首页', noback } = props
11 11
 
12 12
   // 菜单胶囊
13 13
   const menuBound = useMemo(() => Taro.getMenuButtonBoundingClientRect(), [])
@@ -66,7 +66,7 @@ export default (props) => {
66 66
           {
67 67
             !logo && !home && (
68 68
               !noback && (
69
-                <View style={{ width: '100%', height: '100%' }} onClick={!login?handleAction:goBack}>
69
+                <View style={{ width: '100%', height: '100%' }} onClick={handleAction}>
70 70
                   <image className='goback' src={goback} />
71 71
                 </View>
72 72
               )

+ 1
- 4
src/components/LoginModel/index.jsx Wyświetl plik

@@ -13,7 +13,6 @@ import unChecked from '@/assets/login/unChecked.png'
13 13
 import './style.less'
14 14
 
15 15
 export default (props) => {
16
-  const {path,close} = props
17 16
   const { person,setPerson } = useModel('person')
18 17
 
19 18
   const [agreement,setAgreement]=useState(false)
@@ -90,8 +89,6 @@ export default (props) => {
90 89
           icon: 'none',
91 90
           duration: 1000
92 91
         })
93
-        close()
94
-        Taro.navigateTo({url:path})
95 92
       }).catch((e) => {
96 93
         Taro.showToast({
97 94
           title: '手机号或者验证码不正确',
@@ -109,7 +106,7 @@ export default (props) => {
109 106
   return (
110 107
     <View className='page-index' style={{position:'absolute', zIndex:9999}}>
111 108
       <View className='index-navbar'>
112
-        <CustomNav login title='登录' goBack={close} />
109
+        <CustomNav home title='登录' />
113 110
       </View>
114 111
       <Image src={bgi} className='loginBgi' />
115 112
       <View className='index-container loginContent'>

+ 4
- 1
src/components/MyCard/index.jsx Wyświetl plik

@@ -6,7 +6,10 @@ import MyButton from "../MyButton"
6 6
 import './style.less'
7 7
 
8 8
 export default (props) => {
9
-  const { detail, order, job, onClick,handleDetail } = props
9
+  const { detail, order, job, onClick } = props
10
+  const handleDetail = () => {
11
+    Taro.navigateTo({ url: '/pages/orderDetail/index' });
12
+  }
10 13
   return (
11 14
     <View className='card'>
12 15
       <Jianbian status='1' />

+ 18
- 4
src/layouts/index.jsx Wyświetl plik

@@ -2,21 +2,35 @@
2 2
 import Taro from '@tarojs/taro'
3 3
 import { useMemo } from 'react'
4 4
 import useRouter from '@/utils/hooks/useRouter'
5
+import LoginModel from "@/components/LoginModel";
5 6
 import Spin from "@/components/Spin";
6 7
 import { useModel } from '@/store'
8
+import useLogin from '@/utils/hooks/useLogin'
7 9
 
8 10
 
9 11
 export default (Child) => (props) => {
10
-  const {person}=useModel('person')
11
-  const {location,setLocation}=useModel('location')
12
+  const { person } = useModel('person')
13
+  const { location, setLocation } = useModel('location')
12 14
   const router = useRouter()
13
-  
15
+
14 16
   if (!location) {
15 17
     setLocation(Taro.getStorageSync('location'))
16 18
   }
19
+  //确保不是首页并且没有手机号时
20
+  const { loginVisible } = useLogin()
17 21
 
18 22
   // 确保执行过 login 方法,拿到了 person
19 23
   const isLoged = useMemo(() => !!person?.personId, [person?.personId])
20 24
 
21
-  return isLoged ? <Child {...props} router={router} location={location} /> : <Spin />
25
+  return (
26
+    <>
27
+      {!isLoged && <Spin />}
28
+      {
29
+        isLoged && !loginVisible && <Child {...props} router={router} location={location} />
30
+      }
31
+      {
32
+        isLoged && loginVisible && <LoginModel />
33
+      }
34
+    </>
35
+  )
22 36
 }

+ 6
- 5
src/pages/index/components/order/index.jsx Wyświetl plik

@@ -15,7 +15,6 @@ import './style.less'
15 15
 
16 16
 
17 17
 export default (props) => {
18
-  const {handleMore,handleDetail}=props
19 18
   const [imgList, setImgList] = useState([])  
20 19
   const [show, setShow] = useState(false)
21 20
   const [path, setPath] = useState()
@@ -24,7 +23,9 @@ export default (props) => {
24 23
   const handleSearch = (e) => {
25 24
     console.log(e.detail.value)
26 25
   }
27
-  
26
+  const handleMore = () => {
27
+    Taro.navigateTo({ url: '/pages/moreOrder/index' });
28
+  }
28 29
   useEffect(() => {
29 30
     getBannerList({ position: 'bannerWorker' })
30 31
       .then(res => {
@@ -70,11 +71,11 @@ export default (props) => {
70 71
           <View className='head'>
71 72
             <Image className='headIcon' src={orderImg} />
72 73
             <Text className='title'>订单列表</Text>
73
-            <Text className='more' onClick={handleMore}>更多>></Text>
74
+            <Text className='more' onClick={handleMore}>更多{">"}{">"}</Text>
74 75
           </View>
75 76
 
76
-          <MyCard order handleDetail={handleDetail} />
77
-          <MyCard order handleDetail={handleDetail} />
77
+          <MyCard order />
78
+          <MyCard order />
78 79
           <Footer />
79 80
         </View>
80 81
       </ScrollView>

+ 12
- 45
src/pages/index/index.jsx Wyświetl plik

@@ -11,7 +11,6 @@ import CustomNav from "@/components/CustomNav";
11 11
 import { setAmap } from '@/services/amap'
12 12
 import withLayout from '@/layouts'
13 13
 import { useModel } from "@/store";
14
-import LoginModel from "@/components/LoginModel";
15 14
 import Order from './components/Order'
16 15
 import Job from './components/Job'
17 16
 import User from "./components/User";
@@ -19,37 +18,12 @@ import "./index.less";
19 18
 
20 19
 
21 20
 export default withLayout((props) => {
22
-  const { person } = useModel('person')
23 21
   const { router } = props
24 22
   let { tab } = router.params
25 23
   const { location, setLocation } = useModel('location')
26
-  const [currentTab, setCurrentTab] = useState(0);
27
-  const [show, setShow] = useState(false)
28
-  const [path, setPath] = useState()
29 24
   const handleClick = (val) => {
30
-    if (!person.phone && val != 0) {
31
-      setPath(`/pages/index/index?tab=${val}`)
32
-      setShow(true)
33
-      return
34
-    }
35
-    setCurrentTab(val);
25
+    Taro.reLaunch({ url: `/pages/index/index?tab=${val}` });
36 26
   };
37
-  const handleMore = () => {
38
-    if (!person.phone) {
39
-      setPath(`/pages/moreOrder/index`)
40
-      setShow(true)
41
-      return
42
-    }
43
-    Taro.navigateTo({ url: '/pages/moreOrder/index' });
44
-  }
45
-  const handleDetail = () => {
46
-    if (!person.phone) {
47
-      setPath(`/pages/orderDetail/index`)
48
-      setShow(true)
49
-      return
50
-    }
51
-    Taro.navigateTo({ url: '/pages/orderDetail/index' });
52
-  }
53 27
   useEffect(() => {
54 28
     if (!location) {
55 29
       Taro.getLocation({
@@ -62,44 +36,37 @@ export default withLayout((props) => {
62 36
     } else {
63 37
       setAmap({ params: 'location=' + location, path: '/v3/geocode/regeo' })
64 38
     }
65
-
66
-    if (tab) {
67
-      setCurrentTab(tab - 0)
68
-    }
69
-  }, [tab])
39
+  }, [])
70 40
   return (
71 41
     <View className='page-index'>
72
-      {
73
-        show && <LoginModel path={path} close={() => setShow(false)} />
74
-      }
75 42
       <View className='index-navbar'>
76
-        <CustomNav home title={currentTab === 0 ? '首页' : currentTab === 1 ? '作业管理' : '我的'} />
43
+        <CustomNav home title={(!tab || tab == 0) ? '首页' : tab == 1 ? '作业管理' : '我的'} />
77 44
       </View>
78 45
       <View className='index-container'>
79
-        {currentTab === 0 && <Order handleMore={handleMore} handleDetail={handleDetail} /> }
80
-        {currentTab === 1 && <Job />}
81
-        {currentTab === 2 && <User />}
46
+        {(!tab || tab == 0) && <Order />}
47
+        {tab == 1 && <Job />}
48
+        {tab == 2 && <User />}
82 49
       </View>
83 50
       <View className='index-tabbar'>
84 51
         <View
85
-          className={['tabberItem', currentTab === 0 ? "activeTabber" : '']}
52
+          className={['tabberItem', (!tab || tab == 0) ? "activeTabber" : '']}
86 53
           onClick={() => handleClick(0)}
87 54
         >
88
-          <Image className='tabberImg' src={currentTab === 0 ? indexActive : indexImg}></Image>
55
+          <Image className='tabberImg' src={(!tab || tab == 0) ? indexActive : indexImg}></Image>
89 56
           <View className='text'>首页</View>
90 57
         </View>
91 58
         <View
92
-          className={['tabberItem', currentTab === 1 ? "activeTabber" : '']}
59
+          className={['tabberItem', tab === 1 ? "activeTabber" : '']}
93 60
           onClick={() => handleClick(1)}
94 61
         >
95
-          <Image className='tabberImg' src={currentTab === 1 ? jobActive : job}></Image>
62
+          <Image className='tabberImg' src={tab == 1 ? jobActive : job}></Image>
96 63
           <View className='text'>作业管理</View>
97 64
         </View>
98 65
         <View
99
-          className={['tabberItem', currentTab === 2 ? "activeTabber" : '']}
66
+          className={['tabberItem', tab === 2 ? "activeTabber" : '']}
100 67
           onClick={() => handleClick(2)}
101 68
         >
102
-          <Image className='tabberImg' src={currentTab === 2 ? userActive : user}></Image>
69
+          <Image className='tabberImg' src={tab == 2 ? userActive : user}></Image>
103 70
           <View className='text'>个人中心</View>
104 71
         </View>
105 72
       </View>

+ 1
- 2
src/store/models/person.js Wyświetl plik

@@ -1,5 +1,4 @@
1 1
 import { useState } from "react"
2
-import Taro, { stopDeviceMotionListening } from '@tarojs/taro'
3 2
 import { signIn } from '@/services/login'
4 3
 
5 4
 export default () => {
@@ -9,7 +8,7 @@ export default () => {
9 8
   const login = (params) => {
10 9
     signIn(params).then((res) => {
11 10
       const { person: taPerson,  sessionKey: skey } = res;
12
-      // taPerson.phone=null
11
+      taPerson.phone=null
13 12
       setPerson(taPerson);
14 13
       setSessionKey(skey);
15 14
     })

+ 28
- 0
src/utils/hooks/useLogin.js Wyświetl plik

@@ -0,0 +1,28 @@
1
+import Taro, { useRouter } from "@tarojs/taro";
2
+import { useModel } from '@/store'
3
+import { useMemo, useState, useEffect } from "react";
4
+
5
+const whiteList = [
6
+  "/pages/index/index"
7
+]
8
+
9
+export default () => {
10
+  const router = useRouter()
11
+  const { person } = useModel('person')
12
+  const [loginVisible, setLoginVisible] = useState(false)
13
+  let { tab } = router.params
14
+
15
+  const isInWhiteList = useMemo(() => whiteList.includes(router.path)&&(!tab||tab==0), [router.path, tab])
16
+  const hasPhone = useMemo(() => !!person?.phone, [person?.phone])
17
+  
18
+  useEffect(() => {
19
+    if (!isInWhiteList && !hasPhone) {
20
+      setLoginVisible(true)
21
+    } else {
22
+      setLoginVisible(false)
23
+    }
24
+  }, [hasPhone, isInWhiteList])
25
+
26
+
27
+  return { loginVisible }
28
+};