李志伟 3 年之前
父節點
當前提交
8f06f10785

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

@@ -4,5 +4,7 @@ import useRouter from '@/utils/hooks/useRouter'
4 4
 
5 5
 export default (Child) => (props) => {
6 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,9 +44,6 @@ export default (props) => {
44 44
   const signOut = () => { 
45 45
     Taro.reLaunch({ url: '/pages/index/index?tab=2' });
46 46
   }
47
-  const handleMap = () => { 
48
-    Taro.reLaunch({ url: '/pages/machineryMap/index' });
49
-  }
50 47
   return (
51 48
     <ScrollView scrollY style={{ height: '100%' }}>
52 49
       {
@@ -105,10 +102,6 @@ export default (props) => {
105 102
         <View className='userBox'>
106 103
           <MyCell icon={feedback} action={goto} user handleAction={handleFeedback}>意见反馈</MyCell>
107 104
         </View>
108
-
109
-        <View className='userBox'>
110
-          <MyCell icon={feedback} action={goto} user handleAction={handleMap}>农机地图</MyCell>
111
-        </View>
112 105
         {
113 106
           isLogin && <View className='signOut' onClick={signOut}>退出登录</View>
114 107
         }

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

@@ -4,12 +4,15 @@ import banner1 from '@/assets/banner/2.jpg'
4 4
 import './style.less'
5 5
 
6 6
 export default (props) => {
7
-  const {onClick}=props
7
+  const {onClick,goMap}=props
8 8
   return (
9
-  <View className='machineryCard' onClick={onClick}>
9
+  <View className='machineryCard'>
10 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 16
   </View>
14 17
   )
15 18
 }

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

@@ -1,5 +1,4 @@
1 1
 .machineryCard{
2
-  height: 594px;
3 2
   background: #FFF;
4 3
   box-shadow: 0px 0px 44px 0px rgba(0, 0, 0, 0.08);
5 4
   border-radius: 40px;
@@ -10,10 +9,19 @@
10 9
     height: calc(calc(100vw - 60px) * 0.66);
11 10
     width: 100%;
12 11
   }
13
-  .machineryName{
14
-    font-size: 36px;
12
+  .info{
15 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,9 +6,12 @@ import MachineryCard from './Card'
6 6
 import './style.less'
7 7
 
8 8
 export default withLayout((props) => {
9
-  const goMap=()=>{
9
+  const goDetail=()=>{
10 10
     Taro.navigateTo({ url: '/pages/machineryDetail/index' });
11 11
   }
12
+  const goMap=()=>{
13
+    Taro.navigateTo({ url: '/pages/machineryMap/index' });
14
+  }
12 15
   return (
13 16
     <View className='page-index'>
14 17
       <View className='index-navbar'>
@@ -16,7 +19,7 @@ export default withLayout((props) => {
16 19
       </View>
17 20
       <View className='index-container machineryListContent'>
18 21
         <ScrollView scrollY style={{ height: '100%' }}>
19
-          <MachineryCard onClick={()=>goMap()} />
22
+          <MachineryCard onClick={()=>goDetail()}  goMap={()=>goMap()} />
20 23
           <MachineryCard />
21 24
           <MachineryCard />
22 25
         </ScrollView>

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

@@ -1,6 +1,6 @@
1 1
 import Taro from "@tarojs/taro"
2 2
 import { useState } from "react"
3
-import { View, Map,Image } from "@tarojs/components"
3
+import { View, Map, Image } from "@tarojs/components"
4 4
 import withLayout from '@/layouts'
5 5
 import CustomNav from "@/components/CustomNav"
6 6
 import m1 from '@/assets/machinery/greenMachinery.png'
@@ -9,60 +9,64 @@ import picon from '@/assets/comm/position.png'
9 9
 import './style.less'
10 10
 
11 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 32
     console.log(e.markerId)
33 33
     setShow(true)
34 34
   }
35
-  const goDetail=()=>{
35
+  const goDetail = () => {
36 36
     Taro.navigateTo({ url: '/pages/machineryDetail/index' });
37 37
   }
38
+  const goList=()=>{
39
+    Taro.navigateTo({ url: '/pages/machineryList/index' });
40
+  }
38 41
   return (
39 42
     <View className='page-index'>
40 43
       <View className='index-navbar'>
41 44
         <CustomNav title='我的农机' />
42 45
       </View>
43 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 52
           onMarkerTap={handleClick}
50
-          onRegionChange={()=>setShow(false)}
53
+          onRegionChange={() => setShow(false)}
51 54
         />
52 55
         {
53
-          show&&
56
+          show &&
54 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 67
           </View>
63
-        </View>
64 68
         }
65
-        
69
+
66 70
       </View>
67 71
     </View>
68 72
   )

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

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

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

@@ -56,23 +56,3 @@ export function random(prefix) {
56 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 查看文件

@@ -0,0 +1,126 @@
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
+}