提交 4b4e8b1e 编写于 作者: Q qiang

chore: Merge branch 'next' of github.com:dcloudio/uni-app into next

# Conflicts:
#	package.json
#	pnpm-lock.yaml
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
"node": ">=10.0.0" "node": ">=10.0.0"
}, },
"devDependencies": { "devDependencies": {
"@dcloudio/types": "^2.5.17", "@dcloudio/types": "^2.5.18",
"@dcloudio/uni-api": "3.0.0-alpha-3040220220310001", "@dcloudio/uni-api": "3.0.0-alpha-3040220220310001",
"@dcloudio/uni-app": "3.0.0-alpha-3040220220310001", "@dcloudio/uni-app": "3.0.0-alpha-3040220220310001",
"@jest/types": "^27.0.2", "@jest/types": "^27.0.2",
......
...@@ -10,7 +10,12 @@ const SCENE: Parameters<API_TYPE_SHARE>[0]['scene'][] = [ ...@@ -10,7 +10,12 @@ const SCENE: Parameters<API_TYPE_SHARE>[0]['scene'][] = [
export const SahreOptions: ApiOptions<API_TYPE_SHARE> = { export const SahreOptions: ApiOptions<API_TYPE_SHARE> = {
formatArgs: { formatArgs: {
scene(value, params) { scene(value, params) {
if (params.provider === 'weixin' && (!value || !SCENE.includes(value))) { const { provider, openCustomerServiceChat } = params
if (
provider === 'weixin' &&
!openCustomerServiceChat &&
(!value || !SCENE.includes(value))
) {
return `分享到微信时,scene必须为以下其中一个:${SCENE.join('')}` return `分享到微信时,scene必须为以下其中一个:${SCENE.join('')}`
} }
}, },
...@@ -39,6 +44,16 @@ export const SahreOptions: ApiOptions<API_TYPE_SHARE> = { ...@@ -39,6 +44,16 @@ export const SahreOptions: ApiOptions<API_TYPE_SHARE> = {
return '分享小程序时,miniProgram必填' return '分享小程序时,miniProgram必填'
} }
}, },
corpid(value, params) {
if (params.openCustomerServiceChat && !value) {
return `使用打开客服功能时 corpid 必填`
}
},
customerUrl(value, params) {
if (params.openCustomerServiceChat && !value) {
return `使用打开客服功能时 customerUrl 必填`
}
},
}, },
} }
export const ShareProtocols: ApiProtocol<API_TYPE_SHARE> = { export const ShareProtocols: ApiProtocol<API_TYPE_SHARE> = {
......
...@@ -49,17 +49,17 @@ export const login = defineAsyncApi<API_TYPE_LOGIN>( ...@@ -49,17 +49,17 @@ export const login = defineAsyncApi<API_TYPE_LOGIN>(
(params, { resolve, reject }) => { (params, { resolve, reject }) => {
const provider = params.provider || 'weixin' const provider = params.provider || 'weixin'
const errorCallback = warpPlusErrorCallback(reject) const errorCallback = warpPlusErrorCallback(reject)
const authOptions = const isAppleLogin = provider === 'apple'
provider === 'apple' const authOptions = isAppleLogin
? { scope: 'email' } ? { scope: 'email' }
: params.univerifyStyle : params.univerifyStyle
? { ? {
univerifyStyle: univerifyButtonsClickHandling( univerifyStyle: univerifyButtonsClickHandling(
params.univerifyStyle, params.univerifyStyle,
errorCallback errorCallback
), ),
} }
: {} : {}
getService(provider) getService(provider)
.then((service) => { .then((service) => {
...@@ -76,9 +76,11 @@ export const login = defineAsyncApi<API_TYPE_LOGIN>( ...@@ -76,9 +76,11 @@ export const login = defineAsyncApi<API_TYPE_LOGIN>(
service.login( service.login(
(res) => { (res) => {
const authResult = res.target.authResult const authResult = res.target.authResult
const appleInfo = res.target.appleInfo
resolve({ resolve({
code: authResult.code, code: authResult.code,
authResult: authResult, authResult: authResult,
appleInfo,
}) })
}, },
errorCallback, errorCallback,
...@@ -87,7 +89,7 @@ export const login = defineAsyncApi<API_TYPE_LOGIN>( ...@@ -87,7 +89,7 @@ export const login = defineAsyncApi<API_TYPE_LOGIN>(
} }
// 先注销再登录 // 先注销再登录
// apple登录logout之后无法重新触发获取email,fullname;一键登录无logout // apple登录logout之后无法重新触发获取email,fullname;一键登录无logout
if (provider === 'apple' || provider === 'univerify') { if (isAppleLogin || provider === 'univerify') {
login() login()
} else { } else {
service.logout(login, login) service.logout(login, login)
...@@ -261,19 +263,19 @@ class UniverifyManager implements UniApp.UniverifyManager { ...@@ -261,19 +263,19 @@ class UniverifyManager implements UniApp.UniverifyManager {
eventName: string = 'api.univerifyButtonsClick' eventName: string = 'api.univerifyButtonsClick'
close() { close() {
closeAuthView() return closeAuthView()
} }
login(options: UniApp.UniverifyLoginOptions) { login(options: UniApp.UniverifyLoginOptions) {
login(this._getOptions(options)) return login(this._getOptions(options))
} }
getCheckBoxState(options: UniApp.GetCheckBoxStateOptions) { getCheckBoxState(options: UniApp.GetCheckBoxStateOptions) {
getCheckBoxState(options) return getCheckBoxState(options)
} }
preLogin(options?: UniApp.CallBackOptions) { preLogin(options?: UniApp.CallBackOptions) {
preLogin(this._getOptions(options)) return preLogin(this._getOptions(options))
} }
onButtonsClick(callback: UniApp.CallbackFunction) { onButtonsClick(callback: UniApp.CallbackFunction) {
......
...@@ -40,7 +40,7 @@ const TYPES = { ...@@ -40,7 +40,7 @@ const TYPES = {
}, },
} }
const parseParams = <T extends Data>(args: UniApp.ShareOptions): T | string => { const parseParams = (args: UniApp.ShareOptions) => {
args.type = args.type || 0 args.type = args.type || 0
let { let {
...@@ -53,6 +53,9 @@ const parseParams = <T extends Data>(args: UniApp.ShareOptions): T | string => { ...@@ -53,6 +53,9 @@ const parseParams = <T extends Data>(args: UniApp.ShareOptions): T | string => {
mediaUrl: media, mediaUrl: media,
scene, scene,
miniProgram, miniProgram,
openCustomerServiceChat,
corpid,
customerUrl: url,
} = args } = args
if (typeof imageUrl === 'string' && imageUrl) { if (typeof imageUrl === 'string' && imageUrl) {
...@@ -74,55 +77,66 @@ const parseParams = <T extends Data>(args: UniApp.ShareOptions): T | string => { ...@@ -74,55 +77,66 @@ const parseParams = <T extends Data>(args: UniApp.ShareOptions): T | string => {
extra: { extra: {
scene, scene,
}, },
openCustomerServiceChat,
corpid,
url,
} }
if (provider === 'weixin' && (type === 1 || type === 2)) { if (provider === 'weixin' && (type === 1 || type === 2)) {
delete sendMsg.thumbs delete sendMsg.thumbs
} }
return sendMsg as unknown as T return sendMsg
} }
return '分享参数 type 不正确' return '分享参数 type 不正确'
} }
type ParseParams = ReturnType<typeof parseParams>
const sendShareMsg = function ( const sendShareMsg = function (
service: PlusShareShareService, service: PlusShareShareService,
params: Data, params: Exclude<ParseParams, string>,
resolve: (args?: any) => void, resolve: (args?: any) => void,
reject: (errMsg: string, errRes?: any) => void, reject: (errMsg: string, errRes?: any) => void,
method = 'share' method = 'share'
) { ) {
const errorCallback = warpPlusErrorCallback(reject) const errorCallback = warpPlusErrorCallback(reject)
const serviceMethod = params.openCustomerServiceChat
service.send( ? 'openCustomerServiceChat'
params, : 'send'
() => { try {
resolve() // @ts-expect-error openCustomerServiceChat
}, service[serviceMethod](
errorCallback params,
) () => {
resolve()
},
errorCallback
)
} catch (error) {
errorCallback({
message: `${params.provider} ${serviceMethod} 方法调用失败`,
})
}
} }
export const share = defineAsyncApi<API_TYPE_SHARE>( export const share = defineAsyncApi<API_TYPE_SHARE>(
API_SHREA, API_SHREA,
(params, { resolve, reject }) => { (params, { resolve, reject }) => {
const res = parseParams<typeof params>(params) const parsedParams = parseParams(params)
const errorCallback = warpPlusErrorCallback(reject) const errorCallback = warpPlusErrorCallback(reject)
if (typeof res === 'string') { if (typeof parsedParams === 'string') {
return reject(res) return reject(parsedParams)
} else {
params = res
} }
plus.share.getServices((services) => { plus.share.getServices((services) => {
const service = services.find(({ id }) => id === params.provider) const service = services.find(({ id }) => id === parsedParams.provider)
if (!service) { if (!service) {
reject('service not found') reject('service not found')
} else { } else {
if (service.authenticated) { if (service.authenticated) {
sendShareMsg(service, params, resolve, reject) sendShareMsg(service, parsedParams, resolve, reject)
} else { } else {
service.authorize( service.authorize(
() => sendShareMsg(service, params, resolve, reject), () => sendShareMsg(service, parsedParams, resolve, reject),
errorCallback errorCallback
) )
} }
......
...@@ -4,7 +4,7 @@ importers: ...@@ -4,7 +4,7 @@ importers:
.: .:
specifiers: specifiers:
'@dcloudio/types': ^2.5.17 '@dcloudio/types': ^2.5.18
'@dcloudio/uni-api': 3.0.0-alpha-3040220220310001 '@dcloudio/uni-api': 3.0.0-alpha-3040220220310001
'@dcloudio/uni-app': 3.0.0-alpha-3040220220310001 '@dcloudio/uni-app': 3.0.0-alpha-3040220220310001
'@jest/types': ^27.0.2 '@jest/types': ^27.0.2
...@@ -51,7 +51,7 @@ importers: ...@@ -51,7 +51,7 @@ importers:
vue-router: ^4.0.13 vue-router: ^4.0.13
yorkie: ^2.0.0 yorkie: ^2.0.0
devDependencies: devDependencies:
'@dcloudio/types': 2.5.17 '@dcloudio/types': 2.5.18
'@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.4.2 '@jest/types': 27.4.2
...@@ -2480,8 +2480,8 @@ packages: ...@@ -2480,8 +2480,8 @@ packages:
lodash.once: 4.1.1 lodash.once: 4.1.1
dev: true dev: true
/@dcloudio/types/2.5.17: /@dcloudio/types/2.5.18:
resolution: {integrity: sha512-PMxXWdFOAmDQUo7BNx19O4htfaztdOT7RuD5jTVm8/jFcUd/hkNJJXLcSLePqXZwyTjjirstLBhC3FU709Y+8Q==} resolution: {integrity: sha512-1EMwZsi5j9KHI5wdLwZJmUyo5b8HnG60CRqsqW5kcd3cgSrKtgL3EKCYUjmJw+3gd9G/4NeEkSx5pT5l+4rNXg==}
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.
先完成此消息的编辑!
想要评论请 注册