Compare commits

...

4 Commits

Author SHA1 Message Date
chenjiahan
cde3876fb0 fix(NoticeBar): incorrect scroll speed 2021-05-11 15:43:53 +08:00
rex
c0db43fc88
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
2021-05-11 15:24:04 +08:00
echofly
44da05bec4
fix(notice-bar): adjust scrollable behavior (#4201) 2021-05-11 15:16:05 +08:00
rex
62f7d2b65e
feat(panel): remove useFooterSlot (#4205) 2021-05-11 15:12:32 +08:00
24 changed files with 140 additions and 120 deletions

View File

@ -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": {

View File

@ -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);
},
});
}
}
},

View File

@ -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 }}"

View File

@ -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);
const { canIUseGetUserProfile, openType, getUserProfileDesc } = this.data;
if (openType === 'getUserInfo' && canIUseGetUserProfile) {
wx.getUserProfile({
desc: getUserProfileDesc || ' ',
complete: (userProfile) => {
this.$emit('getuserinfo', userProfile);
},
});
}
},
noop() {},
},
});

View File

@ -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

View File

@ -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" />

View File

@ -56,3 +56,7 @@ export function canIUseNextTick() {
export function canIUseCanvas2d() {
return gte('2.9.0');
}
export function canIUseGetUserProfile() {
return !!wx.getUserProfile;
}

View File

@ -37,7 +37,7 @@ export type VantComponentOptions<
Data & {
name: string;
value: any;
},
} & Record<string, any>,
Props,
Methods
> &

View File

@ -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: {

View File

@ -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>

View File

@ -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'),

View File

@ -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>

View File

@ -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,

View File

@ -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 }}"

View File

@ -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'],

View File

@ -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);
},
},
});

View File

@ -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);
},
},
});

View File

@ -101,8 +101,8 @@
| background | 滚动条背景 | _string_ | `#fffbe8` |
| left-icon | 左侧[图标名称](#/icon)或图片链接 | _string_ | - |
| delay | 动画延迟时间 (s) | _number_ | `1` |
| speed | 滚动速率 (px/s) | _number_ | `50` |
| scrollable | 是否开启滚动播放,内容长度溢出时默认开启 | _boolean_ | `true` |
| speed | 滚动速率 (px/s) | _number_ | `60` |
| scrollable | 是否开启滚动播放,内容长度溢出时默认开启 | _boolean_ | - |
| wrapable | 是否开启文本换行,只在禁用滚动时生效 | _boolean_ | `false` |
| open-type | 微信开放能力 | _string_ | `navigate` |

View File

@ -26,13 +26,10 @@ VantComponent({
},
speed: {
type: Number,
value: 50,
value: 60,
observer: 'init',
},
scrollable: {
type: Boolean,
value: true,
},
scrollable: null,
leftIcon: {
type: String,
value: '',
@ -70,19 +67,20 @@ VantComponent({
getRect(this, '.van-notice-bar__wrap'),
]).then((rects) => {
const [contentRect, wrapRect] = rects;
const { speed, scrollable, delay } = this.data;
if (
contentRect == null ||
wrapRect == null ||
!contentRect.width ||
!wrapRect.width
!wrapRect.width ||
scrollable === false
) {
return;
}
const { speed, scrollable, delay } = this.data;
if (scrollable || wrapRect.width < contentRect.width) {
const duration = (contentRect.width / speed) * 1000;
const duration =
((wrapRect.width + contentRect.width) / speed) * 1000;
this.wrapWidth = wrapRect.width;
this.contentWidth = contentRect.width;

View File

@ -16,7 +16,7 @@
<slot wx:else name="left-icon" />
<view class="van-notice-bar__wrap">
<view class="van-notice-bar__content {{ !scrollable && !wrapable ? 'van-ellipsis' : '' }}" animation="{{ animationData }}">
<view class="van-notice-bar__content {{ scrollable === false && !wrapable ? 'van-ellipsis' : '' }}" animation="{{ animationData }}">
{{ text }}
<slot wx:if="{{ !text }}"></slot>
</view>

View File

@ -27,7 +27,7 @@
使用`slot`自定义内容。
```html
<van-panel title="标题" desc="描述信息" status="状态" use-footer-slot>
<van-panel title="标题" desc="描述信息" status="状态">
<view>内容</view>
<view slot="footer">
<van-button size="small">按钮</van-button>
@ -40,12 +40,11 @@
### Props
| 参数 | 说明 | 类型 | 默认值 | 版本 |
| --------------- | -------------------- | --------- | ------- | ---- |
| title | 标题 | _string_ | - | - |
| desc | 描述 | _string_ | - | - |
| status | 状态 | _string_ | - | - |
| use-footer-slot | 是否使用 footer slot | _boolean_ | `false` | - |
| 参数 | 说明 | 类型 | 默认值 | 版本 |
| ------ | ---- | -------- | ------ | ---- |
| title | 标题 | _string_ | - | - |
| desc | 描述 | _string_ | - | - |
| status | 状态 | _string_ | - | - |
### Slot
@ -53,7 +52,7 @@
| ------ | -------------------------------------------------------------- |
| - | 自定义内容 |
| header | 自定义 header如果设置了`title``desc``status`属性则不生效 |
| footer | 自定义 footer,需要设置 `use-footer-slot`属性 |
| footer | 自定义 footer |
### 外部样式类

View File

@ -10,5 +10,9 @@
&__footer {
.theme(padding,'@panel-footer-padding');
&:empty {
display: none;
}
}
}

View File

@ -7,6 +7,5 @@ VantComponent({
desc: String,
title: String,
status: String,
useFooterSlot: Boolean,
},
});

View File

@ -1,5 +1,5 @@
<view class="van-panel van-hairline--top-bottom custom-class">
<van-cell
<van-cell
wx:if="{{ title || desc || status }}"
title="{{ title }}"
label="{{ desc }}"
@ -13,7 +13,7 @@
<slot />
</view>
<view wx:if="{{ useFooterSlot }}" class="van-panel__footer van-hairline--top footer-class">
<view class="van-panel__footer van-hairline--top footer-class">
<slot name="footer" />
</view>
</view>