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

feat(app): getProvider add providers param

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