提交 1af09aed 编写于 作者: M mahaifeng

[provider]添加getProviderSync 示例

上级 f6cab979
...@@ -48,24 +48,28 @@ ...@@ -48,24 +48,28 @@
{ service: "location", name: "定位", provider: [], providerObj: [], providerObjMap: [] } { service: "location", name: "定位", provider: [], providerObj: [], providerObjMap: [] }
] as ProviderItem[], ] as ProviderItem[],
providerIds: [] as string[], providerIds: [] as string[],
providerObjects : [] as UniProvider[], providerObjects: [] as UniProvider[],
} }
}, },
methods: { methods: {
getProvider() { getProvider() {
this.serviceList.forEach((item : ProviderItem) => { this.serviceList.forEach((item : ProviderItem) => {
uni.getProvider({ var provider = uni.getProviderSync({
service: item.service, service: item.service,
success: (e) => { // success: (e) => {
e.providerIds.forEach((value) => { // // e.providerIds.forEach((value) => {
this.providerIds.push(value) // // this.providerIds.push(value)
}) // // })
this.updateProvider(item.service, e.providerIds, e.providerObjects); // // this.updateProvider(item.service, e.providerIds, e.providerObjects);
}, // },
fail: (e) => { // fail: (e) => {
console.log("获取provider失败:", e); // console.log("获取provider失败:", e);
} // }
} as GetProviderOptions) } as GetProviderSyncOptions)
provider.providerIds.forEach((value) => {
this.providerIds.push(value)
})
this.updateProvider(item.service, provider.providerIds, provider.providerObjects);
}) })
}, },
updateProvider(service : string, provider ?: string[] | null, uniProvider : UniProvider[]) { updateProvider(service : string, provider ?: string[] | null, uniProvider : UniProvider[]) {
...@@ -77,7 +81,7 @@ ...@@ -77,7 +81,7 @@
item.providerObj = uniProvider item.providerObj = uniProvider
item.providerObj.forEach((obj) => { item.providerObj.forEach((obj) => {
this.providerObjects.push(obj) this.providerObjects.push(obj)
// #ifdef APP-ANDROID // #ifdef APP-ANDROID
if (obj instanceof UniPaymentWxpayProvider) {//判断微信是否安装 if (obj instanceof UniPaymentWxpayProvider) {//判断微信是否安装
var isWeChatInstalled = (obj as UniPaymentWxpayProvider).isWeChatInstalled var isWeChatInstalled = (obj as UniPaymentWxpayProvider).isWeChatInstalled
...@@ -155,4 +159,4 @@ ...@@ -155,4 +159,4 @@
.btn-get-provider { .btn-get-provider {
margin-top: 30px; margin-top: 30px;
} }
</style> </style>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册