Browse Source

no message

aXin-0810 1 week ago
parent
commit
16ac12fd86
2 changed files with 33 additions and 35 deletions
  1. 5 0
      src/common/utils/util.js
  2. 28 35
      src/packageHome/pages/codeActivity/activityForm.vue

+ 5 - 0
src/common/utils/util.js

@@ -1027,6 +1027,11 @@ export const wxConfig = function (configInfo, userInfo, cb, _url) {
 
         wx.ready(() => {
           cb?.(wx)
+          uni.getLocation({
+            type: 'gcj02',
+            success: () => {}, // 空函数仅用于触发权限请求
+            fail: () => {}
+          })
           if (configInfo && userInfo) {
             wxShare({
               configInfo,

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

@@ -456,45 +456,38 @@ export default {
 
     // 地图选点
     getLocation() {
-      // 页面加载时预请求权限(可选)
-      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)
-                              }
-                            }
-                          })
+      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)
+        }
       })
     }
   }