From c92a2d1557a5b7e89fe03026e35a88a7f5a060c4 Mon Sep 17 00:00:00 2001 From: donqi Date: Sun, 11 Dec 2022 21:12:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E4=BD=8D=E6=89=93=E5=8D=A1=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/js/request.js | 21 ++++++- pages/order-manage/order-manage.vue | 88 +++++++++++++++++++++-------- 2 files changed, 84 insertions(+), 25 deletions(-) diff --git a/common/js/request.js b/common/js/request.js index 098723f..738d592 100644 --- a/common/js/request.js +++ b/common/js/request.js @@ -665,7 +665,7 @@ export default { let res1 = await wx.getSetting(); if (res1) { if (!res1.authSetting[authScope]) { - let res = _this[callbackName](); + let res = await _this[callbackName](); if (res && res[callbackSuccessKey]) { return res; } @@ -677,7 +677,7 @@ export default { }) return 'rejected'; } else { - return _this[callbackName](); + return await _this[callbackName](); } } }, @@ -697,10 +697,25 @@ export default { return false; }, async wxGetLocation() { + let errCode = null; let res = await wx.getLocation({ - type: 'gcj02' + type: 'gcj02', + fail: async (result) => { + if (result.errCode === 2) { + uni.showToast({ + title: '定位获取失败,请确认是否开启定位', + icon: 'none', + duration: 2500 + }) + } + }, + success: async (result) => { + console.log("success"); + return result; + } }) // res.latitude, res.longitude + console.log(res) return res; } } diff --git a/pages/order-manage/order-manage.vue b/pages/order-manage/order-manage.vue index 13e28ed..2ae011d 100644 --- a/pages/order-manage/order-manage.vue +++ b/pages/order-manage/order-manage.vue @@ -1178,31 +1178,75 @@ } }, async recordClockInLocation(order) { - 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: '定位获取失败,打卡失败,请稍后重试', - icon: 'none', - duration: 2500 - }) - } else { - let params = { - id: order.orderDetailId, - clockInLocation: res.longitude + "," + res.latitude - } - let updateOrderRes = await this.$request.updateDetailOrder(params); - if (updateOrderRes && updateOrderRes.code === 0) { - this.reloadMasterOrderPage(); - uni.showToast({ - icon: 'success', - duration: 1000 + let _this = this; + // 通过 wx.getSetting 先查询一下用户是否授权了authScope + let res1 = await wx.getSetting(); + if (res1) { + if (!res1.authSetting['scope.userLocation']) { + let res2 = await wx.getLocation({ + type: 'gcj02', + fail: async (result) => { + console.log(result) + if (result.errno === 103) { + this.hasAuthLocation = false; + // 用户授权 + uni.showToast({ + title: '请先授权', + icon: 'none', + duration: 1500 + }) + } else { + // 用户授权 + uni.showToast({ + title: '请确认是否开启定位', + icon: 'none', + duration: 1500 + }) + } + }, + success: async (result) => { + _this.persistClockInLocation(order, result); + } + }) + } else { + wx.getLocation({ + type: 'gcj02', + fail: async (result) => { + console.log(result) + if (result.errCode === 2 || result.errCode === 404) { + uni.showToast({ + title: '定位获取失败,请确认是否开启定位', + icon: 'none', + duration: 2500 + }) + } else { + uni.showToast({ + title: '定位获取失败,请稍后重试', + icon: 'none', + duration: 2500 + }) + } + }, + success: async (result) => { + _this.persistClockInLocation(order, result); + } }) } } + }, + async persistClockInLocation(order, res) { + let params = { + id: order.orderDetailId, + clockInLocation: res.longitude + "," + res.latitude + } + let updateOrderRes = await this.$request.updateDetailOrder(params); + if (updateOrderRes && updateOrderRes.code === 0) { + this.reloadMasterOrderPage(); + uni.showToast({ + icon: 'success', + duration: 1000 + }) + } } } }