李志伟 3 年前
父节点
当前提交
8f06f10785

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

4
 
4
 
5
 export default (Child) => (props) => {
5
 export default (Child) => (props) => {
6
   const router = useRouter()
6
   const router = useRouter()
7
-  return <Child {...props} router={router} />
7
+  const location = Taro.getStorageSync('location')
8
+
9
+  return <Child {...props} router={router} location={location} />
8
 }
10
 }

+ 0
- 7
src/pages/index/components/User/index.jsx 查看文件

44
   const signOut = () => { 
44
   const signOut = () => { 
45
     Taro.reLaunch({ url: '/pages/index/index?tab=2' });
45
     Taro.reLaunch({ url: '/pages/index/index?tab=2' });
46
   }
46
   }
47
-  const handleMap = () => { 
48
-    Taro.reLaunch({ url: '/pages/machineryMap/index' });
49
-  }
50
   return (
47
   return (
51
     <ScrollView scrollY style={{ height: '100%' }}>
48
     <ScrollView scrollY style={{ height: '100%' }}>
52
       {
49
       {
105
         <View className='userBox'>
102
         <View className='userBox'>
106
           <MyCell icon={feedback} action={goto} user handleAction={handleFeedback}>意见反馈</MyCell>
103
           <MyCell icon={feedback} action={goto} user handleAction={handleFeedback}>意见反馈</MyCell>
107
         </View>
104
         </View>
108
-
109
-        <View className='userBox'>
110
-          <MyCell icon={feedback} action={goto} user handleAction={handleMap}>农机地图</MyCell>
111
-        </View>
112
         {
105
         {
113
           isLogin && <View className='signOut' onClick={signOut}>退出登录</View>
106
           isLogin && <View className='signOut' onClick={signOut}>退出登录</View>
114
         }
107
         }

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

4
 import './style.less'
4
 import './style.less'
5
 
5
 
6
 export default (props) => {
6
 export default (props) => {
7
-  const {onClick}=props
7
+  const {onClick,goMap}=props
8
   return (
8
   return (
9
-  <View className='machineryCard' onClick={onClick}>
9
+  <View className='machineryCard'>
10
     <Jianbian status='1' />
10
     <Jianbian status='1' />
11
-    <Image src={banner1} mode='aspectFill' />
12
-    <View className='machineryName'>收割机001--S01</View>
11
+    <Image src={banner1} mode='aspectFill' onClick={onClick} />
12
+    <View className='info'>
13
+      <View className='machineryName' onClick={onClick} >收割机001--S01</View>
14
+      <View className='goMap' onClick={goMap}>进入地图 {">"}{">"}</View>
15
+    </View>    
13
   </View>
16
   </View>
14
   )
17
   )
15
 }
18
 }

+ 13
- 5
src/pages/machineryList/Card/style.less 查看文件

1
 .machineryCard{
1
 .machineryCard{
2
-  height: 594px;
3
   background: #FFF;
2
   background: #FFF;
4
   box-shadow: 0px 0px 44px 0px rgba(0, 0, 0, 0.08);
3
   box-shadow: 0px 0px 44px 0px rgba(0, 0, 0, 0.08);
5
   border-radius: 40px;
4
   border-radius: 40px;
10
     height: calc(calc(100vw - 60px) * 0.66);
9
     height: calc(calc(100vw - 60px) * 0.66);
11
     width: 100%;
10
     width: 100%;
12
   }
11
   }
13
-  .machineryName{
14
-    font-size: 36px;
12
+  .info{
15
     font-weight: bold;
13
     font-weight: bold;
16
-    color: #222222;
17
-    margin: 39px 0 0 28px;
14
+    display: flex;
15
+    align-items: center;
16
+    margin: 39px 0 60px 28px;
17
+    .machineryName{
18
+      font-size: 36px;
19
+      color: #222222;
20
+    }
21
+    .goMap{
22
+      position: absolute;
23
+      right: 28px;
24
+      color: #666666;
25
+    }
18
   }
26
   }
19
 }
27
 }

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

6
 import './style.less'
6
 import './style.less'
7
 
7
 
8
 export default withLayout((props) => {
8
 export default withLayout((props) => {
9
-  const goMap=()=>{
9
+  const goDetail=()=>{
10
     Taro.navigateTo({ url: '/pages/machineryDetail/index' });
10
     Taro.navigateTo({ url: '/pages/machineryDetail/index' });
11
   }
11
   }
12
+  const goMap=()=>{
13
+    Taro.navigateTo({ url: '/pages/machineryMap/index' });
14
+  }
12
   return (
15
   return (
13
     <View className='page-index'>
16
     <View className='page-index'>
14
       <View className='index-navbar'>
17
       <View className='index-navbar'>
16
       </View>
19
       </View>
17
       <View className='index-container machineryListContent'>
20
       <View className='index-container machineryListContent'>
18
         <ScrollView scrollY style={{ height: '100%' }}>
21
         <ScrollView scrollY style={{ height: '100%' }}>
19
-          <MachineryCard onClick={()=>goMap()} />
22
+          <MachineryCard onClick={()=>goDetail()}  goMap={()=>goMap()} />
20
           <MachineryCard />
23
           <MachineryCard />
21
           <MachineryCard />
24
           <MachineryCard />
22
         </ScrollView>
25
         </ScrollView>

+ 37
- 33
src/pages/machineryMap/index.jsx 查看文件

1
 import Taro from "@tarojs/taro"
1
 import Taro from "@tarojs/taro"
2
 import { useState } from "react"
2
 import { useState } from "react"
3
-import { View, Map,Image } from "@tarojs/components"
3
+import { View, Map, Image } from "@tarojs/components"
4
 import withLayout from '@/layouts'
4
 import withLayout from '@/layouts'
5
 import CustomNav from "@/components/CustomNav"
5
 import CustomNav from "@/components/CustomNav"
6
 import m1 from '@/assets/machinery/greenMachinery.png'
6
 import m1 from '@/assets/machinery/greenMachinery.png'
9
 import './style.less'
9
 import './style.less'
10
 
10
 
11
 export default withLayout((props) => {
11
 export default withLayout((props) => {
12
-  const [show,setShow]=useState(false)
13
-  const markers=[
12
+  const [show, setShow] = useState(false)
13
+  const markers = [
14
     {
14
     {
15
-      id:1,
16
-      longitude:112.105348,
17
-      latitude:32.697352,
18
-      iconPath:m1,
19
-      width:50,
20
-      height:50
15
+      id: 1,
16
+      longitude: 112.105348,
17
+      latitude: 32.697352,
18
+      iconPath: m1,
19
+      width: 50,
20
+      height: 50
21
     },
21
     },
22
     {
22
     {
23
-      id:2,
24
-      longitude:112.120295,
25
-      latitude:32.686656,
26
-      iconPath:m2,      
27
-      width:50,
28
-      height:50
23
+      id: 2,
24
+      longitude: 112.120295,
25
+      latitude: 32.686656,
26
+      iconPath: m2,
27
+      width: 50,
28
+      height: 50
29
     }
29
     }
30
   ]
30
   ]
31
-  const handleClick=(e)=>{
31
+  const handleClick = (e) => {
32
     console.log(e.markerId)
32
     console.log(e.markerId)
33
     setShow(true)
33
     setShow(true)
34
   }
34
   }
35
-  const goDetail=()=>{
35
+  const goDetail = () => {
36
     Taro.navigateTo({ url: '/pages/machineryDetail/index' });
36
     Taro.navigateTo({ url: '/pages/machineryDetail/index' });
37
   }
37
   }
38
+  const goList=()=>{
39
+    Taro.navigateTo({ url: '/pages/machineryList/index' });
40
+  }
38
   return (
41
   return (
39
     <View className='page-index'>
42
     <View className='page-index'>
40
       <View className='index-navbar'>
43
       <View className='index-navbar'>
41
         <CustomNav title='我的农机' />
44
         <CustomNav title='我的农机' />
42
       </View>
45
       </View>
43
       <View className='index-container machineryMap'>
46
       <View className='index-container machineryMap'>
44
-        <Map 
45
-          longitude={112.116846} 
46
-          latitude={32.688935} 
47
-          markers={markers} 
48
-          className='map' 
47
+        <Map
48
+          longitude={112.116846}
49
+          latitude={32.688935}
50
+          markers={markers}
51
+          className='map'
49
           onMarkerTap={handleClick}
52
           onMarkerTap={handleClick}
50
-          onRegionChange={()=>setShow(false)}
53
+          onRegionChange={() => setShow(false)}
51
         />
54
         />
52
         {
55
         {
53
-          show&&
56
+          show &&
54
           <View className='showModel'>
57
           <View className='showModel'>
55
-          <View className='title'>
56
-            <View className='name'>收割机001--S001</View>
57
-            <View className='action' onClick={goDetail}>详情 {">"}{">"}</View>
58
-          </View>
59
-          <View className='position'>
60
-            <Image src={picon} className='picon' />
61
-            当前位置:&nbsp;&nbsp;邓州市陈楼
58
+            <View className='goList' onClick={goList}>{'<'}{'<'} 农机列表</View>
59
+            <View className='title'>
60
+              <View className='name'>收割机001--S001</View>
61
+              <View className='action' onClick={goDetail}>详情 {">"}{">"}</View>
62
+            </View>
63
+            <View className='position'>
64
+              <Image src={picon} className='picon' />
65
+              当前位置:&nbsp;&nbsp;邓州市陈楼
66
+            </View>
62
           </View>
67
           </View>
63
-        </View>
64
         }
68
         }
65
-        
69
+
66
       </View>
70
       </View>
67
     </View>
71
     </View>
68
   )
72
   )

+ 4
- 1
src/pages/machineryMap/style.less 查看文件

15
     font-weight: bold;
15
     font-weight: bold;
16
     font-size: 30px;
16
     font-size: 30px;
17
     color: #222222;
17
     color: #222222;
18
+    .goList{
19
+      color: #666666;
20
+    }
18
     .title{
21
     .title{
19
       display: flex;
22
       display: flex;
20
       align-items: center;
23
       align-items: center;
21
-      margin-bottom: 40px;
24
+      margin:60px 0 40px;
22
       .name{
25
       .name{
23
         font-size: 36px;
26
         font-size: 36px;
24
       }
27
       }

+ 0
- 20
src/utils/index.js 查看文件

56
   return prefix ? `${prefix}-${s}` : s
56
   return prefix ? `${prefix}-${s}` : s
57
 }
57
 }
58
 
58
 
59
-/**
60
- * 压缩图片
61
- * @param {*} url 
62
- * @returns 
63
- */
64
-export function compressImage(url, typ) {
65
-  if (!url) return url;
66
-
67
-  // GIF 不压缩
68
-  if (url.indexOf('.gif') > -1) return url;
69
-
70
-  const style = typ || 'cmp80'
71
-
72
-  // eslint-disable-next-line no-undef
73
-  if (url.indexOf(OSS) > -1) {
74
-    return `${url}?x-oss-process=style/${style}`.replace('http://', 'https://')
75
-  }
76
-
77
-  return url;
78
-}

+ 126
- 0
src/utils/request.js 查看文件

1
+
2
+import Taro from '@tarojs/taro'
3
+import { getQueryString } from '.'
4
+
5
+const logger = Taro.getRealtimeLogManager()
6
+
7
+export default (url, options) => {
8
+  const { params, skipError, header, ...leftOptions } = options || {}
9
+  const queryStr = getQueryString(params)
10
+
11
+  const urlWithParams = queryStr ? `${url}?${queryStr}` : url;
12
+  const nwUrl = `${HOST}/api/wx${urlWithParams}`
13
+
14
+  const authToken = Taro.getStorageSync('token')
15
+  const tokenHeader = authToken ? { 'X-Authorization-JWT': authToken } : {}
16
+  const nwHeader = {
17
+    ...(header || {}),
18
+    ...tokenHeader,
19
+  }
20
+
21
+  return new Promise((resolve, reject) => {
22
+    Taro.request({
23
+      ...leftOptions,
24
+      url: nwUrl,
25
+      header: nwHeader,
26
+      success: (res) => {
27
+        const { code, message, data, token } = res.data
28
+
29
+        if (token || data?.token) {
30
+          Taro.setStorage({ key: 'token', data: token || data?.token })
31
+        }
32
+
33
+        if (code === 1000) {
34
+          resolve(data)
35
+
36
+        } else {
37
+          console.error(res)
38
+          logger.error(nwUrl)
39
+          logger.error(options)
40
+          logger.error(res)
41
+
42
+          if (!skipError) {
43
+            Taro.showToast({
44
+              title: message || '网络异常',
45
+              icon: 'none',
46
+            })
47
+          }
48
+          reject(message?.indexOf('java') > -1 ? '系统内部错误' : message)
49
+        }
50
+      },
51
+
52
+      fail: (err) => {
53
+        console.error(err)
54
+
55
+        logger.error('网络错误')
56
+        logger.error(nwUrl)
57
+        logger.error(options)
58
+        logger.error(err)
59
+
60
+        const message = err.message || err.errMsg || err
61
+
62
+        if (!skipError) {
63
+          Taro.showToast({
64
+            title: message,
65
+            icon: 'none',
66
+          })
67
+        }
68
+
69
+        reject(message)
70
+      }
71
+    })
72
+  })
73
+}
74
+
75
+
76
+export function uploadFile(filePath) {
77
+
78
+  const authToken = Taro.getStorageSync('token')
79
+  const tokenHeader = authToken ? { 'X-Authorization-JWT': authToken } : {}
80
+
81
+  return new Promise((resolve, reject) => {
82
+    Taro.uploadFile({
83
+      // eslint-disable-next-line no-undef
84
+      url: `${HOST}/api/wx/image`,
85
+      filePath,
86
+      name: 'file',
87
+      header: tokenHeader,
88
+      success: (res) => {
89
+        if (res.errMsg === 'uploadFile:ok') {
90
+          const { code, message, data, token } = JSON.parse(res.data)
91
+
92
+          if (token || data?.token) {
93
+            Taro.setStorage({ key: 'token', data: token || data?.token })
94
+          }
95
+
96
+          if (code === 1000) {
97
+            resolve(data)
98
+          } else {
99
+            console.error(res)
100
+
101
+            logger.error("上传文件失败")
102
+            logger.error(res)
103
+
104
+            reject(message?.indexOf('java') > -1 ? '系统内部错误' : message)
105
+          }
106
+        } else {
107
+          console.error(res)
108
+
109
+          logger.error("上传文件失败")
110
+          logger.error(res)
111
+
112
+          reject(res.errMsg)
113
+        }
114
+      },
115
+      fail: (err) => {
116
+        console.error(err)
117
+
118
+        logger.error("上传文件失败")
119
+        logger.error(err)
120
+
121
+        const message = err.message || err.errMsg || err
122
+        reject(message)
123
+      }
124
+    })
125
+  })
126
+}