Yansen пре 11 месеци
родитељ
комит
0444d45a2a
1 измењених фајлова са 21 додато и 3 уклоњено
  1. 21
    3
      src/utils/authorize.js

+ 21
- 3
src/utils/authorize.js Прегледај датотеку

@@ -29,15 +29,33 @@ export default function getAuthorize(scope) {
29 29
 export const getLocation = () => {
30 30
   // eslint-disable-next-line no-undef
31 31
   if (!IS_APP_CLIENT) {
32
-    // 非 app 端, 直接使用默认位置
32
+
33 33
     // eslint-disable-next-line no-undef
34
-    const parts = DEFAULT_POS.split(',')
35
-    return Promise.resolve({
34
+    const parts = DEFAULT_POS.split(',');
35
+    const defaultPost = {
36 36
       location: {
37 37
         lat: parts[1],
38 38
         lng: parts[0],
39 39
       },
40
+    }
41
+
42
+    return new Promise((resolve, reject) => {
43
+      // eslint-disable-next-line no-undef
44
+      new TMap.service.IPLocation().locate().then(res => {
45
+        if (res.status == 0) {
46
+          resolve(res.result);
47
+        } else {
48
+          console.error("-----定位失败----")
49
+          console.error(res.message)
50
+          resolve(defaultPost);
51
+        }
52
+      }).catch(e => {
53
+        console.error("-----定位失败----")
54
+        console.error(e)
55
+        resolve(defaultPost);
56
+      });
40 57
     });
58
+    
41 59
   }
42 60
 
43 61
   return new Promise((resolve, reject) => {