提交 7c38380d 编写于 作者: D DCloud_LXH

feat(app): getProvider add providers param

上级 f39013d4
......@@ -4,20 +4,31 @@ import {
API_TYPE_GET_PROVIDER,
GetProviderProtocol,
} from '@dcloudio/uni-api'
import { isPlainObject, isFunction } from '@vue/shared'
type Provider = (PlusShareShareService['id'] | PlusOauthAuthService['id'])[]
type CallBack = (err: null | Error, provider?: Provider) => void
type Service =
| PlusShareShareService
| PlusOauthAuthService
| PlusPaymentPaymentChannel
| PlusPushClientInfo
type Provider = Service['id'][]
type Providers = Service[]
type CallBack = (
err: null | Error,
provider?: Provider,
providers?: Providers
) => void
const providers = {
oauth(callback: CallBack) {
plus.oauth.getServices(
(services) => {
services = services as PlusOauthAuthService[]
services = services
const provider: Provider = []
services.forEach(({ id }) => {
provider.push(id)
})
callback(null, provider)
callback(null, provider, services)
},
(err) => {
err = err as Error
......@@ -28,12 +39,12 @@ const providers = {
share(callback: CallBack) {
plus.share.getServices(
(services) => {
services = services as PlusShareShareService[]
services = services
const provider: Provider = []
services.forEach(({ id }) => {
provider.push(id)
})
callback(null, provider)
callback(null, provider, services)
},
(err) => {
callback(err)
......@@ -47,7 +58,7 @@ const providers = {
services.forEach(({ id }) => {
provider.push(id)
})
callback(null, provider)
callback(null, provider, services)
},
(err) => {
callback(err)
......@@ -56,7 +67,8 @@ const providers = {
},
push(callback: CallBack) {
if (typeof weex !== 'undefined' || typeof plus !== 'undefined') {
callback(null, [plus.push.getClientInfo().id])
const clientInfo = plus.push.getClientInfo()
callback(null, [clientInfo.id], [clientInfo])
} else {
callback(null, [])
}
......@@ -67,13 +79,28 @@ export const getProvider = defineAsyncApi<API_TYPE_GET_PROVIDER>(
API_GET_PROVIDER,
({ service }, { resolve, reject }) => {
if (providers[service]) {
providers[service]((err, provider) => {
providers[service]((err, provider = [], providers = []) => {
if (err) {
reject(err.message)
} else {
resolve({
service,
// 5+ PlusShareShareService['id'] 类型错误
provider: provider as any[],
providers: providers.map((provider) => {
const returnProvider: Service = {}
if (isPlainObject(provider)) {
for (const key in provider) {
if (Object.hasOwnProperty.call(provider, key)) {
const item = provider[key as keyof Service]
if (!isFunction(item) && typeof item !== 'undefined') {
;(returnProvider as any)[key] = item
}
}
}
}
return returnProvider
}),
})
}
})
......
......@@ -6,7 +6,7 @@ importers:
specifiers:
'@babel/core': ^7.17.10
'@babel/preset-env': ^7.16.11
'@dcloudio/types': ^3.0.4
'@dcloudio/types': ^3.0.6
'@dcloudio/uni-api': 3.0.0-alpha-3050020220617004
'@dcloudio/uni-app': 3.0.0-alpha-3050020220617004
'@jest/types': ^27.0.2
......@@ -57,7 +57,7 @@ importers:
devDependencies:
'@babel/core': 7.18.5
'@babel/preset-env': 7.18.2_@babel+core@7.18.5
'@dcloudio/types': 3.0.4
'@dcloudio/types': 3.0.6
'@dcloudio/uni-api': link:packages/uni-api
'@dcloudio/uni-app': link:packages/uni-app
'@jest/types': 27.5.1
......@@ -2123,8 +2123,8 @@ packages:
resolution: {integrity: sha512-mrCMwcINy1IFjU9VUqLeWBkj404yWs5paLDttBcA+eqUjanuUQbBcTVPqlrGgkyzLXDcV2oDDZRSNxNpXi4kMQ==}
dev: true
/@dcloudio/types/3.0.4:
resolution: {integrity: sha512-fCv61xpedHVo+6ScOuTUDseyqqAeqBt2rtvkwcI7itS9CIwfoel03vlnTuoNh/rtb44sK2niDwFcli6B1hlpYg==}
/@dcloudio/types/3.0.6:
resolution: {integrity: sha512-8E63ebFBjRdBcPokVVFkQoSqRH118g6AHwd4l1CciuRh1A44N7LyP7t3Hb72PZfkfJIHuCtOXFoUdm96SUnjrA==}
dev: true
/@dcloudio/uni-cli-i18n/2.0.0-alpha-33020211130001:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册