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

优化 provider 示例。

上级 5426b03f
...@@ -7,19 +7,10 @@ ...@@ -7,19 +7,10 @@
<view class="service-item" v-for="(item, index) in serviceList" :key="index"> <view class="service-item" v-for="(item, index) in serviceList" :key="index">
<text class="service-name">{{item.name}}:</text> <text class="service-name">{{item.name}}:</text>
<view class="provider-list"> <view class="provider-list">
<!-- #ifdef APP-IOS -->
<text class="provider-item" v-for="(item2, index2) in item.provider" :key="index2">
{{item2}}
{{item.providerObjMap.length > 0 ? ':' + JSON.stringify(item.providerObjMap[index2]) : '' }}
</text>
<!-- #endif -->
<!-- #ifdef APP-ANDROID -->
<text class="provider-item" v-for="(item2, index2) in item.provider" :key="index2"> <text class="provider-item" v-for="(item2, index2) in item.provider" :key="index2">
{{item2}} {{item2}}
{{item.providerObj.length > 0 ? ':' + JSON.stringify(item.providerObj[index2]) : '' }} {{item.providerObj.length > 0 ? ':' + JSON.stringify(item.providerObj[index2]) : '' }}
</text> </text>
<!-- #endif -->
</view> </view>
</view> </view>
<button class="btn-get-provider" type="primary" @click="getProvider">getProviderSync</button> <button class="btn-get-provider" type="primary" @click="getProvider">getProviderSync</button>
...@@ -34,8 +25,7 @@ ...@@ -34,8 +25,7 @@
service : string, service : string,
name : string, name : string,
provider : string[], provider : string[],
providerObj : UniProvider[], providerObj : UniProvider[]
providerObjMap : Object[],
} }
export default { export default {
...@@ -44,8 +34,8 @@ ...@@ -44,8 +34,8 @@
title: 'provider', title: 'provider',
flag: false, flag: false,
serviceList: [ serviceList: [
{ service: "payment", name: "支付", provider: [], providerObj: [], providerObjMap: [] }, { service: "payment", name: "支付", provider: [], providerObj: []},
{ service: "location", name: "定位", provider: [], providerObj: [], providerObjMap: [] } { service: "location", name: "定位", provider: [], providerObj: []}
] as ProviderItem[], ] as ProviderItem[],
providerIds: [] as string[], providerIds: [] as string[],
providerObjects: [] as UniProvider[], providerObjects: [] as UniProvider[],
...@@ -81,49 +71,9 @@ ...@@ -81,49 +71,9 @@
console.log(isWeChatInstalled) console.log(isWeChatInstalled)
} }
// #endif // #endif
// #ifdef APP-IOS
const providerObjMap = this.getProviderObjectMap(obj)
console.log(providerObjMap)
item.providerObjMap.push(providerObjMap)
// #endif
}) })
} }
},
// #ifdef APP-IOS
getProviderObjectMap(provider : UniProvider) {
const map = new Map()
if (this.hasProperty(provider, 'id') && provider.id != null) {
map.set('id', provider.id)
}
if (this.hasProperty(provider, 'description') && provider.description != null) {
map.set('description', provider.description)
}
if (this.hasProperty(provider, 'isAppExist') && provider.isAppExist != null) {
map.set('isAppExist', provider.isAppExist)
}
if (this.hasProperty(provider, 'isWeChatInstalled') && provider.isWeChatInstalled != null) {
map.set('isWeChatInstalled', provider.isWeChatInstalled)
}
if (this.hasMethod(provider, 'uniqueMethodForProvider')) {
map.set('func-uniqueMethodForProvider', provider.uniqueMethodForProvider())
}
return Object.fromEntries(map)
},
hasMethod(provider : UniProvider, methodName : string) {
return typeof provider[methodName] === 'function';
},
hasProperty(provider : UniProvider, propName : string) {
return propName in provider
} }
// #endif
} }
} }
</script> </script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册