Yansen 2 years ago
parent
commit
21ac5b0cfb

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

38
     navigationBarBackgroundColor: '#1A7565',
38
     navigationBarBackgroundColor: '#1A7565',
39
     navigationBarTitleText: '文明创城',
39
     navigationBarTitleText: '文明创城',
40
     navigationBarTextStyle: 'white'
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 View File

3
 import style from './map.module.less';
3
 import style from './map.module.less';
4
 
4
 
5
 export default (props) => {
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
   return (
9
   return (
10
     <View className={style['map-box']}>
10
     <View className={style['map-box']}>

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

1
 import React from 'react';
1
 import React from 'react';
2
+import Taro from '@tarojs/taro';
2
 import { View } from '@tarojs/components';
3
 import { View } from '@tarojs/components';
3
 import Page from '@/layouts/index';
4
 import Page from '@/layouts/index';
5
+import getAuthorize from '@/utils/authorize';
6
+import { Notify } from '@antmjs/vantui';
4
 import Map from './components/Map';
7
 import Map from './components/Map';
5
 import Issue from './components/Issue';
8
 import Issue from './components/Issue';
6
 
9
 
7
 export default (props) => {
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
   return (
35
   return (
10
     <Page>
36
     <Page>
11
-      <Map />
37
+      <Map location={loc} />
12
       <Issue />
38
       <Issue />
13
     </Page>
39
     </Page>
14
   )
40
   )

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

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 View File

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