linwenxin 7 mēneši atpakaļ
vecāks
revīzija
64c225ed66
2 mainītis faili ar 46 papildinājumiem un 15 dzēšanām
  1. 28 14
      src/common/utils/common.js
  2. 18 1
      src/common/utils/util.js

+ 28 - 14
src/common/utils/common.js

@@ -1,5 +1,7 @@
 import store from '@/store/index.js'
 import wx from 'weixin-js-sdk'
+import { getConfigInfo, wxConfig } from '@/common/utils/util'
+
 // 不含icon提示框
 export const toast = str => {
   return new Promise((resolve, reject) => {
@@ -236,20 +238,32 @@ export const openLocation = (options = {}) => {
 // 获取当前定位
 export const getLocation = async function () {
   return new Promise((resolve, reject) => {
-    wx.getLocation({
-      type: 'gcj02',
-      // isHighAccuracy: true,
-      // geocode: true,
-      success: res => {
-        resolve(res)
-      },
-      fail: err => {
-        modal({
-          title: '提示',
-          content: '获取当前定位失败',
-          showCancel: false
-        }).then(() => {})
-      }
+    getConfigInfo().then(configInfo => {
+      wxConfig(
+        configInfo,
+        {
+          nickName: store.state.user.name,
+          userId: store.state.user.userId
+        },
+        () => {
+          wx.getLocation({
+            type: 'gcj02',
+            // isHighAccuracy: true,
+            // geocode: true,
+            success: res => {
+              resolve(res)
+            },
+            fail: err => {
+              reject('获取当前定位失败')
+              modal({
+                title: '提示',
+                content: '获取当前定位失败',
+                showCancel: false
+              }).then(() => {})
+            }
+          })
+        }
+      )
     })
   })
 }

+ 18 - 1
src/common/utils/util.js

@@ -944,7 +944,7 @@ export const weixinPay = function (data, successful, cancel, failure) {
 }
 
 // 微信授权验证配置
-export const wxConfig = function (configInfo, userInfo) {
+export const wxConfig = function (configInfo, userInfo, cb) {
   let url = ''
   const systemInfo = uni.getSystemInfoSync()
   if (systemInfo.platform === 'android') {
@@ -982,7 +982,22 @@ export const wxConfig = function (configInfo, userInfo) {
             'openLocation'
           ]
         })
+
+        wx.checkJsApi({
+          jsApiList: ['getLocation'],
+          success: function (res) {
+            if (res.checkResult.getLocation == false) {
+              alert('你的微信版本太低,不支持微信JS接口,请升级到最新的微信版本!')
+              return
+            }
+          },
+          fail: function (res) {
+            console.log('checkJsApi fail=' + JSON.stringify(res))
+          }
+        })
+
         wx.ready(() => {
+          cb?.()
           if (configInfo && userInfo) {
             wxShare({
               configInfo,
@@ -990,7 +1005,9 @@ export const wxConfig = function (configInfo, userInfo) {
             })
           }
         })
+
         wx.error(function (res) {
+          cb?.()
           // alert('出错了:' + res.errMsg) //wx.config配置错误,会弹出窗口哪里错误,然后根据微信文档查询即可。
         })
       } else {