From fb8103b7b8b040632f189ebe7772a4e5c5305c76 Mon Sep 17 00:00:00 2001 From: rex Date: Mon, 10 May 2021 20:49:20 +0800 Subject: [PATCH 1/3] chore(open-type): merge open type mixin into button mixin --- packages/action-sheet/index.ts | 3 +-- packages/button/index.ts | 3 +-- packages/cell/index.wxml | 1 + packages/dialog/index.ts | 5 ++-- packages/goods-action-button/index.ts | 3 +-- packages/goods-action-icon/index.ts | 3 +-- packages/image/index.ts | 3 +-- packages/mixins/button.ts | 27 ++++++++++++++++++++++ packages/mixins/open-type.ts | 33 --------------------------- 9 files changed, 35 insertions(+), 46 deletions(-) delete mode 100644 packages/mixins/open-type.ts diff --git a/packages/action-sheet/index.ts b/packages/action-sheet/index.ts index a539e9809..79dd4c621 100644 --- a/packages/action-sheet/index.ts +++ b/packages/action-sheet/index.ts @@ -1,9 +1,8 @@ import { VantComponent } from '../common/component'; import { button } from '../mixins/button'; -import { openType } from '../mixins/open-type'; VantComponent({ - mixins: [button, openType], + mixins: [button], props: { show: Boolean, title: String, diff --git a/packages/button/index.ts b/packages/button/index.ts index 9c60e75df..d503eacad 100644 --- a/packages/button/index.ts +++ b/packages/button/index.ts @@ -1,9 +1,8 @@ import { VantComponent } from '../common/component'; import { button } from '../mixins/button'; -import { openType } from '../mixins/open-type'; import { canIUseFormFieldButton } from '../common/version'; -const mixins = [button, openType]; +const mixins = [button]; if (canIUseFormFieldButton()) { mixins.push('wx://form-field-button'); } diff --git a/packages/cell/index.wxml b/packages/cell/index.wxml index 7d7d746d9..8387c3c8c 100644 --- a/packages/cell/index.wxml +++ b/packages/cell/index.wxml @@ -20,6 +20,7 @@ style="{{ computed.titleStyle({ titleWidth, titleStyle }) }}" class="van-cell__title title-class" > + {{ title }} diff --git a/packages/dialog/index.ts b/packages/dialog/index.ts index feaa562de..fecb363ce 100644 --- a/packages/dialog/index.ts +++ b/packages/dialog/index.ts @@ -1,12 +1,11 @@ import { VantComponent } from '../common/component'; import { button } from '../mixins/button'; -import { openType } from '../mixins/open-type'; import { GRAY, RED } from '../common/color'; import { toPromise } from '../common/utils'; import type { Action } from './dialog'; VantComponent({ - mixins: [button, openType], + mixins: [button], props: { show: { @@ -75,7 +74,7 @@ VantComponent({ callback: ((() => {}) as unknown) as ( action: string, context: WechatMiniprogram.Component.TrivialInstance - ) => {}, + ) => void, }, methods: { diff --git a/packages/goods-action-button/index.ts b/packages/goods-action-button/index.ts index 883ab99ec..5f5c1d6d3 100644 --- a/packages/goods-action-button/index.ts +++ b/packages/goods-action-button/index.ts @@ -2,10 +2,9 @@ import { VantComponent } from '../common/component'; import { useParent } from '../common/relation'; import { button } from '../mixins/button'; import { link } from '../mixins/link'; -import { openType } from '../mixins/open-type'; VantComponent({ - mixins: [link, button, openType], + mixins: [link, button], relation: useParent('goods-action'), diff --git a/packages/goods-action-icon/index.ts b/packages/goods-action-icon/index.ts index 89dcfa9a4..65feadfa3 100644 --- a/packages/goods-action-icon/index.ts +++ b/packages/goods-action-icon/index.ts @@ -1,12 +1,11 @@ import { VantComponent } from '../common/component'; import { button } from '../mixins/button'; import { link } from '../mixins/link'; -import { openType } from '../mixins/open-type'; VantComponent({ classes: ['icon-class', 'text-class'], - mixins: [link, button, openType], + mixins: [link, button], props: { text: String, diff --git a/packages/image/index.ts b/packages/image/index.ts index 476902a6f..14766b3e1 100644 --- a/packages/image/index.ts +++ b/packages/image/index.ts @@ -1,9 +1,8 @@ import { VantComponent } from '../common/component'; import { button } from '../mixins/button'; -import { openType } from '../mixins/open-type'; VantComponent({ - mixins: [button, openType], + mixins: [button], classes: ['custom-class', 'loading-class', 'error-class', 'image-class'], diff --git a/packages/mixins/button.ts b/packages/mixins/button.ts index 4e1050bf7..b93056b6d 100644 --- a/packages/mixins/button.ts +++ b/packages/mixins/button.ts @@ -12,5 +12,32 @@ export const button = Behavior({ showMessageCard: Boolean, appParameter: String, ariaLabel: String, + openType: String, + }, + + methods: { + bindGetUserInfo(event: WechatMiniprogram.ButtonGetUserInfo) { + this.triggerEvent('getuserinfo', event.detail); + }, + + bindContact(event: WechatMiniprogram.ButtonContact) { + this.triggerEvent('contact', event.detail); + }, + + bindGetPhoneNumber(event: WechatMiniprogram.ButtonGetPhoneNumber) { + this.triggerEvent('getphonenumber', event.detail); + }, + + bindError(event: WechatMiniprogram.ButtonError) { + this.triggerEvent('error', event.detail); + }, + + bindLaunchApp(event: WechatMiniprogram.ButtonLaunchApp) { + this.triggerEvent('launchapp', event.detail); + }, + + bindOpenSetting(event: WechatMiniprogram.ButtonOpenSetting) { + this.triggerEvent('opensetting', event.detail); + }, }, }); diff --git a/packages/mixins/open-type.ts b/packages/mixins/open-type.ts deleted file mode 100644 index 0c0fa5107..000000000 --- a/packages/mixins/open-type.ts +++ /dev/null @@ -1,33 +0,0 @@ -// @ts-nocheck - -export const openType = Behavior({ - properties: { - openType: String, - }, - - methods: { - bindGetUserInfo(event: WechatMiniprogram.ButtonGetUserInfo) { - this.$emit('getuserinfo', event.detail); - }, - - bindContact(event: WechatMiniprogram.ButtonContact) { - this.$emit('contact', event.detail); - }, - - bindGetPhoneNumber(event: WechatMiniprogram.ButtonGetPhoneNumber) { - this.$emit('getphonenumber', event.detail); - }, - - bindError(event: WechatMiniprogram.ButtonError) { - this.$emit('error', event.detail); - }, - - bindLaunchApp(event: WechatMiniprogram.ButtonLaunchApp) { - this.$emit('launchapp', event.detail); - }, - - bindOpenSetting(event: WechatMiniprogram.ButtonOpenSetting) { - this.$emit('opensetting', event.detail); - }, - }, -}); From 5a5563fcb1ed006ff1bdd7f0f457d422d3b1a746 Mon Sep 17 00:00:00 2001 From: rex Date: Mon, 10 May 2021 20:58:28 +0800 Subject: [PATCH 2/3] chore(button): shorten open type method names --- packages/action-sheet/index.wxml | 12 ++++++------ packages/button/index.wxml | 12 ++++++------ packages/dialog/index.wxml | 24 ++++++++++++------------ packages/goods-action-button/index.wxml | 12 ++++++------ packages/goods-action-icon/index.wxml | 12 ++++++------ packages/mixins/button.ts | 12 ++++++------ 6 files changed, 42 insertions(+), 42 deletions(-) diff --git a/packages/action-sheet/index.wxml b/packages/action-sheet/index.wxml index c2bebcacf..a208017c1 100644 --- a/packages/action-sheet/index.wxml +++ b/packages/action-sheet/index.wxml @@ -33,12 +33,12 @@ hover-class="van-action-sheet__item--hover" data-index="{{ index }}" bind:tap="onSelect" - bindgetuserinfo="bindGetUserInfo" - bindcontact="bindContact" - bindgetphonenumber="bindGetPhoneNumber" - binderror="bindError" - bindlaunchapp="bindLaunchApp" - bindopensetting="bindOpenSetting" + bindgetuserinfo="onGetUserInfo" + bindcontact="onContact" + bindgetphonenumber="onGetPhoneNumber" + binderror="onError" + bindlaunchapp="onLaunchApp" + bindopensetting="onOpenSetting" lang="{{ lang }}" session-from="{{ sessionFrom }}" send-message-title="{{ sendMessageTitle }}" diff --git a/packages/button/index.wxml b/packages/button/index.wxml index e4cec8aeb..efb4b2b8a 100644 --- a/packages/button/index.wxml +++ b/packages/button/index.wxml @@ -19,12 +19,12 @@ app-parameter="{{ appParameter }}" aria-label="{{ ariaLabel }}" bindtap="{{ !disabled ? 'onClick' : 'noop' }}" - bindgetuserinfo="bindGetUserInfo" - bindcontact="bindContact" - bindgetphonenumber="bindGetPhoneNumber" - binderror="bindError" - bindlaunchapp="bindLaunchApp" - bindopensetting="bindOpenSetting" + bindgetuserinfo="onGetUserInfo" + bindcontact="onContact" + bindgetphonenumber="onGetPhoneNumber" + binderror="onError" + bindlaunchapp="onLaunchApp" + bindopensetting="onOpenSetting" > {{ confirmButtonText }} @@ -100,12 +100,12 @@ app-parameter="{{ appParameter }}" bind:click="onConfirm" - bindgetuserinfo="bindGetUserInfo" - bindcontact="bindContact" - bindgetphonenumber="bindGetPhoneNumber" - binderror="bindError" - bindlaunchapp="bindLaunchApp" - bindopensetting="bindOpenSetting" + bindgetuserinfo="onGetUserInfo" + bindcontact="onContact" + bindgetphonenumber="onGetPhoneNumber" + binderror="onError" + bindlaunchapp="onLaunchApp" + bindopensetting="onOpenSetting" > {{ confirmButtonText }} diff --git a/packages/goods-action-button/index.wxml b/packages/goods-action-button/index.wxml index 3912cedb0..4505f212e 100644 --- a/packages/goods-action-button/index.wxml +++ b/packages/goods-action-button/index.wxml @@ -18,12 +18,12 @@ show-message-card="{{ showMessageCard }}" send-message-title="{{ sendMessageTitle }}" bind:click="onClick" - binderror="bindError" - bindcontact="bindContact" - bindopensetting="bindOpenSetting" - bindgetuserinfo="bindGetUserInfo" - bindgetphonenumber="bindGetPhoneNumber" - bindlaunchapp="bindLaunchApp" + binderror="onError" + bindcontact="onContact" + bindopensetting="onOpenSetting" + bindgetuserinfo="onGetUserInfo" + bindgetphonenumber="onGetPhoneNumber" + bindlaunchapp="onLaunchApp" > {{ text }} diff --git a/packages/goods-action-icon/index.wxml b/packages/goods-action-icon/index.wxml index 1983cae46..65b7ced3d 100644 --- a/packages/goods-action-icon/index.wxml +++ b/packages/goods-action-icon/index.wxml @@ -15,12 +15,12 @@ show-message-card="{{ showMessageCard }}" send-message-title="{{ sendMessageTitle }}" bind:click="onClick" - binderror="bindError" - bindcontact="bindContact" - bindopensetting="bindOpenSetting" - bindgetuserinfo="bindGetUserInfo" - bindgetphonenumber="bindGetPhoneNumber" - bindlaunchapp="bindLaunchApp" + binderror="onError" + bindcontact="onContact" + bindopensetting="onOpenSetting" + bindgetuserinfo="onGetUserInfo" + bindgetphonenumber="onGetPhoneNumber" + bindlaunchapp="onLaunchApp" > Date: Tue, 11 May 2021 12:02:45 +0800 Subject: [PATCH 3/3] feat(open-type): support getUserProfile --- example/project.config.json | 7 +++++-- packages/action-sheet/index.ts | 16 +++++++++++++--- packages/action-sheet/index.wxml | 4 ++-- packages/button/index.ts | 17 ++++++++++++----- packages/button/index.wxml | 4 ++-- packages/common/version.ts | 4 ++++ packages/definitions/index.ts | 2 +- packages/mixins/button.ts | 7 +++++++ 8 files changed, 46 insertions(+), 15 deletions(-) diff --git a/example/project.config.json b/example/project.config.json index cd039eb6f..187e5f0f1 100644 --- a/example/project.config.json +++ b/example/project.config.json @@ -21,24 +21,27 @@ "checkSiteMap": true, "uploadWithSourceMap": true, "compileHotReLoad": false, - "useMultiFrameRuntime": false, + "useMultiFrameRuntime": true, "useApiHook": true, + "useApiHostProcess": false, "babelSetting": { "ignore": [], "disablePlugins": [], "outputPath": "" }, + "enableEngineNative": false, "bundle": false, "useIsolateContext": true, "useCompilerModule": true, "userConfirmedUseCompilerModuleSwitch": false, + "userConfirmedBundleSwitch": false, "packNpmManually": false, "packNpmRelationList": [], "minifyWXSS": true }, "compileType": "miniprogram", "cloudfunctionRoot": "functions/", - "libVersion": "2.3.0", + "libVersion": "2.3.2", "appid": "wx1c01b35002d3ba14", "projectname": "vant-weapp", "debugOptions": { diff --git a/packages/action-sheet/index.ts b/packages/action-sheet/index.ts index 79dd4c621..4fa3583ea 100644 --- a/packages/action-sheet/index.ts +++ b/packages/action-sheet/index.ts @@ -41,13 +41,23 @@ VantComponent({ methods: { onSelect(event: WechatMiniprogram.TouchEvent) { const { index } = event.currentTarget.dataset; - const item = this.data.actions[index]; - if (item && !item.disabled && !item.loading) { + const { actions, closeOnClickAction, canIUseGetUserProfile } = this.data; + const item = actions[index]; + if (item) { this.$emit('select', item); - if (this.data.closeOnClickAction) { + if (closeOnClickAction) { this.onClose(); } + + if (item.openType === 'getUserInfo' && canIUseGetUserProfile) { + wx.getUserProfile({ + desc: item.getUserProfileDesc || ' ', + complete: (userProfile) => { + this.$emit('getuserinfo', userProfile); + }, + }); + } } }, diff --git a/packages/action-sheet/index.wxml b/packages/action-sheet/index.wxml index a208017c1..24d24ac67 100644 --- a/packages/action-sheet/index.wxml +++ b/packages/action-sheet/index.wxml @@ -27,12 +27,12 @@