Yansen 2 anni fa
parent
commit
21ac5b0cfb

+ 9
- 1
src/app.config.js Vedi File

@@ -38,5 +38,13 @@ export default defineAppConfig({
38 38
     navigationBarBackgroundColor: '#1A7565',
39 39
     navigationBarTitleText: '文明创城',
40 40
     navigationBarTextStyle: 'white'
41
-  }
41
+  },
42
+  permission: {
43
+    "scope.userLocation": {
44
+      desc: "你的位置信息将用于定位点位" // 高速公路行驶持续后台定位
45
+    }
46
+  },
47
+  requiredPrivateInfos: [
48
+    'getLocation'
49
+  ]
42 50
 })

+ 2
- 2
src/pages/reporting/detail/components/Map.jsx Vedi File

@@ -3,8 +3,8 @@ import { View, Map } from '@tarojs/components';
3 3
 import style from './map.module.less';
4 4
 
5 5
 export default (props) => {
6
-  const { location = '118.805513,31.969974' } = props;
7
-  const loc = location.split(',')
6
+  const { location } = props;
7
+  const loc = location ? location.split(',') : [,];
8 8
   
9 9
   return (
10 10
     <View className={style['map-box']}>

+ 28
- 2
src/pages/reporting/detail/index.jsx Vedi File

@@ -1,14 +1,40 @@
1 1
 import React from 'react';
2
+import Taro from '@tarojs/taro';
2 3
 import { View } from '@tarojs/components';
3 4
 import Page from '@/layouts/index';
5
+import getAuthorize from '@/utils/authorize';
6
+import { Notify } from '@antmjs/vantui';
4 7
 import Map from './components/Map';
5 8
 import Issue from './components/Issue';
6 9
 
7 10
 export default (props) => {
8
-  
11
+
12
+  const [loc, setLoc] = React.useState();
13
+
14
+  React.useMemo(() => {
15
+    getAuthorize('scope.userLocation').then(() => {
16
+      Taro.getLocation({
17
+        success(res) {
18
+          setLoc(`${res.longitude},${res.latitude}`);
19
+        },
20
+        fail() {
21
+          Notify.show({
22
+            message: '获取位置失败, 请退出重试',
23
+            type: 'warning',
24
+          })
25
+        }
26
+      });
27
+    }).catch((err) => {
28
+      Notify.show({
29
+        message: '未能获取位置, 程序部分功能将不能正常使用',
30
+        type: 'warning',
31
+      })
32
+    });
33
+  }, []);
34
+
9 35
   return (
10 36
     <Page>
11
-      <Map />
37
+      <Map location={loc} />
12 38
       <Issue />
13 39
     </Page>
14 40
   )

+ 26
- 0
src/utils/authorize.js Vedi File

@@ -0,0 +1,26 @@
1
+import Taro from '@tarojs/taro';
2
+
3
+export default (scope) => {
4
+  return new Promise((resolve, reject) => {
5
+    Taro.getSetting({
6
+      success(res) {
7
+        if (!res.authSetting[scope]) {
8
+          Taro.authorize({
9
+            scope,
10
+            success: resolve,
11
+            fail: (err) => {
12
+              console.error(err);
13
+              reject(err);
14
+            },
15
+          })
16
+        } else {
17
+          resolve();
18
+        }
19
+      },
20
+      fail(err) {
21
+        console.error(err);
22
+        reject(err);
23
+      }
24
+    });
25
+  });
26
+}

+ 2
- 2
src/utils/request.js Vedi File

@@ -25,9 +25,9 @@ export default function request(api, options = {}) {
25 25
       logger.error(err);
26 26
 
27 27
       if (!silent && 'GET' !== method.toUpperCase()) {
28
-        Taro.showToast({
28
+        Taro.showModal({
29 29
           title: err.message || err,
30
-          icon: 'error'
30
+          showCancel: false,
31 31
         })
32 32
       }
33 33