提交 a64e8b6c 编写于 作者: zhaofengliang920817's avatar zhaofengliang920817 提交者: DCloud-WZF

Merge branch 'dev-provider' into dev

上级 466e4880
......@@ -7,10 +7,14 @@
<view class="service-item" v-for="(item, index) in serviceList" :key="index">
<text class="service-name">{{item.name}}:</text>
<view class="provider-list">
<text class="provider-item" v-for="(item2, index2) in item.provider" :key="index2">{{item2}}</text>
<text class="provider-item" v-for="(item2, index2) in item.provider" :key="index2">
{{item2}}
{{item.providerObj.length > 0 ? ':'+ JSON.stringify(item.providerObj[index2]) : '' }}
</text>
</view>
</view>
<button class="btn-get-provider" type="primary" @click="getProvider">getProvider</button>
<button class="btn-get-provider" type="primary" @click="getProviderIds">getProviderIds</button>
<button class="btn-get-provider" type="primary" @click="getProviderObject">getProviderObject</button>
</view>
<!-- #ifdef APP -->
</scroll-view>
......@@ -18,45 +22,65 @@
</template>
<script>
type ProviderItem = {
service : string,
name : string,
provider : string[]
provider : string[],
providerObj : UniProvider[]
}
export default {
data() {
return {
title: 'provider',
flag: false,
serviceList: [
{ service: "oauth", name: "登陆", provider: [] },
{ service: "share", name: "分享", provider: [] },
{ service: "payment", name: "支付", provider: [] },
{ service: "push", name: "推送", provider: [] },
{ service: "location", name: "定位", provider: [] }
] as ProviderItem[]
{ service: "oauth", name: "登陆", provider: [], providerObj: [] },
{ service: "share", name: "分享", provider: [], providerObj: [] },
{ service: "payment", name: "支付", provider: [], providerObj: [] },
{ service: "push", name: "推送", provider: [], providerObj: [] },
{ service: "location", name: "定位", provider: [], providerObj: [] }
] as ProviderItem[],
providerObjList: [] as UniProvider[]
}
},
methods: {
getProvider() {
getProviderIds() {
this.serviceList.forEach((item : ProviderItem) => {
uni.getProvider({
service: item.service,
success: (e) => {
this.updateProvider(e.service, e.provider);
}
let providerIds = uni.getProviderIds({
service: item.service
})
this.updateProvider(item.service, providerIds);
})
},
updateProvider(service : string, provider : string[]) {
updateProvider(service : string, provider ?: string[] | null) {
const item : ProviderItem | null = this.serviceList.find((item : ProviderItem) : boolean => {
return item.service == service
});
if (item != null) {
if (item != null && provider != null) {
item.provider = provider
}
},
getProviderObject() {
this.flag = true
this.getProviderIds()
let objList = []
this.serviceList.forEach((value) => {
value.provider.forEach((provider) => {
let obj = uni.getProviderObject({
service: value.service,
provider: provider
})
if (obj != null) {
value.providerObj.push(obj)
}
})
})
}
},
}
</script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册