Compare commits

...

5 Commits

Author SHA1 Message Date
landluck
33e1725b0a
fix(uploader): fix preview video index error (#5142) 2022-12-14 10:25:36 +08:00
landluck
91a12bbaaf
fix(dialog): fixed extra lines without button (#5141) 2022-12-14 10:25:02 +08:00
landluck
76522a173f
feat(tab): add before-change event support (#5139)
* feat(tab): add before-change event support

* docs(tab): delete unnecessary content
2022-12-14 10:24:32 +08:00
landluck
e7426dba36
fix(dropdown): fix last item style on text over (#5145) 2022-12-14 10:12:52 +08:00
landluck
5ef53f25e0
fix(search): optimize the Cancel button click area (#5148)
* fix(search): optimize the Cancel button click area

* test(search): fix test case failed
2022-12-14 10:12:32 +08:00
12 changed files with 308 additions and 29 deletions

View File

@ -645,7 +645,7 @@
@dropdown-menu-title-text-color: @text-color;
@dropdown-menu-title-active-text-color: @red;
@dropdown-menu-title-disabled-text-color: @gray-6;
@dropdown-menu-title-padding: 0 @padding-xs;
@dropdown-menu-title-padding: 0 @padding-lg 0 @padding-xs;
@dropdown-menu-title-line-height: 18px;
@dropdown-menu-option-active-color: @red;
@dropdown-menu-box-shadow: 0 2px 12px fade(@gray-7, 12);

View File

@ -69,7 +69,7 @@
</van-goods-action-button>
</van-goods-action>
<view wx:else class="van-hairline--top van-dialog__footer">
<view wx:elif="{{ showCancelButton || showConfirmButton }}" class="van-hairline--top van-dialog__footer">
<van-button
wx:if="{{ showCancelButton }}"
size="large"

View File

@ -56,7 +56,7 @@
&::after {
position: absolute;
top: 50%;
right: -4px;
right: 11px;
margin-top: -5px;
border: 3px solid;
border-color: transparent transparent currentColor currentColor;

View File

@ -38,7 +38,6 @@
}
&__action {
padding: var(--search-action-padding, @search-action-padding);
font-size: var(--search-action-font-size, @search-action-font-size);
line-height: var(--search-input-height, @search-input-height);
color: var(--search-action-text-color, @search-action-text-color);
@ -46,5 +45,9 @@
&--hover {
background-color: @active-color;
}
&-button {
padding: var(--search-action-padding, @search-action-padding);
}
}
}

View File

@ -48,6 +48,6 @@
hover-stay-time="70"
>
<slot wx:if="{{ useActionSlot }}" name="action" />
<view wx:else bind:tap="onCancel" class="cancel-class">{{ actionText }}</view>
<view wx:else bind:tap="onCancel" class="van-search__action-button cancel-class">{{ actionText }}</view>
</view>
</view>

View File

@ -222,7 +222,7 @@ exports[`should render demo and match snapshot 1`] = `
hoverStayTime="70"
>
<wx-view
class="cancel-class"
class="van-search__action-button cancel-class"
bind:tap="onCancel"
>
取消

View File

@ -185,6 +185,49 @@ Page({
</van-popup>
```
### 异步切换
通过 `before-change` 事件可以在切换标签前执行特定的逻辑,实现切换前校验、异步切换的目的
```html
<van-tabs active="{{ active }}" use-before-change="{{ true }}" bind:change="onChange" bind:before-change="onBeforeChange" >
<van-tab title="标签 1">内容 1</van-tab>
<van-tab title="标签 2">内容 2</van-tab>
<van-tab title="标签 3">内容 3</van-tab>
<van-tab title="标签 4">内容 4</van-tab>
</van-tabs>
```
```js
Page({
data: {
active: 1,
},
onChange(event) {
wx.showToast({
title: `切换到标签 ${event.detail.name}`,
icon: 'none',
});
},
onBeforeChange(event) {
const { callback, title } = event.detail;
wx.showModal({
title: '异步切换',
content: `确定要切换至 ${title} tab吗`,
success: (res) => {
if (res.confirm) {
callback(true)
} else if (res.cancel) {
callback(false)
}
},
})
}
});
```
## API
### Tabs Props
@ -208,6 +251,7 @@ Page({
| title-active-color | 标题选中态颜色 | _string_ | - |
| title-inactive-color | 标题默认态颜色 | _string_ | - |
| z-index | z-index 层级 | _number_ | `1` |
| use-before-change `v1.10.10` | 是否开启切换前校验 | _boolean_ | `false` |
### Tab Props
@ -238,18 +282,19 @@ Page({
| 事件名 | 说明 | 参数 |
| --- | --- | --- |
| bind:click | 点击标签时触发 | name标签标识符title标题 |
| bind:before-change `v1.10.10` | tab 切换前会触发,在回调函数中返回 `false` 可终止 tab 切换,绑定事件的同时需要将`use-before-change`属性设置为`true` | `event.detail.name`: 当前切换的 tab 标识符, `event.detail.title`: 当前切换的 tab 标题, `event.detail.index`: 当前切换的 tab 下标,`event.detail.callback`: 回调函数,调用`callback(false)`终止 tab 切换 |
| bind:change | 当前激活的标签改变时触发 | name标签标识符title标题 |
| bind:disabled | 点击被禁用的标签时触发 | name标签标识符title标题 |
| bind:scroll | 滚动时触发 | { scrollTop: 距离顶部位置, isFixed: 是否吸顶 } |
### 外部样式类
| 类名 | 说明 |
| ---------------- | ---------------- |
| custom-class | 根节点样式类 |
| nav-class | 标签栏样式类 |
| tab-class | 标签样式类 |
| tab-active-class | 标签激活态样式类 |
| 类名 | 说明 |
| ---------------- | ------------------ |
| custom-class | 根节点样式类 |
| nav-class | 标签栏样式类 |
| tab-class | 标签样式类 |
| tab-active-class | 标签激活态样式类 |
| wrap-class | 标签栏根节点样式类 |
### 方法

View File

@ -41,5 +41,20 @@ VantComponent({
icon: 'none',
});
},
onBeforeChange(event) {
const { callback, title } = event.detail;
wx.showModal({
title: '异步切换',
content: `确定要切换至 ${title} tab吗`,
success: (res) => {
if (res.confirm) {
callback(true);
} else if (res.cancel) {
callback(false);
}
},
});
},
},
});

View File

@ -147,3 +147,18 @@
</van-tab>
</van-tabs>
</demo-block>
<demo-block title="异步切换">
<van-tabs active="{{ 1 }}" swipeable use-before-change bind:change="onChange" bind:before-change="onBeforeChange" >
<van-tab
wx:for="{{ tabs4 }}"
wx:key="index"
title="{{ '标签 ' + item }}"
>
<view class="content">
{{ '内容' + item }}
</view>
</van-tab>
</van-tabs>
</demo-block>

View File

@ -1548,5 +1548,165 @@ exports[`should render demo and match snapshot 1`] = `
</van-tabs>
</wx-view>
</demo-block>
<demo-block>
<wx-view
class="custom-class demo-block van-clearfix "
>
<wx-view
class="demo-block__title"
>
异步切换
</wx-view>
<van-tabs
bind:before-change="onBeforeChange"
bind:change="onChange"
>
<wx-view
class="custom-class van-tabs van-tabs--line"
>
<van-sticky
bind:scroll="onTouchScroll"
>
<wx-view
class="custom-class van-sticky"
style="z-index:1"
>
<wx-view
class="van-sticky-wrap"
style="z-index:1"
>
<wx-view
class="van-tabs__wrap wrap-class"
>
<wx-scroll-view
class="van-tabs__scroll van-tabs__scroll--line"
scrollLeft="{{0}}"
scrollWithAnimation="{{false}}"
scrollX="{{false}}"
style=""
>
<wx-view
class="van-tabs__nav van-tabs__nav--line nav-class"
style=""
>
<wx-view
class="van-tabs__line"
style="width:40px;opacity:0;transform:translateX(0px);-webkit-transform:translateX(0px)"
/>
<wx-view
class="tab-class van-ellipsis van-tab"
data-index="{{0}}"
style=""
bind:tap="onTap"
>
<wx-view
class="van-ellipsis"
style=""
>
标签 1
</wx-view>
</wx-view>
<wx-view
class="tab-class tab-active-class van-ellipsis van-tab van-tab--active"
data-index="{{1}}"
style=""
bind:tap="onTap"
>
<wx-view
class="van-ellipsis"
style=""
>
标签 2
</wx-view>
</wx-view>
<wx-view
class="tab-class van-ellipsis van-tab"
data-index="{{2}}"
style=""
bind:tap="onTap"
>
<wx-view
class="van-ellipsis"
style=""
>
标签 3
</wx-view>
</wx-view>
<wx-view
class="tab-class van-ellipsis van-tab"
data-index="{{3}}"
style=""
bind:tap="onTap"
>
<wx-view
class="van-ellipsis"
style=""
>
标签 4
</wx-view>
</wx-view>
</wx-view>
</wx-scroll-view>
</wx-view>
</wx-view>
</wx-view>
</van-sticky>
<wx-view
class="van-tabs__content"
bind:touchcancel="onTouchEnd"
bind:touchend="onTouchEnd"
bind:touchmove="onTouchMove"
bind:touchstart="onTouchStart"
>
<wx-view
class="van-tabs__track van-tabs__track"
style=""
>
<van-tab>
<wx-view
class="custom-class van-tab__pane van-tab__pane--inactive"
style="display: none;"
/>
</van-tab>
<van-tab>
<wx-view
class="custom-class van-tab__pane van-tab__pane--active"
style=""
>
<wx-view
class="content"
>
内容2
</wx-view>
</wx-view>
</van-tab>
<van-tab>
<wx-view
class="custom-class van-tab__pane van-tab__pane--inactive"
style="display: none;"
/>
</van-tab>
<van-tab>
<wx-view
class="custom-class van-tab__pane van-tab__pane--inactive"
style="display: none;"
/>
</van-tab>
</wx-view>
</wx-view>
</wx-view>
</van-tabs>
</wx-view>
</demo-block>
</main>
`;

View File

@ -93,6 +93,10 @@ VantComponent({
type: Boolean,
value: true,
},
useBeforeChange: {
type: Boolean,
value: false,
},
},
data: {
@ -134,17 +138,13 @@ VantComponent({
trigger(eventName: string, child?: TrivialInstance) {
const { currentIndex } = this.data;
const currentChild = child || this.children[currentIndex];
const data = this.getChildData(currentIndex, child);
if (!isDef(currentChild)) {
if (!isDef(data)) {
return;
}
this.$emit(eventName, {
index: currentChild.index,
name: currentChild.getComputedName(),
title: currentChild.data.title,
});
this.$emit(eventName, data);
},
onTap(event: WechatMiniprogram.TouchEvent) {
@ -153,12 +153,15 @@ VantComponent({
if (child.data.disabled) {
this.trigger('disabled', child);
} else {
return;
}
this.onBeforeChange(index).then(() => {
this.setCurrentIndex(index);
nextTick(() => {
this.trigger('click');
});
}
});
},
// correct the index of active tab
@ -313,7 +316,7 @@ VantComponent({
if (direction === 'horizontal' && offsetX >= minSwipeDistance) {
const index = this.getAvaiableTab(deltaX);
if (index !== -1) {
this.setCurrentIndex(index);
this.onBeforeChange(index).then(() => this.setCurrentIndex(index));
}
}
@ -343,5 +346,32 @@ VantComponent({
return -1;
},
onBeforeChange(index: number): Promise<void> {
const { useBeforeChange } = this.data;
if (!useBeforeChange) {
return Promise.resolve();
}
return new Promise((resolve, reject) => {
this.$emit('before-change', {
...this.getChildData(index),
callback: (status) => (status ? resolve() : reject()),
});
});
},
getChildData(index: number, child?: TrivialInstance) {
const currentChild = child || this.children[index];
if (!isDef(currentChild)) {
return;
}
return {
index: currentChild.index,
name: currentChild.getComputedName(),
title: currentChild.data.title,
};
},
},
});

View File

@ -186,14 +186,25 @@ VantComponent({
const { index } = event.currentTarget.dataset;
const { lists } = this.data as { lists: File[] };
const sources: WechatMiniprogram.MediaSource[] = [];
const current = lists.reduce((sum, cur, curIndex) => {
if (!isVideoFile(cur)) {
return sum;
}
sources.push({ ...cur, type: 'video' });
if (curIndex < index) {
sum++;
}
return sum;
}, 0);
wx.previewMedia({
sources: lists
.filter((item) => isVideoFile(item))
.map((item) => ({
...item,
type: 'video',
})),
current: index,
sources,
current,
fail() {
wx.showToast({ title: '预览视频失败', icon: 'none' });
},