From 9a0bd14db8717f902cf123e43e9ae3fb034aff73 Mon Sep 17 00:00:00 2001 From: zhaofengliang Date: Tue, 13 Aug 2024 18:05:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=AE=9A=E4=BD=8D=E5=92=8C?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E7=A4=BA=E4=BE=8B=EF=BD=9C=E9=80=82=E9=85=8D?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=96=B9=E6=B3=95=20uni.getProviderSync?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/API/get-location/get-location.uvue | 53 +++++++----------- pages/API/provider/provider.uvue | 2 +- .../API/request-payment/request-payment.uvue | 54 ++++++++----------- 3 files changed, 43 insertions(+), 66 deletions(-) diff --git a/pages/API/get-location/get-location.uvue b/pages/API/get-location/get-location.uvue index 8ca70144..8f45e8cf 100644 --- a/pages/API/get-location/get-location.uvue +++ b/pages/API/get-location/get-location.uvue @@ -84,13 +84,13 @@ jest_provider: '', jest_type: 'wgs84' as GetLocationType, jest_isAltitude: false, - jest_isGeocode: false, + jest_isGeocode: false, jest_isHighAccuracy: false, jest_altitude: -1000, jest_longitude: 200, jest_latitude: 100, jest_address: '', - jest_errCode: 0, + jest_errCode: 0, jest_complete: false } }, @@ -102,31 +102,18 @@ methods: { getProvider() { // #ifdef APP - uni.getProvider({ - service: "location", - success: (e) => { - console.log("location success:" + JSON.stringify(e), e.providerObjects.length); - let array = e.providerIds as string[] - array.forEach((value : string) => { - let locationProvider = e.providerObjects.find((item) : boolean => { - return item.id == value - }) - if (locationProvider != null) { - this.providerList.push({ - name: locationProvider.description, - id: locationProvider.id, - provider: e.providerObjects.find((item) : boolean => { - return item.id == locationProvider.id - }) - } as LocationItem); - } - }) - }, - fail: (e) => { - console.log("获取定位服务商失败:", e); - } - }); + let provider = uni.getProviderSync({ + service: "location", + } as GetProviderSyncOptions) + console.log(provider) + provider.providerObjects.forEach((value : UniProvider) => { + this.providerList.push({ + name: value.description, + id: value.id, + provider: value + } as LocationItem); + }) this.providerList.forEach((value, index) => { if (value.id == "system") { @@ -203,8 +190,8 @@ }, // 仅用于自动化测试 - jestGetLocation() { - this.jest_complete = false + jestGetLocation() { + this.jest_complete = false this.jest_errCode = 0 uni.getLocation(({ // #ifdef APP @@ -214,17 +201,17 @@ altitude: this.jest_isAltitude, isHighAccuracy: this.jest_isHighAccuracy, geocode: this.jest_isGeocode, - success: (res) => { - if (res.address != null) { - this.jest_address = res.address! + success: (res) => { + if (res.address != null) { + this.jest_address = res.address! } this.jest_longitude = res.longitude this.jest_latitude = res.latitude - this.jest_altitude = res.altitude + this.jest_altitude = res.altitude this.jest_complete = true }, fail: (err) => { - this.jest_errCode = err.errCode + this.jest_errCode = err.errCode this.jest_complete = true } })); diff --git a/pages/API/provider/provider.uvue b/pages/API/provider/provider.uvue index 4795b148..c8358a28 100644 --- a/pages/API/provider/provider.uvue +++ b/pages/API/provider/provider.uvue @@ -22,7 +22,7 @@ - + diff --git a/pages/API/request-payment/request-payment.uvue b/pages/API/request-payment/request-payment.uvue index 3bcc8fa2..3b3097f8 100644 --- a/pages/API/request-payment/request-payment.uvue +++ b/pages/API/request-payment/request-payment.uvue @@ -22,40 +22,30 @@ } }, onLoad: function () { - uni.getProvider({ + let provider = uni.getProviderSync({ service: "payment", - success: (e) => { - console.log("payment success:" + JSON.stringify(e)); - let array = e.providerIds as string[] - array.forEach((value : string) => { - switch (value) { - case 'alipay': - this.providerList.push({ - name: '支付宝', - id: "alipay", - provider: e.providerObjects.find((item) : boolean => { - return item.id == 'alipay' - }) - } as PayItem); - break; - case 'wxpay': - this.providerList.push({ - name: '微信', - id: "wxpay", - provider: e.providerObjects.find((item) : boolean => { - return item.id == 'wxpay' - }) - } as PayItem); - break; - default: - break; - } - }) - }, - fail: (e) => { - console.log("获取支付通道失败:", e); + } as GetProviderSyncOptions) + console.log(provider) + provider.providerObjects.forEach((value : UniProvider) => { + switch (value.id) { + case 'alipay': + this.providerList.push({ + name: '支付宝', + id: "alipay", + provider: value + } as PayItem); + break; + case 'wxpay': + this.providerList.push({ + name: '微信', + id: "wxpay", + provider: value + } as PayItem); + break; + default: + break; } - }); + }) }, methods: { requestPayment(e : PayItem) { -- GitLab