diff --git a/dist/dialog/index.wxml b/dist/dialog/index.wxml
index 72336428..e1ac81eb 100644
--- a/dist/dialog/index.wxml
+++ b/dist/dialog/index.wxml
@@ -69,7 +69,7 @@
-
diff --git a/dist/search/index.wxss b/dist/search/index.wxss
index 212f7aa4..4f306b04 100644
--- a/dist/search/index.wxss
+++ b/dist/search/index.wxss
@@ -1 +1 @@
-@import '../common/index.wxss';.van-search{align-items:center;box-sizing:border-box;display:flex;padding:var(--search-padding,10px 12px)}.van-search__content{background-color:var(--search-background-color,#f7f8fa);border-radius:2px;display:flex;flex:1;padding-left:var(--padding-sm,12px)}.van-search__content--round{border-radius:999px}.van-search__label{color:var(--search-label-color,#323233);font-size:var(--search-label-font-size,14px);line-height:var(--search-input-height,34px);padding:var(--search-label-padding,0 5px)}.van-search__field{flex:1}.van-search__field__left-icon{color:var(--search-left-icon-color,#969799)}.van-search--withaction{padding-right:0}.van-search__action{color:var(--search-action-text-color,#323233);font-size:var(--search-action-font-size,14px);line-height:var(--search-input-height,34px);padding:var(--search-action-padding,0 8px)}.van-search__action--hover{background-color:#f2f3f5}
\ No newline at end of file
+@import '../common/index.wxss';.van-search{align-items:center;box-sizing:border-box;display:flex;padding:var(--search-padding,10px 12px)}.van-search__content{background-color:var(--search-background-color,#f7f8fa);border-radius:2px;display:flex;flex:1;padding-left:var(--padding-sm,12px)}.van-search__content--round{border-radius:999px}.van-search__label{color:var(--search-label-color,#323233);font-size:var(--search-label-font-size,14px);line-height:var(--search-input-height,34px);padding:var(--search-label-padding,0 5px)}.van-search__field{flex:1}.van-search__field__left-icon{color:var(--search-left-icon-color,#969799)}.van-search--withaction{padding-right:0}.van-search__action{color:var(--search-action-text-color,#323233);font-size:var(--search-action-font-size,14px);line-height:var(--search-input-height,34px)}.van-search__action--hover{background-color:#f2f3f5}.van-search__action-button{padding:var(--search-action-padding,0 8px)}
\ No newline at end of file
diff --git a/dist/tabs/index.js b/dist/tabs/index.js
index 6ee2cb2d..b602278d 100644
--- a/dist/tabs/index.js
+++ b/dist/tabs/index.js
@@ -79,6 +79,10 @@ VantComponent({
type: Boolean,
value: true,
},
+ useBeforeChange: {
+ type: Boolean,
+ value: false,
+ },
},
data: {
tabs: [],
@@ -112,28 +116,25 @@ VantComponent({
},
trigger(eventName, child) {
const { currentIndex } = this.data;
- const currentChild = child || this.children[currentIndex];
- if (!isDef(currentChild)) {
+ const data = this.getChildData(currentIndex, child);
+ if (!isDef(data)) {
return;
}
- this.$emit(eventName, {
- index: currentChild.index,
- name: currentChild.getComputedName(),
- title: currentChild.data.title,
- });
+ this.$emit(eventName, data);
},
onTap(event) {
const { index } = event.currentTarget.dataset;
const child = this.children[index];
if (child.data.disabled) {
this.trigger('disabled', child);
+ return;
}
- else {
+ this.onBeforeChange(index).then(() => {
this.setCurrentIndex(index);
nextTick(() => {
this.trigger('click');
});
- }
+ });
},
// correct the index of active tab
setCurrentIndexByName(name) {
@@ -255,7 +256,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));
}
}
this.swiping = false;
@@ -274,5 +275,25 @@ VantComponent({
}
return -1;
},
+ onBeforeChange(index) {
+ const { useBeforeChange } = this.data;
+ if (!useBeforeChange) {
+ return Promise.resolve();
+ }
+ return new Promise((resolve, reject) => {
+ this.$emit('before-change', Object.assign(Object.assign({}, this.getChildData(index)), { callback: (status) => (status ? resolve() : reject()) }));
+ });
+ },
+ getChildData(index, child) {
+ const currentChild = child || this.children[index];
+ if (!isDef(currentChild)) {
+ return;
+ }
+ return {
+ index: currentChild.index,
+ name: currentChild.getComputedName(),
+ title: currentChild.data.title,
+ };
+ },
},
});
diff --git a/dist/uploader/index.js b/dist/uploader/index.js
index beac3192..75c4c509 100644
--- a/dist/uploader/index.js
+++ b/dist/uploader/index.js
@@ -129,11 +129,20 @@ VantComponent({
return;
const { index } = event.currentTarget.dataset;
const { lists } = this.data;
+ const sources = [];
+ const current = lists.reduce((sum, cur, curIndex) => {
+ if (!isVideoFile(cur)) {
+ return sum;
+ }
+ sources.push(Object.assign(Object.assign({}, cur), { type: 'video' }));
+ if (curIndex < index) {
+ sum++;
+ }
+ return sum;
+ }, 0);
wx.previewMedia({
- sources: lists
- .filter((item) => isVideoFile(item))
- .map((item) => (Object.assign(Object.assign({}, item), { type: 'video' }))),
- current: index,
+ sources,
+ current,
fail() {
wx.showToast({ title: '预览视频失败', icon: 'none' });
},
diff --git a/lib/dialog/index.wxml b/lib/dialog/index.wxml
index 72336428..e1ac81eb 100644
--- a/lib/dialog/index.wxml
+++ b/lib/dialog/index.wxml
@@ -69,7 +69,7 @@
-
diff --git a/lib/search/index.wxss b/lib/search/index.wxss
index 212f7aa4..4f306b04 100644
--- a/lib/search/index.wxss
+++ b/lib/search/index.wxss
@@ -1 +1 @@
-@import '../common/index.wxss';.van-search{align-items:center;box-sizing:border-box;display:flex;padding:var(--search-padding,10px 12px)}.van-search__content{background-color:var(--search-background-color,#f7f8fa);border-radius:2px;display:flex;flex:1;padding-left:var(--padding-sm,12px)}.van-search__content--round{border-radius:999px}.van-search__label{color:var(--search-label-color,#323233);font-size:var(--search-label-font-size,14px);line-height:var(--search-input-height,34px);padding:var(--search-label-padding,0 5px)}.van-search__field{flex:1}.van-search__field__left-icon{color:var(--search-left-icon-color,#969799)}.van-search--withaction{padding-right:0}.van-search__action{color:var(--search-action-text-color,#323233);font-size:var(--search-action-font-size,14px);line-height:var(--search-input-height,34px);padding:var(--search-action-padding,0 8px)}.van-search__action--hover{background-color:#f2f3f5}
\ No newline at end of file
+@import '../common/index.wxss';.van-search{align-items:center;box-sizing:border-box;display:flex;padding:var(--search-padding,10px 12px)}.van-search__content{background-color:var(--search-background-color,#f7f8fa);border-radius:2px;display:flex;flex:1;padding-left:var(--padding-sm,12px)}.van-search__content--round{border-radius:999px}.van-search__label{color:var(--search-label-color,#323233);font-size:var(--search-label-font-size,14px);line-height:var(--search-input-height,34px);padding:var(--search-label-padding,0 5px)}.van-search__field{flex:1}.van-search__field__left-icon{color:var(--search-left-icon-color,#969799)}.van-search--withaction{padding-right:0}.van-search__action{color:var(--search-action-text-color,#323233);font-size:var(--search-action-font-size,14px);line-height:var(--search-input-height,34px)}.van-search__action--hover{background-color:#f2f3f5}.van-search__action-button{padding:var(--search-action-padding,0 8px)}
\ No newline at end of file
diff --git a/lib/tabs/index.js b/lib/tabs/index.js
index b8928edb..e16ace9d 100644
--- a/lib/tabs/index.js
+++ b/lib/tabs/index.js
@@ -1,4 +1,15 @@
"use strict";
+var __assign = (this && this.__assign) || function () {
+ __assign = Object.assign || function(t) {
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
+ s = arguments[i];
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
+ t[p] = s[p];
+ }
+ return t;
+ };
+ return __assign.apply(this, arguments);
+};
Object.defineProperty(exports, "__esModule", { value: true });
var component_1 = require("../common/component");
var touch_1 = require("../mixins/touch");
@@ -84,6 +95,10 @@ var relation_1 = require("../common/relation");
type: Boolean,
value: true,
},
+ useBeforeChange: {
+ type: Boolean,
+ value: false,
+ },
},
data: {
tabs: [],
@@ -118,15 +133,11 @@ var relation_1 = require("../common/relation");
},
trigger: function (eventName, child) {
var currentIndex = this.data.currentIndex;
- var currentChild = child || this.children[currentIndex];
- if (!(0, validator_1.isDef)(currentChild)) {
+ var data = this.getChildData(currentIndex, child);
+ if (!(0, validator_1.isDef)(data)) {
return;
}
- this.$emit(eventName, {
- index: currentChild.index,
- name: currentChild.getComputedName(),
- title: currentChild.data.title,
- });
+ this.$emit(eventName, data);
},
onTap: function (event) {
var _this = this;
@@ -134,13 +145,14 @@ var relation_1 = require("../common/relation");
var child = this.children[index];
if (child.data.disabled) {
this.trigger('disabled', child);
+ return;
}
- else {
- this.setCurrentIndex(index);
+ this.onBeforeChange(index).then(function () {
+ _this.setCurrentIndex(index);
(0, utils_1.nextTick)(function () {
_this.trigger('click');
});
- }
+ });
},
// correct the index of active tab
setCurrentIndexByName: function (name) {
@@ -260,14 +272,15 @@ var relation_1 = require("../common/relation");
},
// watch swipe touch end
onTouchEnd: function () {
+ var _this = this;
if (!this.data.swipeable || !this.swiping)
return;
var _a = this, direction = _a.direction, deltaX = _a.deltaX, offsetX = _a.offsetX;
var minSwipeDistance = 50;
if (direction === 'horizontal' && offsetX >= minSwipeDistance) {
- var index = this.getAvaiableTab(deltaX);
- if (index !== -1) {
- this.setCurrentIndex(index);
+ var index_1 = this.getAvaiableTab(deltaX);
+ if (index_1 !== -1) {
+ this.onBeforeChange(index_1).then(function () { return _this.setCurrentIndex(index_1); });
}
}
this.swiping = false;
@@ -286,5 +299,26 @@ var relation_1 = require("../common/relation");
}
return -1;
},
+ onBeforeChange: function (index) {
+ var _this = this;
+ var useBeforeChange = this.data.useBeforeChange;
+ if (!useBeforeChange) {
+ return Promise.resolve();
+ }
+ return new Promise(function (resolve, reject) {
+ _this.$emit('before-change', __assign(__assign({}, _this.getChildData(index)), { callback: function (status) { return (status ? resolve() : reject()); } }));
+ });
+ },
+ getChildData: function (index, child) {
+ var currentChild = child || this.children[index];
+ if (!(0, validator_1.isDef)(currentChild)) {
+ return;
+ }
+ return {
+ index: currentChild.index,
+ name: currentChild.getComputedName(),
+ title: currentChild.data.title,
+ };
+ },
},
});
diff --git a/lib/uploader/index.js b/lib/uploader/index.js
index 6aefba12..0420bddb 100644
--- a/lib/uploader/index.js
+++ b/lib/uploader/index.js
@@ -144,11 +144,20 @@ var validator_1 = require("../common/validator");
return;
var index = event.currentTarget.dataset.index;
var lists = this.data.lists;
+ var sources = [];
+ var current = lists.reduce(function (sum, cur, curIndex) {
+ if (!(0, utils_1.isVideoFile)(cur)) {
+ return sum;
+ }
+ sources.push(__assign(__assign({}, cur), { type: 'video' }));
+ if (curIndex < index) {
+ sum++;
+ }
+ return sum;
+ }, 0);
wx.previewMedia({
- sources: lists
- .filter(function (item) { return (0, utils_1.isVideoFile)(item); })
- .map(function (item) { return (__assign(__assign({}, item), { type: 'video' })); }),
- current: index,
+ sources: sources,
+ current: current,
fail: function () {
wx.showToast({ title: '预览视频失败', icon: 'none' });
},