mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
feat(open-type): support getUserProfile (#4203)
* chore(open-type): merge open type mixin into button mixin * chore(button): shorten open type method names * feat(open-type): support getUserProfile
This commit is contained in:
parent
44da05bec4
commit
c0db43fc88
@ -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": {
|
||||
|
@ -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,
|
||||
@ -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);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -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 }}"
|
||||
|
@ -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');
|
||||
}
|
||||
@ -54,12 +53,19 @@ VantComponent({
|
||||
},
|
||||
|
||||
methods: {
|
||||
onClick() {
|
||||
if (!this.data.loading) {
|
||||
this.$emit('click');
|
||||
}
|
||||
},
|
||||
onClick(event: WechatMiniprogram.TouchEvent) {
|
||||
this.$emit('click', event);
|
||||
|
||||
noop() {},
|
||||
const { canIUseGetUserProfile, openType, getUserProfileDesc } = this.data;
|
||||
|
||||
if (openType === 'getUserInfo' && canIUseGetUserProfile) {
|
||||
wx.getUserProfile({
|
||||
desc: getUserProfileDesc || ' ',
|
||||
complete: (userProfile) => {
|
||||
this.$emit('getuserinfo', userProfile);
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
@ -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 }}"
|
||||
@ -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
|
||||
|
@ -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" />
|
||||
|
||||
|
@ -56,3 +56,7 @@ export function canIUseNextTick() {
|
||||
export function canIUseCanvas2d() {
|
||||
return gte('2.9.0');
|
||||
}
|
||||
|
||||
export function canIUseGetUserProfile() {
|
||||
return !!wx.getUserProfile;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ export type VantComponentOptions<
|
||||
Data & {
|
||||
name: string;
|
||||
value: any;
|
||||
},
|
||||
} & Record<string, any>,
|
||||
Props,
|
||||
Methods
|
||||
> &
|
||||
|
@ -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: {
|
||||
|
@ -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>
|
||||
@ -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>
|
||||
|
@ -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'),
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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,
|
||||
|
@ -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 }}"
|
||||
|
@ -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'],
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { canIUseGetUserProfile } from '../common/version';
|
||||
|
||||
export const button = Behavior({
|
||||
externalClasses: ['hover-class'],
|
||||
|
||||
@ -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);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
@ -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);
|
||||
},
|
||||
},
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user