Browse Source

修复bug

Yansen 11 months ago
parent
commit
0444d45a2a
1 changed files with 21 additions and 3 deletions
  1. 21
    3
      src/utils/authorize.js

+ 21
- 3
src/utils/authorize.js View File

29
 export const getLocation = () => {
29
 export const getLocation = () => {
30
   // eslint-disable-next-line no-undef
30
   // eslint-disable-next-line no-undef
31
   if (!IS_APP_CLIENT) {
31
   if (!IS_APP_CLIENT) {
32
-    // 非 app 端, 直接使用默认位置
32
+
33
     // eslint-disable-next-line no-undef
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
       location: {
36
       location: {
37
         lat: parts[1],
37
         lat: parts[1],
38
         lng: parts[0],
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
   return new Promise((resolve, reject) => {
61
   return new Promise((resolve, reject) => {