提交 01f32162 编写于 作者: M mahaifeng

[provider]将getprovider改为provider,方便生成示例文档

上级 4ac6aa4c
......@@ -1100,10 +1100,10 @@
},
// #ifndef WEB
{
"path": "pages/API/get-provider/get-provider",
"path": "pages/API/provider/provider",
"group": "1,1,6",
"style": {
"navigationBarTitleText": "getProvider | 获取服务提供商"
"navigationBarTitleText": "provider | 服务提供商"
}
},
// #endif
......@@ -2041,8 +2041,8 @@
"name": "exit"
},
{
"id": "api.base.getProvider",
"name": "getProvider"
"id": "api.base.provider",
"name": "provider"
}
]
},
......@@ -2681,4 +2681,4 @@
]
}
]
}
\ No newline at end of file
}
<template>
<!-- #ifdef APP -->
<scroll-view class="page-scroll-view">
<!-- #endif -->
<view class="page">
<page-head :title="title"></page-head>
<view class="service-item" v-for="(item, index) in serviceList" :key="index">
<text class="service-name">{{item.name}}:</text>
<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">
{{item2}}
{{item.providerObj.length > 0 ? ':' + JSON.stringify(item.providerObj[index2]) : '' }}
</text>
<!-- #endif -->
</view>
</view>
<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>
<!-- #endif -->
</template>
<script>
type ProviderItem = {
service : string,
name : string,
provider : string[],
providerObj : UniProvider[],
providerObjMap : Object[],
}
export default {
data() {
return {
title: 'provider',
flag: false,
serviceList: [
{ service: "oauth", name: "登陆", provider: [], providerObj: [], providerObjMap: [] },
{ service: "share", name: "分享", provider: [], providerObj: [], providerObjMap: [] },
{ service: "payment", name: "支付", provider: [], providerObj: [], providerObjMap: [] },
{ service: "push", name: "推送", provider: [], providerObj: [], providerObjMap: [] },
{ service: "location", name: "定位", provider: [], providerObj: [], providerObjMap: [] }
] as ProviderItem[],
providerObjList: [] as UniProvider[]
}
},
methods: {
getProviderIds() {
this.serviceList.forEach((item : ProviderItem) => {
let providerIds = uni.getProviderIds({
service: item.service
})
this.updateProvider(item.service, providerIds);
})
},
updateProvider(service : string, provider ?: string[] | null) {
const item : ProviderItem | null = this.serviceList.find((item : ProviderItem) : boolean => {
return item.service == service
});
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) {
console.log(obj)
console.log(JSON.stringify(obj))
value.providerObj.push(obj)
// #ifdef APP-IOS
const providerObjMap = this.getProviderObjectMap(obj)
console.log(providerObjMap)
value.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>
<style>
.page {
padding: 15px;
}
.service-item {
margin-top: 10px;
}
.service-name {
font-weight: bold;
}
.provider-list {
margin-left: 32px;
}
.provider-item {
line-height: 1.5;
}
.btn-get-provider {
margin-top: 30px;
}
<template>
<!-- #ifdef APP -->
<scroll-view class="page-scroll-view">
<!-- #endif -->
<view class="page">
<page-head :title="title"></page-head>
<view class="service-item" v-for="(item, index) in serviceList" :key="index">
<text class="service-name">{{item.name}}:</text>
<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">
{{item2}}
{{item.providerObj.length > 0 ? ':' + JSON.stringify(item.providerObj[index2]) : '' }}
</text>
<!-- #endif -->
</view>
</view>
<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>
<!-- #endif -->
</template>
<script>
type ProviderItem = {
service : string,
name : string,
provider : string[],
providerObj : UniProvider[],
providerObjMap : Object[],
}
export default {
data() {
return {
title: 'provider',
flag: false,
serviceList: [
{ service: "oauth", name: "登陆", provider: [], providerObj: [], providerObjMap: [] },
{ service: "share", name: "分享", provider: [], providerObj: [], providerObjMap: [] },
{ service: "payment", name: "支付", provider: [], providerObj: [], providerObjMap: [] },
{ service: "push", name: "推送", provider: [], providerObj: [], providerObjMap: [] },
{ service: "location", name: "定位", provider: [], providerObj: [], providerObjMap: [] }
] as ProviderItem[],
providerObjList: [] as UniProvider[]
}
},
methods: {
getProviderIds() {
this.serviceList.forEach((item : ProviderItem) => {
let providerIds = uni.getProviderIds({
service: item.service
})
this.updateProvider(item.service, providerIds);
})
},
updateProvider(service : string, provider ?: string[] | null) {
const item : ProviderItem | null = this.serviceList.find((item : ProviderItem) : boolean => {
return item.service == service
});
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) {
console.log(obj)
console.log(JSON.stringify(obj))
value.providerObj.push(obj)
// #ifdef APP-IOS
const providerObjMap = this.getProviderObjectMap(obj)
console.log(providerObjMap)
value.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>
<style>
.page {
padding: 15px;
}
.service-item {
margin-top: 10px;
}
.service-name {
font-weight: bold;
}
.provider-list {
margin-left: 32px;
}
.provider-item {
line-height: 1.5;
}
.btn-get-provider {
margin-top: 30px;
}
</style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册