aXin-0810 1 nedēļu atpakaļ
vecāks
revīzija
4627e5fd0a
1 mainītis faili ar 35 papildinājumiem un 28 dzēšanām
  1. 35 28
      src/packageHome/pages/codeActivity/activityForm.vue

+ 35 - 28
src/packageHome/pages/codeActivity/activityForm.vue

@@ -456,38 +456,45 @@ export default {
 
     // 地图选点
     getLocation() {
-      uni.chooseLocation({
-        success: async res => {
-          // uni.setStorageSync('formData',{name: this.name,phone: this.phone,address: res.address})
-          let addressData = await this.getRegionByLatLng(res.latitude, res.longitude)
-          this.address = addressData.provinceName + addressData.cityName + addressData.areaName + res.address
-        },
-        fail: res => {
-          uni.getSetting({
-            success: res => {
-              if (!res.authSetting['scope.userLocation']) {
-                uni.showModal({
-                  title: '是否授权当前位置',
-                  content: '需要获取您的地理位置,请确认授权,否则地图功能将无法使用',
-                  success: tip => {
-                    if (tip.confirm) {
-                      uni.openSetting({
-                        success: data => {
-                          if (data.authSetting['scope.userLocation'] === true) {
-                            this.$successToast('授权成功')
-                            setTimeout(() => {
-                              this.getLocation()
-                            }, 1000)
-                          }
+      // 页面加载时预请求权限(可选)
+      uni.getLocation({
+        type: 'gcj02',
+        success: () => {
+          uni.chooseLocation({
+            success: async res => {
+              // uni.setStorageSync('formData',{name: this.name,phone: this.phone,address: res.address})
+              let addressData = await this.getRegionByLatLng(res.latitude, res.longitude)
+              this.address = addressData.provinceName + addressData.cityName + addressData.areaName + res.address
+            },
+            fail: res => {
+              uni.getSetting({
+                success: res => {
+                  if (!res.authSetting['scope.userLocation']) {
+                    uni.showModal({
+                      title: '是否授权当前位置',
+                      content: '需要获取您的地理位置,请确认授权,否则地图功能将无法使用',
+                      success: tip => {
+                        if (tip.confirm) {
+                          uni.openSetting({
+                            success: data => {
+                              if (data.authSetting['scope.userLocation'] === true) {
+                                this.$successToast('授权成功')
+                                setTimeout(() => {
+                                  this.getLocation()
+                                }, 1000)
+                              }
+                            }
+                          })
                         }
-                      })
-                    }
+                      }
+                    })
                   }
-                })
-              }
+                }
+              })
             }
           })
-        }
+        }, // 空函数仅用于触发权限请求
+        fail: err => console.log('请求权限失败', err)
       })
     }
   }