李志伟 3 anni fa
parent
commit
a8e8f24cfc

+ 2
- 2
src/components/CustomNav/index.jsx Vedi File

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

+ 1
- 4
src/components/LoginModel/index.jsx Vedi File

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

+ 4
- 1
src/components/MyCard/index.jsx Vedi File

6
 import './style.less'
6
 import './style.less'
7
 
7
 
8
 export default (props) => {
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
   return (
13
   return (
11
     <View className='card'>
14
     <View className='card'>
12
       <Jianbian status='1' />
15
       <Jianbian status='1' />

+ 18
- 4
src/layouts/index.jsx Vedi File

2
 import Taro from '@tarojs/taro'
2
 import Taro from '@tarojs/taro'
3
 import { useMemo } from 'react'
3
 import { useMemo } from 'react'
4
 import useRouter from '@/utils/hooks/useRouter'
4
 import useRouter from '@/utils/hooks/useRouter'
5
+import LoginModel from "@/components/LoginModel";
5
 import Spin from "@/components/Spin";
6
 import Spin from "@/components/Spin";
6
 import { useModel } from '@/store'
7
 import { useModel } from '@/store'
8
+import useLogin from '@/utils/hooks/useLogin'
7
 
9
 
8
 
10
 
9
 export default (Child) => (props) => {
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
   const router = useRouter()
14
   const router = useRouter()
13
-  
15
+
14
   if (!location) {
16
   if (!location) {
15
     setLocation(Taro.getStorageSync('location'))
17
     setLocation(Taro.getStorageSync('location'))
16
   }
18
   }
19
+  //确保不是首页并且没有手机号时
20
+  const { loginVisible } = useLogin()
17
 
21
 
18
   // 确保执行过 login 方法,拿到了 person
22
   // 确保执行过 login 方法,拿到了 person
19
   const isLoged = useMemo(() => !!person?.personId, [person?.personId])
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 Vedi File

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

+ 12
- 45
src/pages/index/index.jsx Vedi File

11
 import { setAmap } from '@/services/amap'
11
 import { setAmap } from '@/services/amap'
12
 import withLayout from '@/layouts'
12
 import withLayout from '@/layouts'
13
 import { useModel } from "@/store";
13
 import { useModel } from "@/store";
14
-import LoginModel from "@/components/LoginModel";
15
 import Order from './components/Order'
14
 import Order from './components/Order'
16
 import Job from './components/Job'
15
 import Job from './components/Job'
17
 import User from "./components/User";
16
 import User from "./components/User";
19
 
18
 
20
 
19
 
21
 export default withLayout((props) => {
20
 export default withLayout((props) => {
22
-  const { person } = useModel('person')
23
   const { router } = props
21
   const { router } = props
24
   let { tab } = router.params
22
   let { tab } = router.params
25
   const { location, setLocation } = useModel('location')
23
   const { location, setLocation } = useModel('location')
26
-  const [currentTab, setCurrentTab] = useState(0);
27
-  const [show, setShow] = useState(false)
28
-  const [path, setPath] = useState()
29
   const handleClick = (val) => {
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
   useEffect(() => {
27
   useEffect(() => {
54
     if (!location) {
28
     if (!location) {
55
       Taro.getLocation({
29
       Taro.getLocation({
62
     } else {
36
     } else {
63
       setAmap({ params: 'location=' + location, path: '/v3/geocode/regeo' })
37
       setAmap({ params: 'location=' + location, path: '/v3/geocode/regeo' })
64
     }
38
     }
65
-
66
-    if (tab) {
67
-      setCurrentTab(tab - 0)
68
-    }
69
-  }, [tab])
39
+  }, [])
70
   return (
40
   return (
71
     <View className='page-index'>
41
     <View className='page-index'>
72
-      {
73
-        show && <LoginModel path={path} close={() => setShow(false)} />
74
-      }
75
       <View className='index-navbar'>
42
       <View className='index-navbar'>
76
-        <CustomNav home title={currentTab === 0 ? '首页' : currentTab === 1 ? '作业管理' : '我的'} />
43
+        <CustomNav home title={(!tab || tab == 0) ? '首页' : tab == 1 ? '作业管理' : '我的'} />
77
       </View>
44
       </View>
78
       <View className='index-container'>
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
       </View>
49
       </View>
83
       <View className='index-tabbar'>
50
       <View className='index-tabbar'>
84
         <View
51
         <View
85
-          className={['tabberItem', currentTab === 0 ? "activeTabber" : '']}
52
+          className={['tabberItem', (!tab || tab == 0) ? "activeTabber" : '']}
86
           onClick={() => handleClick(0)}
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
           <View className='text'>首页</View>
56
           <View className='text'>首页</View>
90
         </View>
57
         </View>
91
         <View
58
         <View
92
-          className={['tabberItem', currentTab === 1 ? "activeTabber" : '']}
59
+          className={['tabberItem', tab === 1 ? "activeTabber" : '']}
93
           onClick={() => handleClick(1)}
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
           <View className='text'>作业管理</View>
63
           <View className='text'>作业管理</View>
97
         </View>
64
         </View>
98
         <View
65
         <View
99
-          className={['tabberItem', currentTab === 2 ? "activeTabber" : '']}
66
+          className={['tabberItem', tab === 2 ? "activeTabber" : '']}
100
           onClick={() => handleClick(2)}
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
           <View className='text'>个人中心</View>
70
           <View className='text'>个人中心</View>
104
         </View>
71
         </View>
105
       </View>
72
       </View>

+ 1
- 2
src/store/models/person.js Vedi File

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

+ 28
- 0
src/utils/hooks/useLogin.js Vedi File

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
+};