From f06e270b358d0c60aa6ee9fd8930ea5a639182d6 Mon Sep 17 00:00:00 2001 From: donqi Date: Fri, 2 Dec 2022 02:27:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=88=E6=9D=83=E6=89=93=E5=8D=A1=E6=8B=92?= =?UTF-8?q?=E7=BB=9D=E9=9C=80=E8=A6=81=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=86=8D=E6=AC=A1=E6=8E=88=E6=9D=83=E7=9A=84=E5=85=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=9B=E4=BF=AE=E6=94=B9=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/js/request.js | 37 +++++++++++++++++++++++++++++ pages/area-proxy/my-team.vue | 2 +- pages/order-manage/order-manage.vue | 17 ++++++++++--- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/common/js/request.js b/common/js/request.js index 98c9d9f..098723f 100644 --- a/common/js/request.js +++ b/common/js/request.js @@ -659,6 +659,43 @@ export default { }) return res[1].data; }, + async checkAuth(authScope, callbackName, callbackSuccessKey) { + let _this = this; + // 通过 wx.getSetting 先查询一下用户是否授权了authScope + let res1 = await wx.getSetting(); + if (res1) { + if (!res1.authSetting[authScope]) { + let res = _this[callbackName](); + if (res && res[callbackSuccessKey]) { + return res; + } + // 用户授权 + uni.showToast({ + title: '请先授权', + icon: 'none', + duration: 1500 + }) + return 'rejected'; + } else { + return _this[callbackName](); + } + } + }, + async openAndAuthSetting(authScope) { + wx.openSetting({ + success(res) { + if (res[authScope]) { + return true; + } + } + }) + uni.showToast({ + icon: 'error', + duration: 1500, + title: '授权失败' + }) + return false; + }, async wxGetLocation() { let res = await wx.getLocation({ type: 'gcj02' diff --git a/pages/area-proxy/my-team.vue b/pages/area-proxy/my-team.vue index 279be0f..0c60325 100644 --- a/pages/area-proxy/my-team.vue +++ b/pages/area-proxy/my-team.vue @@ -65,7 +65,7 @@ - + diff --git a/pages/order-manage/order-manage.vue b/pages/order-manage/order-manage.vue index 1467278..2df6617 100644 --- a/pages/order-manage/order-manage.vue +++ b/pages/order-manage/order-manage.vue @@ -210,7 +210,8 @@ - + + @@ -503,7 +504,8 @@ picModalImgList: [], curDate: '', curUserInfo: {}, - orderStatistics: {} + orderStatistics: {}, + hasAuthLocation: true } }, onLoad(option) { @@ -1170,8 +1172,17 @@ current: e.currentTarget.dataset.url }); }, + async authLocationCallback(res) { + if (res.detail.authSetting['scope.userLocation']) { + this.hasAuthLocation = true; + } + }, async recordClockInLocation(order) { - let res = await this.$request.wxGetLocation(); + let res = await this.$request.checkAuth('scope.userLocation', 'wxGetLocation', 'latitude'); + if (res && res === 'rejected') { + this.hasAuthLocation = false; + return; + } if (!res || !res.latitude) { uni.showToast({ title: '定位获取失败,打卡失败,请稍后重试',