提交 2117a8ed 编写于 作者: zhaofengliang920817's avatar zhaofengliang920817

调整定位和支付示例|适配新增方法 uni.getProviderSync。

上级 8d6619e2
...@@ -102,31 +102,18 @@ ...@@ -102,31 +102,18 @@
methods: { methods: {
getProvider() { getProvider() {
// #ifdef APP // #ifdef APP
uni.getProvider({
let provider = uni.getProviderSync({
service: "location", service: "location",
success: (e) => { } as GetProviderSyncOptions)
console.log("location success:" + JSON.stringify(e), e.providerObjects.length); console.log(provider)
let array = e.providerIds as string[] provider.providerObjects.forEach((value : UniProvider) => {
array.forEach((value : string) => {
let locationProvider = e.providerObjects.find((item) : boolean => {
return item.id == value
})
if (locationProvider != null) {
this.providerList.push({ this.providerList.push({
name: locationProvider.description, name: value.description,
id: locationProvider.id, id: value.id,
provider: e.providerObjects.find((item) : boolean => { provider: value
return item.id == locationProvider.id
})
} as LocationItem); } as LocationItem);
}
}) })
},
fail: (e) => {
console.log("获取定位服务商失败:", e);
}
});
this.providerList.forEach((value, index) => { this.providerList.forEach((value, index) => {
if (value.id == "system") { if (value.id == "system") {
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
</view> </view>
</view> </view>
<button class="btn-get-provider" type="primary" @click="getProvider">getProvider</button> <button class="btn-get-provider" type="primary" @click="getProvider">getProviderSync</button>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
</scroll-view> </scroll-view>
......
...@@ -22,29 +22,24 @@ ...@@ -22,29 +22,24 @@
} }
}, },
onLoad: function () { onLoad: function () {
uni.getProvider({ let provider = uni.getProviderSync({
service: "payment", service: "payment",
success: (e) => { } as GetProviderSyncOptions)
console.log("payment success:" + JSON.stringify(e)); console.log(provider)
let array = e.providerIds as string[] provider.providerObjects.forEach((value : UniProvider) => {
array.forEach((value : string) => { switch (value.id) {
switch (value) {
case 'alipay': case 'alipay':
this.providerList.push({ this.providerList.push({
name: '支付宝', name: '支付宝',
id: "alipay", id: "alipay",
provider: e.providerObjects.find((item) : boolean => { provider: value
return item.id == 'alipay'
})
} as PayItem); } as PayItem);
break; break;
case 'wxpay': case 'wxpay':
this.providerList.push({ this.providerList.push({
name: '微信', name: '微信',
id: "wxpay", id: "wxpay",
provider: e.providerObjects.find((item) : boolean => { provider: value
return item.id == 'wxpay'
})
} as PayItem); } as PayItem);
break; break;
default: default:
...@@ -52,11 +47,6 @@ ...@@ -52,11 +47,6 @@
} }
}) })
}, },
fail: (e) => {
console.log("获取支付通道失败:", e);
}
});
},
methods: { methods: {
requestPayment(e : PayItem) { requestPayment(e : PayItem) {
const provider = e.id const provider = e.id
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册