Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(open-type): support getUserProfile #4203

Merged
merged 3 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions example/project.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
19 changes: 14 additions & 5 deletions packages/action-sheet/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -42,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);
},
});
}
}
},

Expand Down
16 changes: 8 additions & 8 deletions packages/action-sheet/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
<button
wx:for="{{ actions }}"
wx:key="index"
open-type="{{ item.openType }}"
open-type="{{ item.disabled || item.loading || canIUseGetUserProfile ? '' : item.openType }}"
style="{{ item.color ? 'color: ' + item.color : '' }}"
class="{{ utils.bem('action-sheet__item', { disabled: item.disabled || item.loading }) }} {{ item.className || '' }}"
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"
bindtap="{{ item.disabled || item.loading ? '' : 'onSelect' }}"
bindgetuserinfo="onGetUserInfo"
bindcontact="onContact"
bindgetphonenumber="onGetPhoneNumber"
binderror="onError"
bindlaunchapp="onLaunchApp"
bindopensetting="onOpenSetting"
lang="{{ lang }}"
session-from="{{ sessionFrom }}"
send-message-title="{{ sendMessageTitle }}"
Expand Down
20 changes: 13 additions & 7 deletions packages/button/index.ts
Original file line number Diff line number Diff line change
@@ -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');
}
Expand Down Expand Up @@ -54,12 +53,19 @@ VantComponent({
},

methods: {
onClick() {
if (!this.data.loading) {
this.$emit('click');
onClick(event: WechatMiniprogram.TouchEvent) {
this.$emit('click', event);

const { canIUseGetUserProfile, openType, getUserProfileDesc } = this.data;

if (openType === 'getUserInfo' && canIUseGetUserProfile) {
wx.getUserProfile({
desc: getUserProfileDesc || ' ',
complete: (userProfile) => {
this.$emit('getuserinfo', userProfile);
},
});
}
},

noop() {},
},
});
16 changes: 8 additions & 8 deletions packages/button/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
lang="{{ lang }}"
form-type="{{ formType }}"
style="{{ computed.rootStyle({ plain, color, customStyle }) }}"
open-type="{{ disabled ? '' : openType }}"
open-type="{{ disabled || loading || canIUseGetUserProfile ? '' : openType }}"
business-id="{{ businessId }}"
session-from="{{ sessionFrom }}"
send-message-title="{{ sendMessageTitle }}"
Expand All @@ -18,13 +18,13 @@
show-message-card="{{ showMessageCard }}"
app-parameter="{{ appParameter }}"
aria-label="{{ ariaLabel }}"
bindtap="{{ !disabled ? 'onClick' : 'noop' }}"
bindgetuserinfo="bindGetUserInfo"
bindcontact="bindContact"
bindgetphonenumber="bindGetPhoneNumber"
binderror="bindError"
bindlaunchapp="bindLaunchApp"
bindopensetting="bindOpenSetting"
bindtap="{{ disabled || loading ? '' : 'onClick' }}"
bindgetuserinfo="onGetUserInfo"
bindcontact="onContact"
bindgetphonenumber="onGetPhoneNumber"
binderror="onError"
bindlaunchapp="onLaunchApp"
bindopensetting="onOpenSetting"
>
<block wx:if="{{ loading }}">
<van-loading
Expand Down
1 change: 1 addition & 0 deletions packages/cell/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
style="{{ computed.titleStyle({ titleWidth, titleStyle }) }}"
class="van-cell__title title-class"
>

<block wx:if="{{ title }}">{{ title }}</block>
<slot wx:else name="title" />

Expand Down
4 changes: 4 additions & 0 deletions packages/common/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ export function canIUseNextTick() {
export function canIUseCanvas2d() {
return gte('2.9.0');
}

export function canIUseGetUserProfile() {
return !!wx.getUserProfile;
}
2 changes: 1 addition & 1 deletion packages/definitions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type VantComponentOptions<
Data & {
name: string;
value: any;
},
} & Record<string, any>,
Props,
Methods
> &
Expand Down
5 changes: 2 additions & 3 deletions packages/dialog/index.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down Expand Up @@ -75,7 +74,7 @@ VantComponent({
callback: ((() => {}) as unknown) as (
action: string,
context: WechatMiniprogram.Component.TrivialInstance
) => {},
) => void,
},

methods: {
Expand Down
24 changes: 12 additions & 12 deletions packages/dialog/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,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 }}
</van-goods-action-button>
Expand Down Expand Up @@ -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 }}
</van-button>
Expand Down
3 changes: 1 addition & 2 deletions packages/goods-action-button/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),

Expand Down
12 changes: 6 additions & 6 deletions packages/goods-action-button/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
<slot></slot>
Expand Down
3 changes: 1 addition & 2 deletions packages/goods-action-icon/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
12 changes: 6 additions & 6 deletions packages/goods-action-icon/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<van-icon
wx:if="{{ icon }}"
Expand Down
3 changes: 1 addition & 2 deletions packages/image/index.ts
Original file line number Diff line number Diff line change
@@ -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'],

Expand Down
34 changes: 34 additions & 0 deletions packages/mixins/button.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { canIUseGetUserProfile } from '../common/version';

export const button = Behavior({
externalClasses: ['hover-class'],

Expand All @@ -12,5 +14,37 @@ export const button = Behavior({
showMessageCard: Boolean,
appParameter: String,
ariaLabel: String,
openType: String,
getUserProfileDesc: String,
},

data: {
canIUseGetUserProfile: canIUseGetUserProfile(),
},

methods: {
onGetUserInfo(event: WechatMiniprogram.ButtonGetUserInfo) {
this.triggerEvent('getuserinfo', event.detail);
},

onContact(event: WechatMiniprogram.ButtonContact) {
this.triggerEvent('contact', event.detail);
},

onGetPhoneNumber(event: WechatMiniprogram.ButtonGetPhoneNumber) {
this.triggerEvent('getphonenumber', event.detail);
},

onError(event: WechatMiniprogram.ButtonError) {
this.triggerEvent('error', event.detail);
},

onLaunchApp(event: WechatMiniprogram.ButtonLaunchApp) {
this.triggerEvent('launchapp', event.detail);
},

onOpenSetting(event: WechatMiniprogram.ButtonOpenSetting) {
this.triggerEvent('opensetting', event.detail);
},
},
});
33 changes: 0 additions & 33 deletions packages/mixins/open-type.ts

This file was deleted.