提交 d189e5b3 编写于 作者: D DCloud_LXH

feat(App): getProvider

上级 6455f8c0
......@@ -75,6 +75,8 @@ export * from './protocols/ui/startPullDownRefresh'
export * from './protocols/ui/stopPullDownRefresh'
export * from './protocols/ui/tabBar'
export * from './protocols/ui/window'
export * from './protocols/plugin/getProvider'
// helpers
export {
defineOnApi,
......
......@@ -30,3 +30,5 @@ export * from './location/getLocation'
export * from './ui/popup/showModal'
export * from './ui/popup/showActionSheet'
export * from './ui/popup/showToast'
export * from './plugin/getProvider'
import {
defineAsyncApi,
API_GET_PROVIDER,
API_TYPE_GET_PROVIDER,
GetProviderProtocol,
} from '@dcloudio/uni-api'
type Provider = PlusOauthAuthService['id'][]
type CallBack = (err: null | Error, provider?: Provider) => void
const providers = {
oauth(callback: CallBack) {
plus.oauth.getServices(
(services) => {
services = services as PlusOauthAuthService[]
const provider: Provider = []
services.forEach(({ id }) => {
provider.push(id)
})
callback(null, provider)
},
(err) => {
err = err as Error
callback(err)
}
)
},
share(callback: CallBack) {
plus.share.getServices(
(services) => {
const provider: Provider = []
services.forEach(({ id }) => {
provider.push(id)
})
callback(null, provider)
},
(err) => {
callback(err)
}
)
},
payment(callback: CallBack) {
plus.payment.getChannels(
(services) => {
const provider: Provider = []
services.forEach(({ id }) => {
provider.push(id)
})
callback(null, provider)
},
(err) => {
callback(err)
}
)
},
push(callback: CallBack) {
if (typeof weex !== 'undefined' || typeof plus !== 'undefined') {
callback(null, [plus.push.getClientInfo().id])
} else {
callback(null, [])
}
},
}
export const getProvider = defineAsyncApi<API_TYPE_GET_PROVIDER>(
API_GET_PROVIDER,
({ service }, { resolve, reject }) => {
if (providers[service]) {
providers[service]((err, provider) => {
if (err) {
reject(err.message)
} else {
resolve({
service,
provider: provider as any[],
})
}
})
} else {
reject('service not found')
}
},
GetProviderProtocol
)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册