李志伟 3 年之前
父節點
當前提交
0b2e620552

+ 2
- 2
src/components/CustomNav/index.jsx 查看文件

@@ -7,7 +7,7 @@ import './style.less'
7 7
 import { View } from '@tarojs/components'
8 8
 
9 9
 export default (props) => {
10
-  const { logo, title = '首页', home, noback } = props
10
+  const { logo,home, login, title = '首页', noback,goBack } = 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={handleAction}>
69
+                <View style={{ width: '100%', height: '100%' }} onClick={!login?handleAction:goBack}>
70 70
                   <image className='goback' src={goback} />
71 71
                 </View>
72 72
               )

src/pages/login/index.jsx → src/components/LoginModel/index.jsx 查看文件

@@ -1,9 +1,8 @@
1 1
 import Taro from "@tarojs/taro"
2 2
 import { useState } from "react"
3 3
 import { useModel } from '@/store'
4
-import { View, Image, Input, Text, Checkbox, Label, Button } from "@tarojs/components"
4
+import { View, Image, Input, Text, Button } from "@tarojs/components"
5 5
 import CustomNav from "@/components/CustomNav"
6
-import withLayout from '@/layouts'
7 6
 import MyButton from "@/components/MyButton"
8 7
 import {updatePhone, setQcode } from '@/services/login'
9 8
 import bgi from '@/assets/login/loginImg.png'
@@ -13,7 +12,8 @@ import unChecked from '@/assets/login/unChecked.png'
13 12
 
14 13
 import './style.less'
15 14
 
16
-export default withLayout((props) => {
15
+export default (props) => {
16
+  const {path,close} = props
17 17
   const { person,setPerson } = useModel('person')
18 18
 
19 19
   const [agreement,setAgreement]=useState(false)
@@ -90,7 +90,8 @@ export default withLayout((props) => {
90 90
           icon: 'none',
91 91
           duration: 1000
92 92
         })
93
-        Taro.navigateBack({ detail:1 });
93
+        close()
94
+        Taro.navigateTo({url:path})
94 95
       }).catch((e) => {
95 96
         Taro.showToast({
96 97
           title: '手机号或者验证码不正确',
@@ -106,9 +107,9 @@ export default withLayout((props) => {
106 107
     }
107 108
   }
108 109
   return (
109
-    <View className='page-index'>
110
+    <View className='page-index' style={{position:'absolute', zIndex:9999}}>
110 111
       <View className='index-navbar'>
111
-        <CustomNav home title='登录' />
112
+        <CustomNav login title='登录' goBack={close} />
112 113
       </View>
113 114
       <Image src={bgi} className='loginBgi' />
114 115
       <View className='index-container loginContent'>
@@ -135,4 +136,4 @@ export default withLayout((props) => {
135 136
       </View>
136 137
     </View>
137 138
   )
138
-})
139
+}

src/pages/login/style.less → src/components/LoginModel/style.less 查看文件

@@ -4,10 +4,20 @@
4 4
   position: absolute;
5 5
   top: 0;
6 6
 }
7
+.goback{
8
+  width: 19px;
9
+  height: 35px;
10
+  position: absolute;
11
+  left: 30px;
12
+  top: 67.5px;
13
+}
7 14
 .loginContent{
8 15
   padding: 60px 30px;
9 16
   color: #333333;
10 17
   font-weight: bold;
18
+  input{
19
+    font-size: 34px;
20
+  }
11 21
   .title1{
12 22
     padding: 40px 0;
13 23
     font-size: 66px;

+ 2
- 8
src/components/MyCard/index.jsx 查看文件

@@ -6,19 +6,13 @@ import MyButton from "../MyButton"
6 6
 import './style.less'
7 7
 
8 8
 export default (props) => {
9
-  const { detail, order, job, onClick } = props
10
-  const handleDetail = () => {
11
-    Taro.navigateTo({ url: '/pages/orderDetail/index' });
12
-  }
13
-  const handleClick = () => {
14
-    Taro.navigateTo({ url: '/pages/orderDetail/index' });
15
-  }
9
+  const { detail, order, job, onClick,handleDetail } = props
16 10
   return (
17 11
     <View className='card'>
18 12
       <Jianbian status='1' />
19 13
       <View className='cardHead'>
20 14
         {
21
-          job && <MyCell header='需求时间' job action='详情>>' handleAction={handleClick}>2022-06-02</MyCell>
15
+          job && <MyCell header='需求时间' job action='详情>>' handleAction={handleDetail}>2022-06-02</MyCell>
22 16
         }
23 17
         {
24 18
           !job && <>

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

@@ -1,8 +1,7 @@
1 1
 
2 2
 import Taro from '@tarojs/taro'
3
-import { useEffect , useMemo } from 'react'
3
+import { useMemo } from 'react'
4 4
 import useRouter from '@/utils/hooks/useRouter'
5
-import useLogin from '@/utils/hooks/useLogin'
6 5
 import Spin from "@/components/Spin";
7 6
 import { useModel } from '@/store'
8 7
 
@@ -13,16 +12,6 @@ export default (Child) => (props) => {
13 12
   
14 13
   const location = Taro.getStorageSync('location')
15 14
 
16
-  const { hasPhone } = useLogin()
17
-
18
-
19
-  // Taro.useReady(()=>{
20
-  //   useLogin(person,router)
21
-  // })
22
-  // useEffect(()=>{
23
-  //   useLogin(person,router)
24
-  // },[person, person?.phone, router, router?.path])
25
-
26 15
   // 确保执行过 login 方法,拿到了 person
27 16
   const isLoged = useMemo(() => !!person?.personId, [person?.personId])
28 17
 

+ 8
- 4
src/pages/index/components/Job/index.jsx 查看文件

@@ -1,3 +1,4 @@
1
+import Taro from "@tarojs/taro";
1 2
 import { View, ScrollView, Image, Button } from "@tarojs/components"
2 3
 import MyCard from "@/components/MyCard"
3 4
 import { Popup } from "@antmjs/vantui";
@@ -17,12 +18,15 @@ export default (props) => {
17 18
     console.log('开始作业')
18 19
     setShow(false)
19 20
   }
21
+  const handleDetail = () => {
22
+    Taro.navigateTo({ url: '/pages/orderDetail/index' });
23
+  }
20 24
   return (
21 25
     <ScrollView scrollY style={{ height: '100%' }}>
22
-      <MyCard job onClick={handleChange} />
23
-      <MyCard job onClick={handleChange} />
24
-      <MyCard job onClick={handleChange} />
25
-      <MyCard job onClick={handleChange} />
26
+      <MyCard job onClick={handleChange} handleDetail={handleDetail} />
27
+      <MyCard job onClick={handleChange} handleDetail={handleDetail} />
28
+      <MyCard job onClick={handleChange} handleDetail={handleDetail} />
29
+      <MyCard job onClick={handleChange} handleDetail={handleDetail} />
26 30
       <Popup
27 31
         show={show}
28 32
         onClose={onClose}

+ 15
- 7
src/pages/index/components/order/index.jsx 查看文件

@@ -4,22 +4,27 @@ import { View, Input, Swiper, Image, SwiperItem, Text, ScrollView } from "@taroj
4 4
 import positionImg from '@/assets/comm/position.png'
5 5
 import searchImg from '@/assets/comm/search.png'
6 6
 import orderImg from '@/assets/comm/orderList.png'
7
+import LoginModel from "@/components/LoginModel";
7 8
 import Footer from "@/components/Footer";
8 9
 import MyCard from "@/components/MyCard";
10
+import { useModel } from "@/store";
9 11
 
10 12
 
11 13
 import { getBannerList } from "@/services/banner";
12 14
 import './style.less'
13 15
 
14 16
 
15
-export default () => {
16
-  const [imgList, setImgList] = useState([])
17
+export default (props) => {
18
+  const {handleMore,handleDetail}=props
19
+  const [imgList, setImgList] = useState([])  
20
+  const [show, setShow] = useState(false)
21
+  const [path, setPath] = useState()
22
+  const { person } = useModel('person')
23
+
17 24
   const handleSearch = (e) => {
18 25
     console.log(e.detail.value)
19 26
   }
20
-  const handleMore = () => {
21
-    Taro.navigateTo({ url: '/pages/moreOrder/index' });
22
-  }
27
+  
23 28
   useEffect(() => {
24 29
     getBannerList({ position: 'bannerWorker' })
25 30
       .then(res => {
@@ -33,6 +38,9 @@ export default () => {
33 38
   }, [])
34 39
   return (
35 40
     <View className='orderIndex'>
41
+      {
42
+        show && <LoginModel path={path} close={() => setShow(false)} />
43
+      }
36 44
       <View className='top'>
37 45
         <View className='left'>
38 46
           <Image src={positionImg} className='pImg' />
@@ -65,8 +73,8 @@ export default () => {
65 73
             <Text className='more' onClick={handleMore}>更多>></Text>
66 74
           </View>
67 75
 
68
-          <MyCard order />
69
-          <MyCard order />
76
+          <MyCard order handleDetail={handleDetail} />
77
+          <MyCard order handleDetail={handleDetail} />
70 78
           <Footer />
71 79
         </View>
72 80
       </ScrollView>

+ 43
- 17
src/pages/index/index.jsx 查看文件

@@ -1,4 +1,4 @@
1
-import Taro from "@tarojs/taro";
1
+import Taro, { useDidShow } from "@tarojs/taro";
2 2
 import { useState, useEffect } from "react";
3 3
 import { View, Image } from "@tarojs/components"
4 4
 import indexImg from "@/assets/comm/index.png";
@@ -8,49 +8,75 @@ 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
+import { setAmap } from '@/services/amap'
12 12
 import withLayout from '@/layouts'
13 13
 import { useModel } from "@/store";
14
+import LoginModel from "@/components/LoginModel";
14 15
 import Order from './components/Order'
15 16
 import Job from './components/Job'
16 17
 import User from "./components/User";
17 18
 import "./index.less";
18 19
 
20
+
19 21
 export default withLayout((props) => {
20
-  const {person}=useModel('person')
22
+  const { person } = useModel('person')
21 23
   const { router } = props
22 24
   let { tab } = router.params
23
-  const { location,setLocation } = useModel('location')
25
+  const { location, setLocation } = useModel('location')
24 26
   const [currentTab, setCurrentTab] = useState(0);
27
+  const [show, setShow] = useState(false)
28
+  const [path, setPath] = useState()
25 29
   const handleClick = (val) => {
26
-    if (!person.phone) {
27
-      Taro.navigateTo({ url: '/pages/login/index' });
28
-    }      
30
+    if (!person.phone && val != 0) {
31
+      setPath(`/pages/index/index?tab=${val}`)
32
+      setShow(true)
33
+      return
34
+    }
29 35
     setCurrentTab(val);
30 36
   };
31
-  useEffect(() => {  
32
-    if(!location){
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(() => {
54
+    if (!location) {
33 55
       Taro.getLocation({
34
-        type:'gcj02',
35
-        success:function(res){
36
-          setLocation(res.longitude+','+res.latitude)
37
-          setAmap({params:'location='+res.longitude+','+res.latitude,path: '/v3/geocode/regeo'})
38
-        }})
56
+        type: 'gcj02',
57
+        success: function (res) {
58
+          setLocation(res.longitude + ',' + res.latitude)
59
+          setAmap({ params: 'location=' + res.longitude + ',' + res.latitude, path: '/v3/geocode/regeo' })
60
+        }
61
+      })
39 62
     } else {
40
-      setAmap({params:'location='+location,path: '/v3/geocode/regeo'})
63
+      setAmap({ params: 'location=' + location, path: '/v3/geocode/regeo' })
41 64
     }
42
-    
65
+
43 66
     if (tab) {
44 67
       setCurrentTab(tab - 0)
45 68
     }
46 69
   }, [tab])
47 70
   return (
48 71
     <View className='page-index'>
72
+      {
73
+        show && <LoginModel path={path} close={() => setShow(false)} />
74
+      }
49 75
       <View className='index-navbar'>
50 76
         <CustomNav home title={currentTab === 0 ? '首页' : currentTab === 1 ? '作业管理' : '我的'} />
51 77
       </View>
52 78
       <View className='index-container'>
53
-        {currentTab === 0 && <Order />}
79
+        {currentTab === 0 && <Order handleMore={handleMore} handleDetail={handleDetail} /> }
54 80
         {currentTab === 1 && <Job />}
55 81
         {currentTab === 2 && <User />}
56 82
       </View>

+ 0
- 7
src/pages/login/index.config.js 查看文件

@@ -1,7 +0,0 @@
1
-export default {
2
-  navigationBarTitleText: '登录',
3
-  navigationStyle: 'custom',
4
-  styleIsolation: 'shared',
5
-  enableShareAppMessage: true,
6
-  disableScroll: true,
7
-}

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

@@ -14,14 +14,14 @@ export default withLayout((props) => {
14 14
   const goDetail = (val) => {
15 15
     Taro.navigateTo({ url: `/pages/machineryDetail/index?id=${val}` });
16 16
   }
17
-  const goMap = () => {
18
-    Taro.navigateTo({ url: '/pages/machineryMap/index' });
17
+  const goMap = (val) => {
18
+    Taro.navigateTo({ url: `/pages/machineryMap/index?id=${val}` });
19 19
   }
20 20
   useEffect(() => {
21 21
     getMachineryList({ location: location }).then((res) => {
22 22
       setMachinery(res.records)
23 23
     })
24
-  }, [])
24
+  }, [location])
25 25
   return (
26 26
     <View className='page-index'>
27 27
       <View className='index-navbar'>
@@ -31,7 +31,7 @@ export default withLayout((props) => {
31 31
         <ScrollView scrollY style={{ height: '100%' }}>
32 32
           {
33 33
             machinery?.map((item) => {
34
-              return <MachineryCard value={item} onClick={() => goDetail(item.machineryId)} goMap={() => goMap()} />
34
+              return <MachineryCard value={item} key={item.machineryId} onClick={() => goDetail(item.machineryId)} goMap={() => goMap(item.machineryId)} />
35 35
             })
36 36
           }
37 37
         </ScrollView>

+ 20
- 0
src/pages/machineryMap/Model/index.jsx 查看文件

@@ -0,0 +1,20 @@
1
+import { View, Image } from "@tarojs/components"
2
+import picon from '@/assets/comm/position.png'
3
+import './style.less'
4
+
5
+export default (props) => {
6
+  const { value,visible, goDetail, goList } = props
7
+  return (
8
+    <View className='showModel' style={{visibility:visible?'inherit':'hidden'}}>
9
+      <View className='goList' onClick={goList}>{'<'}{'<'} 农机列表</View>
10
+      <View className='title'>
11
+        <View className='name'>{value?.name}</View>
12
+        <View className='action' onClick={() => goDetail(value?.machineryId)}>详情 {">"}{">"}</View>
13
+      </View>
14
+      <View className='position'>
15
+        <Image src={picon} className='picon' />
16
+        当前位置:&nbsp;&nbsp;邓州市陈楼
17
+      </View>
18
+    </View>
19
+  )
20
+}

+ 37
- 0
src/pages/machineryMap/Model/style.less 查看文件

@@ -0,0 +1,37 @@
1
+.showModel{
2
+  position: absolute;
3
+  bottom: 0;
4
+  width: 100%;
5
+  box-sizing: border-box;
6
+  background: #FFFFFF;
7
+  border-radius: 40px 40px 0px 0px;
8
+  padding: 60px 30px;
9
+  font-weight: bold;
10
+  font-size: 30px;
11
+  color: #222222;
12
+  .goList{
13
+    color: #666666;
14
+  }
15
+  .title{
16
+    display: flex;
17
+    align-items: center;
18
+    margin:60px 0 40px;
19
+    .name{
20
+      font-size: 36px;
21
+    }
22
+    .action{
23
+      color: #666666;
24
+      position: absolute;
25
+      right: 30px;
26
+    }
27
+  }
28
+  .position{
29
+    display: flex;
30
+    align-items: center;
31
+    .picon{
32
+      width: 34px;
33
+      height: 34px;
34
+      margin-right: 16px;    
35
+    }
36
+  }
37
+}

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

@@ -5,18 +5,22 @@ import withLayout from '@/layouts'
5 5
 import { getMachineryList } from '@/services/machinery'
6 6
 import { useModel } from "@/store"
7 7
 import CustomNav from "@/components/CustomNav"
8
+import MachineryModel from './Model'
8 9
 import m1 from '@/assets/machinery/greenMachinery.png'
9 10
 import m2 from '@/assets/machinery/orangeMachinery.png'
10
-import picon from '@/assets/comm/position.png'
11 11
 import './style.less'
12 12
 
13 13
 
14
-export default withLayout((props) => {
14
+export default withLayout((props) => {  
15
+  const { router } = props
16
+  const { id } = router.params
15 17
   const [show, setShow] = useState(false)
16 18
   const { location } = useModel('location')
17 19
   const [machineryList, setMachineryList] = useState([])
18 20
   const [markerList, setMarkerList] = useState([])
19 21
   const [current, setCurrent] = useState()
22
+  const [lot,setLot]=useState(112.106514)
23
+  const [lat,setLat]=useState(32.685927)
20 24
 
21 25
   const locList = [
22 26
     {
@@ -70,6 +74,22 @@ export default withLayout((props) => {
70 74
   const goList = () => {
71 75
     Taro.navigateTo({ url: '/pages/machineryList/index' });
72 76
   }
77
+  const changeRegion=()=>{
78
+    setShow(false)
79
+  }
80
+  useEffect(()=>{
81
+    if (id&&machineryList&&markerList.length!=0) {
82
+      machineryList.forEach((item,index)=>{
83
+        if(item.machineryId==id){ 
84
+          setLot(markerList[index].longitude)
85
+          setLat(markerList[index].latitude)
86
+          setCurrent(machineryList[index])
87
+          setShow(true)
88
+          return
89
+        }
90
+      })
91
+    }
92
+  },[id, machineryList, markerList])
73 93
   useEffect(() => {
74 94
     getMachineryList({ location: location }).then((res) => {
75 95
       setMachineryList(res.records)
@@ -85,6 +105,7 @@ export default withLayout((props) => {
85 105
       }))
86 106
     })
87 107
   }, [])
108
+
88 109
   return (
89 110
     <View className='page-index'>
90 111
       <View className='index-navbar'>
@@ -92,28 +113,14 @@ export default withLayout((props) => {
92 113
       </View>
93 114
       <View className='index-container machineryMap'>
94 115
         <Map
95
-          longitude={112.092716}
96
-          latitude={32.681642}
116
+          longitude={lot}
117
+          latitude={lat}
97 118
           markers={markerList}
98 119
           className='map'
99 120
           onMarkerTap={handleClick}
100
-          onRegionChange={() => setShow(false)}
121
+          onRegionChange={changeRegion}
101 122
         />
102
-        {
103
-          show &&
104
-          <View className='showModel'>
105
-            <View className='goList' onClick={goList}>{'<'}{'<'} 农机列表</View>
106
-            <View className='title'>
107
-              <View className='name'>{current.name}</View>
108
-              <View className='action' onClick={() => goDetail(current.machineryId)}>详情 {">"}{">"}</View>
109
-            </View>
110
-            <View className='position'>
111
-              <Image src={picon} className='picon' />
112
-              当前位置:&nbsp;&nbsp;邓州市陈楼
113
-            </View>
114
-          </View>
115
-        }
116
-
123
+        <MachineryModel visible={show} value={current} goDetail={goDetail} goList={goList} />
117 124
       </View>
118 125
     </View>
119 126
   )

+ 0
- 37
src/pages/machineryMap/style.less 查看文件

@@ -4,41 +4,4 @@
4 4
     width: 100vw;
5 5
     height: 100%;
6 6
   }  
7
-  .showModel{
8
-    position: absolute;
9
-    bottom: 0;
10
-    width: 100%;
11
-    box-sizing: border-box;
12
-    background: #FFFFFF;
13
-    border-radius: 40px 40px 0px 0px;
14
-    padding: 60px 30px;
15
-    font-weight: bold;
16
-    font-size: 30px;
17
-    color: #222222;
18
-    .goList{
19
-      color: #666666;
20
-    }
21
-    .title{
22
-      display: flex;
23
-      align-items: center;
24
-      margin:60px 0 40px;
25
-      .name{
26
-        font-size: 36px;
27
-      }
28
-      .action{
29
-        color: #666666;
30
-        position: absolute;
31
-        right: 30px;
32
-      }
33
-    }
34
-    .position{
35
-      display: flex;
36
-      align-items: center;
37
-      .picon{
38
-        width: 34px;
39
-        height: 34px;
40
-        margin-right: 16px;    
41
-      }
42
-    }
43
-  }
44 7
 }

+ 0
- 4
src/routes.js 查看文件

@@ -14,10 +14,6 @@ const mainPages = [
14 14
     title: '详情',
15 15
     page: 'pages/orderDetail/index',
16 16
   },
17
-  {
18
-    title: '登录',
19
-    page: 'pages/login/index',
20
-  },
21 17
   {
22 18
     title: '农机列表',
23 19
     page: 'pages/machineryList/index',

+ 1
- 1
src/store/models/person.js 查看文件

@@ -9,7 +9,7 @@ export default () => {
9 9
   const login = (params) => {
10 10
     signIn(params).then((res) => {
11 11
       const { person: taPerson,  sessionKey: skey } = res;
12
-      // taPerson.phone=null
12
+      taPerson.phone=null
13 13
       setPerson(taPerson);
14 14
       setSessionKey(skey);
15 15
     })

+ 0
- 46
src/utils/hooks/useLogin.js 查看文件

@@ -1,46 +0,0 @@
1
-import Taro, { useRouter, useDidShow } from "@tarojs/taro";
2
-import { useModel } from '@/store'
3
-import { useEffect , useMemo } from "react";
4
-
5
-const whiteList = [
6
-  "/pages/login/index",
7
-  "/pages/index/index"
8
-]
9
-
10
-export default () => {
11
-  const router = useRouter()
12
-  const {person} = useModel('person')
13
-
14
-  const isInWhiteList = useMemo(() => whiteList.includes(router.path), [router.path])
15
-  const hasPhone = useMemo(() => !!person?.phone, [person?.phone])
16
-
17
-  // 校验跳转
18
-  // useMemo(() => {
19
-    // if (!isInWhiteList && !hasPhone) {
20
-    //   Taro.navigateTo({ url: "/pages/login/index" });
21
-    // }
22
-  // }, [hasPhone, isInWhiteList])
23
-
24
-  // useDidShow(() => {
25
-  //   if (!isInWhiteList && !isLoged) {
26
-  //     Taro.navigateTo({ url: "/pages/login/index" });
27
-  //   }
28
-  // })
29
-
30
-  useEffect (() => {
31
-    if (!isInWhiteList && !hasPhone) {
32
-      Taro.navigateTo({ url: "/pages/login/index" });
33
-    }
34
-  }, [hasPhone, isInWhiteList])
35
-
36
-
37
-  // if (router.path === "/pages/login/index") {
38
-  //   return;
39
-  // }
40
-  // if (router.path !== "/pages/index/index" && !person?.phone) {
41
-  //   Taro.navigateTo({ url: "/pages/login/index" });
42
-  // }
43
-
44
-
45
-  return { hasPhone, isInWhiteList }
46
-};