...
 
Commits (7)
    https://gitcode.net/xuxiaowei-cloud/vant-weapp/-/commit/1fcd0caabde3a5a8d6b04f3f386fab3072196e76 :memo: 修正 vant weapp 版本号 2022-09-07T23:26:50+08:00 徐晓伟 xuxiaowei@xuxiaowei.com.cn https://gitcode.net/xuxiaowei-cloud/vant-weapp/-/commit/bd46bae55498ff7f4e5c17236962cea569944b9c :arrow_up: upgrade vant-weapp v1.10.6 2022-11-07T08:09:44+08:00 徐晓伟 xuxiaowei@xuxiaowei.com.cn <a href="https://github.com/vant-ui/vant-weapp/releases/tag/v1.10.6" rel="nofollow noreferrer noopener" target="_blank">https://github.com/vant-ui/vant-weapp/releases/tag/v1.10.6</a> https://gitcode.net/xuxiaowei-cloud/vant-weapp/-/commit/e7659da2f0f5d392fb701c4996f9bf51d730615f !6 :arrow_up: upgrade vant-weapp v1.10.6 2022-11-07T00:10:59+00:00 徐晓伟 xuxiaowei@xuxiaowei.com.cn Merge pull request !6 from 徐晓伟/xuxiaowei <a href="https://github.com/vant-ui/vant-weapp/releases/tag/v1.10.6" rel="nofollow noreferrer noopener" target="_blank">https://github.com/vant-ui/vant-weapp/releases/tag/v1.10.6</a> https://gitcode.net/xuxiaowei-cloud/vant-weapp/-/commit/78630fd8d5b37209300293419973909efcb08fad :arrow_up: upgrade vant-weapp v1.10.11 2023-01-03T10:41:16+08:00 徐晓伟 xuxiaowei@xuxiaowei.com.cn <a href="https://github.com/vant-ui/vant-weapp/releases/tag/v1.10.11" rel="nofollow noreferrer noopener" target="_blank">https://github.com/vant-ui/vant-weapp/releases/tag/v1.10.11</a> https://gitcode.net/xuxiaowei-cloud/vant-weapp/-/commit/592b7b1a99ffc1e15b67e7b67e2ec92ffae34255 !7 :arrow_up: upgrade vant-weapp v1.10.11 2023-01-03T02:42:39+00:00 徐晓伟 xuxiaowei@xuxiaowei.com.cn Merge pull request !7 from 徐晓伟/xuxiaowei https://gitcode.net/xuxiaowei-cloud/vant-weapp/-/commit/a484234026ffa6a73935cc700f600a0e8abe93d3 :sparkles: 授权成功后输出 globalData 2023-01-31T17:05:19+08:00 徐晓伟 xuxiaowei@xuxiaowei.com.cn https://gitcode.net/xuxiaowei-cloud/vant-weapp/-/commit/c8d5563f0a690f6b0091410b25b47a272f5b0ccb :arrow_up: upgrade vant-weapp v1.10.13 2023-02-13T10:09:46+08:00 徐晓伟 xuxiaowei@xuxiaowei.com.cn <a href="https://github.com/vant-ui/vant-weapp/releases/tag/v1.10.13" rel="nofollow noreferrer noopener" target="_blank">https://github.com/vant-ui/vant-weapp/releases/tag/v1.10.13</a>
......@@ -75,7 +75,7 @@
</a>
<a href="https://github.com/youzan/vant-weapp">
<img alt="vant-weapp" src="https://img.shields.io/badge/vant weapp-v1.10.3-blue">
<img alt="vant-weapp" src="https://img.shields.io/badge/vant weapp-v1.10.5-blue">
</a>
<a href="https://github.com/dankogai/js-base64">
......
......@@ -56,6 +56,8 @@ App({
}
}
console.log(this.globalData)
} else {
Dialog.alert({
title: '授权异常',
......
import { VantComponent } from '../common/component';
import { button } from '../mixins/button';
VantComponent({
classes: ['list-class'],
mixins: [button],
props: {
show: Boolean,
......
......@@ -6,7 +6,7 @@
round="{{ round }}"
z-index="{{ zIndex }}"
overlay="{{ overlay }}"
custom-class="van-action-sheet"
custom-class="van-action-sheet custom-class"
safe-area-inset-bottom="{{ safeAreaInsetBottom }}"
close-on-click-overlay="{{ closeOnClickOverlay }}"
bind:close="onClickOverlay"
......@@ -22,7 +22,7 @@
<view wx:if="{{ description }}" class="van-action-sheet__description van-hairline--bottom">
{{ description }}
</view>
<view wx:if="{{ actions && actions.length }}">
<view wx:if="{{ actions && actions.length }}" class="list-class">
<!-- button外包一层view,防止actions动态变化,导致渲染时button被打散 -->
<button
wx:for="{{ actions }}"
......
......@@ -5,7 +5,7 @@
id="{{ id }}"
data-detail="{{ dataset }}"
class="custom-class {{ utils.bem('button', [type, size, { block, round, plain, square, loading, disabled, hairline, unclickable: disabled || loading }]) }} {{ hairline ? 'van-hairline--surround' : '' }}"
hover-class="van-button--active hover-class"
hover-class="{{ disabled || loading ? '' : 'van-button--active hover-class'}}"
lang="{{ lang }}"
form-type="{{ formType }}"
style="{{ computed.rootStyle({ plain, color, customStyle }) }}"
......
......@@ -54,12 +54,12 @@
type="danger"
color="{{ color }}"
custom-class="van-calendar__confirm"
disabled="{{ computed.getButtonDisabled(type, currentDate) }}"
disabled="{{ computed.getButtonDisabled(type, currentDate, minRange) }}"
nativeType="text"
bind:click="onConfirm"
>
{{
computed.getButtonDisabled(type, currentDate)
computed.getButtonDisabled(type, currentDate, minRange)
? confirmDisabledText
: confirmText
}}
......
......@@ -103,6 +103,10 @@ VantComponent({
type: null,
value: null,
},
minRange: {
type: Number,
value: 1,
},
firstDayOfWeek: {
type: Number,
value: 0,
......@@ -159,7 +163,7 @@ VantComponent({
return date;
},
getInitialDate(defaultDate = null) {
const { type, minDate, maxDate } = this.data;
const { type, minDate, maxDate, allowSameDay } = this.data;
const now = getToday().getTime();
if (type === 'range') {
if (!Array.isArray(defaultDate)) {
......@@ -167,7 +171,8 @@ VantComponent({
}
const [startDay, endDay] = defaultDate || [];
const start = this.limitDateRange(startDay || now, minDate, getPrevDay(new Date(maxDate)).getTime());
const end = this.limitDateRange(endDay || now, getNextDay(new Date(minDate)).getTime());
const date = getTime(endDay || now);
const end = this.limitDateRange(date, allowSameDay ? date : getNextDay(new Date(minDate)).getTime());
return [start, end];
}
if (type === 'multiple') {
......
......@@ -12,6 +12,7 @@
position="{{ position }}"
closeable="{{ showTitle || showSubtitle }}"
close-on-click-overlay="{{ closeOnClickOverlay }}"
safe-area-inset-bottom="{{ safeAreaInsetBottom }}"
bind:enter="onOpen"
bind:close="onClose"
bind:after-enter="onOpened"
......
......@@ -15,7 +15,7 @@ function getMonths(minDate, maxDate) {
return months;
}
function getButtonDisabled(type, currentDate) {
function getButtonDisabled(type, currentDate, minRange) {
if (currentDate == null) {
return true;
}
......@@ -25,7 +25,7 @@ function getButtonDisabled(type, currentDate) {
}
if (type === 'multiple') {
return !currentDate.length;
return currentDate.length < minRange;
}
return !currentDate;
......
import { VantComponent } from '../common/component';
var FieldName;
(function (FieldName) {
FieldName["TEXT"] = "text";
FieldName["VALUE"] = "value";
FieldName["CHILDREN"] = "children";
})(FieldName || (FieldName = {}));
const defaultFieldNames = {
text: FieldName.TEXT,
value: FieldName.VALUE,
children: FieldName.CHILDREN,
};
VantComponent({
props: {
title: String,
value: {
type: String,
observer: 'updateValue',
},
placeholder: {
type: String,
value: '请选择',
},
activeColor: {
type: String,
value: '#1989fa',
},
options: {
type: Array,
value: [],
observer: 'updateOptions',
},
swipeable: {
type: Boolean,
value: false,
},
closeable: {
type: Boolean,
value: true,
},
showHeader: {
type: Boolean,
value: true,
},
closeIcon: {
type: String,
value: 'cross',
},
fieldNames: {
type: Object,
value: defaultFieldNames,
observer: 'updateFieldNames',
},
},
data: {
tabs: [],
activeTab: 0,
textKey: FieldName.TEXT,
valueKey: FieldName.VALUE,
childrenKey: FieldName.CHILDREN,
},
created() {
this.updateTabs();
},
methods: {
updateOptions(val, oldVal) {
const isAsync = !!(val.length && oldVal.length);
this.updateTabs(isAsync);
},
updateValue(val) {
if (val !== undefined) {
const values = this.data.tabs.map((tab) => tab.selected && tab.selected[this.data.valueKey]);
if (values.indexOf(val) > -1) {
return;
}
}
this.updateTabs();
},
updateFieldNames() {
const { text = 'text', value = 'value', children = 'children', } = this.data.fieldNames || defaultFieldNames;
this.setData({
textKey: text,
valueKey: value,
childrenKey: children,
});
},
getSelectedOptionsByValue(options, value) {
for (let i = 0; i < options.length; i++) {
const option = options[i];
if (option[this.data.valueKey] === value) {
return [option];
}
if (option[this.data.childrenKey]) {
const selectedOptions = this.getSelectedOptionsByValue(option[this.data.childrenKey], value);
if (selectedOptions) {
return [option, ...selectedOptions];
}
}
}
},
updateTabs(isAsync = false) {
const { options, value } = this.data;
if (value !== undefined) {
const selectedOptions = this.getSelectedOptionsByValue(options, value);
if (selectedOptions) {
let optionsCursor = options;
const tabs = selectedOptions.map((option) => {
const tab = {
options: optionsCursor,
selected: option,
};
const next = optionsCursor.find((item) => item[this.data.valueKey] === option[this.data.valueKey]);
if (next) {
optionsCursor = next[this.data.childrenKey];
}
return tab;
});
if (optionsCursor) {
tabs.push({
options: optionsCursor,
selected: null,
});
}
this.setData({
tabs,
});
wx.nextTick(() => {
this.setData({
activeTab: tabs.length - 1,
});
});
return;
}
}
// 异步更新
if (isAsync) {
const { tabs } = this.data;
tabs[tabs.length - 1].options =
options[options.length - 1][this.data.childrenKey];
this.setData({
tabs,
});
return;
}
this.setData({
tabs: [
{
options,
selected: null,
},
],
});
},
onClose() {
this.$emit('close');
},
onClickTab(e) {
const { index: tabIndex, title } = e.detail;
this.$emit('click-tab', { title, tabIndex });
this.setData({
activeTab: tabIndex,
});
},
// 选中
onSelect(e) {
const { option, tabIndex } = e.currentTarget.dataset;
if (option && option.disabled) {
return;
}
const { valueKey, childrenKey } = this.data;
let { tabs } = this.data;
tabs[tabIndex].selected = option;
if (tabs.length > tabIndex + 1) {
tabs = tabs.slice(0, tabIndex + 1);
}
if (option[childrenKey]) {
const nextTab = {
options: option[childrenKey],
selected: null,
};
if (tabs[tabIndex + 1]) {
tabs[tabIndex + 1] = nextTab;
}
else {
tabs.push(nextTab);
}
wx.nextTick(() => {
this.setData({
activeTab: tabIndex + 1,
});
});
}
this.setData({
tabs,
});
const selectedOptions = tabs.map((tab) => tab.selected).filter(Boolean);
const params = {
value: option[valueKey],
tabIndex,
selectedOptions,
};
this.$emit('change', params);
if (!option[childrenKey]) {
this.$emit('finish', params);
}
},
},
});
{
"component": true,
"usingComponents": {
"van-icon": "../icon/index",
"van-tab": "../tab/index",
"van-tabs": "../tabs/index"
}
}
\ No newline at end of file
<wxs src="./index.wxs" module="utils" />
<view wx:if="{{ showHeader }}" class="van-cascader__header">
<text class="van-cascader__title"><slot name="title"></slot>{{ title }}</text>
<van-icon
wx:if="{{ closeable }}"
name="{{ closeIcon }}"
class="van-cascader__close-icon"
bind:tap="onClose"
/>
</view>
<van-tabs
active="{{ activeTab }}"
custom-class="van-cascader__tabs"
wrap-class="van-cascader__tabs-wrap"
tab-class="van-cascader__tab"
color="{{ activeColor }}"
border="{{ false }}"
swipeable="{{ swipeable }}"
bind:click="onClickTab"
>
<van-tab
wx:for="{{ tabs }}"
wx:for-item="tab"
wx:for-index="tabIndex"
wx:key="tabIndex"
title="{{ tab.selected ? tab.selected[textKey] : placeholder }}"
style="width: 100%;"
title-style="{{ !tab.selected ? 'color: #969799;font-weight:normal;' : '' }}"
>
<!-- 暂不支持 -->
<!-- <slot name="options-top"></slot> -->
<view class="van-cascader__options">
<view
wx:for="{{ tab.options }}"
wx:for-item="option"
wx:key="index"
class="{{ option.className }} {{ utils.optionClass(tab, textKey, option) }}"
style="{{ utils.optionStyle({ tab, textKey, option, activeColor }) }}"
data-option="{{ option }}"
data-tab-index="{{ tabIndex }}"
bind:tap="onSelect"
>
<text>{{ option[textKey] }}</text>
<van-icon wx:if="{{ utils.isSelected(tab, textKey, option) }}" name="success" size="18" />
</view>
</view>
<!-- 暂不支持 -->
<!-- <slot name="options-bottom"></slot> -->
</van-tab>
</van-tabs>
var utils = require('../wxs/utils.wxs');
var style = require('../wxs/style.wxs');
function isSelected(tab, textKey, option) {
return tab.selected && tab.selected[textKey] === option[textKey]
}
function optionClass(tab, textKey, option) {
return utils.bem('cascader__option', { selected: isSelected({ tab, textKey, option }), disabled: option.disabled })
}
function optionStyle(data) {
var color = data.option.color || (isSelected(data.tab, data.textKey, data.option) ? data.activeColor : undefined);
return style({
color
});
}
module.exports = {
isSelected: isSelected,
optionClass: optionClass,
optionStyle: optionStyle,
};
\ No newline at end of file
@import '../common/index.wxss';.van-cascader__header{align-items:center;display:flex;height:48px;justify-content:space-between;padding:0 16px}.van-cascader__title{font-size:16px;font-weight:600;line-height:20px}.van-cascader__close-icon{color:#c8c9cc;font-size:22px;height:22px}.van-cascader__tabs-wrap{height:48px!important;padding:0 8px}.van-cascader__tab{color:#323233!important;flex:none!important;font-weight:600!important;padding:0 8px!important}.van-cascader__tab--unselected{color:#969799!important;font-weight:400!important}.van-cascader__option{align-items:center;cursor:pointer;display:flex;font-size:14px;justify-content:space-between;line-height:20px;padding:10px 16px}.van-cascader__option:active{background-color:#f2f3f5}.van-cascader__option--selected{color:#1989fa;font-weight:600}.van-cascader__option--disabled{color:#c8c9cc;cursor:not-allowed}.van-cascader__option--disabled:active{background-color:initial}.van-cascader__options{-webkit-overflow-scrolling:touch;box-sizing:border-box;height:384px;overflow-y:auto;padding-top:6px}
\ No newline at end of file
......@@ -11,6 +11,7 @@ function VantComponent(vantOptions) {
mapKeys(vantOptions, options, {
data: 'data',
props: 'properties',
watch: 'observers',
mixins: 'behaviors',
methods: 'methods',
beforeCreate: 'created',
......
import { isDef, isNumber, isPlainObject, isPromise } from './validator';
import { canIUseGroupSetData, canIUseNextTick } from './version';
export { isDef } from './validator';
export { getSystemInfoSync } from './version';
export function range(num, min, max) {
return Math.min(Math.max(num, min), max);
}
......@@ -14,13 +15,6 @@ export function nextTick(cb) {
}, 1000 / 30);
}
}
let systemInfo;
export function getSystemInfoSync() {
if (systemInfo == null) {
systemInfo = wx.getSystemInfoSync();
}
return systemInfo;
}
export function addUnit(value) {
if (!isDef(value)) {
return undefined;
......@@ -29,19 +23,9 @@ export function addUnit(value) {
return isNumber(value) ? `${value}px` : value;
}
export function requestAnimationFrame(cb) {
const systemInfo = getSystemInfoSync();
if (systemInfo.platform === 'devtools') {
return setTimeout(() => {
cb();
}, 1000 / 30);
}
return wx
.createSelectorQuery()
.selectViewport()
.boundingClientRect()
.exec(() => {
return setTimeout(() => {
cb();
});
}, 1000 / 30);
}
export function pickExclude(obj, keys) {
if (!isPlainObject(obj)) {
......
import { getSystemInfoSync } from './utils';
let systemInfo;
export function getSystemInfoSync() {
if (systemInfo == null) {
systemInfo = wx.getSystemInfoSync();
}
return systemInfo;
}
function compareVersion(v1, v2) {
v1 = v1.split('.');
v2 = v2.split('.');
......@@ -38,7 +44,12 @@ export function canIUseGroupSetData() {
return gte('2.4.0');
}
export function canIUseNextTick() {
return wx.canIUse('nextTick');
try {
return wx.canIUse('nextTick');
}
catch (e) {
return gte('2.7.1');
}
}
export function canIUseCanvas2d() {
return gte('2.9.0');
......
......@@ -30,7 +30,9 @@ function getContext() {
const Dialog = (options) => {
options = Object.assign(Object.assign({}, currentOptions), options);
return new Promise((resolve, reject) => {
const context = options.context || getContext();
const context = (typeof options.context === 'function'
? options.context()
: options.context) || getContext();
const dialog = context.selectComponent(options.selector);
delete options.context;
delete options.selector;
......
......@@ -5,7 +5,7 @@
z-index="{{ zIndex }}"
overlay="{{ overlay }}"
transition="{{ transition }}"
custom-class="van-dialog van-dialog--{{ theme }} {{ className }}"
custom-class="van-dialog van-dialog--{{ theme }}{{ className }} custom-class"
custom-style="width: {{ utils.addUnit(width) }};{{ customStyle }}"
overlay-style="{{ overlayStyle }}"
close-on-click-overlay="{{ closeOnClickOverlay }}"
......@@ -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"
......
import { useParent } from '../common/relation';
import { VantComponent } from '../common/component';
VantComponent({
classes: ['item-title-class'],
field: true,
relation: useParent('dropdown-menu', function () {
this.updateDataFromParent();
......@@ -25,6 +26,10 @@ VantComponent({
observer: 'rerender',
},
popupStyle: String,
useBeforeToggle: {
type: Boolean,
value: false,
},
},
data: {
transition: true,
......@@ -76,7 +81,6 @@ VantComponent({
}
},
toggle(show, options = {}) {
var _a;
const { showPopup } = this.data;
if (typeof show !== 'boolean') {
show = !showPopup;
......@@ -84,19 +88,37 @@ VantComponent({
if (show === showPopup) {
return;
}
this.setData({
transition: !options.immediate,
showPopup: show,
});
if (show) {
(_a = this.parent) === null || _a === void 0 ? void 0 : _a.getChildWrapperStyle().then((wrapperStyle) => {
this.setData({ wrapperStyle, showWrapper: true });
this.rerender();
this.onBeforeToggle(show).then((status) => {
var _a;
if (!status) {
return;
}
this.setData({
transition: !options.immediate,
showPopup: show,
});
if (show) {
(_a = this.parent) === null || _a === void 0 ? void 0 : _a.getChildWrapperStyle().then((wrapperStyle) => {
this.setData({ wrapperStyle, showWrapper: true });
this.rerender();
});
}
else {
this.rerender();
}
});
},
onBeforeToggle(status) {
const { useBeforeToggle } = this.data;
if (!useBeforeToggle) {
return Promise.resolve(true);
}
else {
this.rerender();
}
return new Promise((resolve) => {
this.$emit('before-toggle', {
status,
callback: (value) => resolve(value),
});
});
},
},
});
......@@ -2,7 +2,7 @@
<view
wx:if="{{ showWrapper }}"
class="{{ utils.bem('dropdown-item', direction) }}"
class="{{ utils.bem('dropdown-item', direction) }} custom-class"
style="{{ wrapperStyle }}"
>
<van-popup
......@@ -30,7 +30,7 @@
>
<view
slot="title"
class="van-dropdown-item__title"
class="van-dropdown-item__title item-title-class"
style="{{ item.value === value ? 'color:' + activeColor : '' }}"
>
{{ item.text }}
......
......@@ -4,6 +4,7 @@ import { addUnit, getRect, getSystemInfoSync } from '../common/utils';
let ARRAY = [];
VantComponent({
field: true,
classes: ['title-class'],
relation: useChildren('dropdown-item', function () {
this.updateItemListData();
}),
......
......@@ -10,7 +10,7 @@
bind:tap="onTitleTap"
>
<view
class="{{ item.titleClass }} {{ utils.bem('dropdown-menu__title', { active: item.showPopup, down: item.showPopup === (direction === 'down') }) }}"
class="{{ item.titleClass }} {{ utils.bem('dropdown-menu__title', { active: item.showPopup, down: item.showPopup === (direction === 'down') }) }} title-class"
style="{{ item.showPopup ? 'color:' + activeColor : '' }}"
>
<view class="van-ellipsis">
......
@import '../common/index.wxss';.van-dropdown-menu{background-color:var(--dropdown-menu-background-color,#fff);box-shadow:var(--dropdown-menu-box-shadow,0 2px 12px hsla(210,1%,40%,.12));display:flex;height:var(--dropdown-menu-height,50px);-webkit-user-select:none;user-select:none}.van-dropdown-menu__item{align-items:center;display:flex;flex:1;justify-content:center;min-width:0}.van-dropdown-menu__item:active{opacity:.7}.van-dropdown-menu__item--disabled:active{opacity:1}.van-dropdown-menu__item--disabled .van-dropdown-menu__title{color:var(--dropdown-menu-title-disabled-text-color,#969799)}.van-dropdown-menu__title{box-sizing:border-box;color:var(--dropdown-menu-title-text-color,#323233);font-size:var(--dropdown-menu-title-font-size,15px);line-height:var(--dropdown-menu-title-line-height,18px);max-width:100%;padding:var(--dropdown-menu-title-padding,0 8px);position:relative}.van-dropdown-menu__title:after{border-color:transparent transparent currentcolor currentcolor;border-style:solid;border-width:3px;content:"";margin-top:-5px;opacity:.8;position:absolute;right:-4px;top:50%;transform:rotate(-45deg)}.van-dropdown-menu__title--active{color:var(--dropdown-menu-title-active-text-color,#ee0a24)}.van-dropdown-menu__title--down:after{margin-top:-1px;transform:rotate(135deg)}
\ No newline at end of file
@import '../common/index.wxss';.van-dropdown-menu{background-color:var(--dropdown-menu-background-color,#fff);box-shadow:var(--dropdown-menu-box-shadow,0 2px 12px hsla(210,1%,40%,.12));display:flex;height:var(--dropdown-menu-height,50px);-webkit-user-select:none;user-select:none}.van-dropdown-menu__item{align-items:center;display:flex;flex:1;justify-content:center;min-width:0}.van-dropdown-menu__item:active{opacity:.7}.van-dropdown-menu__item--disabled:active{opacity:1}.van-dropdown-menu__item--disabled .van-dropdown-menu__title{color:var(--dropdown-menu-title-disabled-text-color,#969799)}.van-dropdown-menu__title{box-sizing:border-box;color:var(--dropdown-menu-title-text-color,#323233);font-size:var(--dropdown-menu-title-font-size,15px);line-height:var(--dropdown-menu-title-line-height,18px);max-width:100%;padding:var(--dropdown-menu-title-padding,0 24px 0 8px);position:relative}.van-dropdown-menu__title:after{border-color:transparent transparent currentcolor currentcolor;border-style:solid;border-width:3px;content:"";margin-top:-5px;opacity:.8;position:absolute;right:11px;top:50%;transform:rotate(-45deg)}.van-dropdown-menu__title--active{color:var(--dropdown-menu-title-active-text-color,#ee0a24)}.van-dropdown-menu__title--down:after{margin-top:-1px;transform:rotate(135deg)}
\ No newline at end of file
......@@ -22,6 +22,9 @@ VantComponent({
}, clearIcon: {
type: String,
value: 'clear',
}, extraEventParams: {
type: Boolean,
value: false,
} }),
data: {
focused: false,
......@@ -37,7 +40,7 @@ VantComponent({
const { value = '' } = event.detail || {};
this.value = value;
this.setShowClear();
this.emitChange();
this.emitChange(event.detail);
},
onFocus(event) {
this.focused = true;
......@@ -60,7 +63,7 @@ VantComponent({
this.value = '';
this.setShowClear();
nextTick(() => {
this.emitChange();
this.emitChange({ value: '' });
this.$emit('clear', '');
});
},
......@@ -76,7 +79,7 @@ VantComponent({
if (value === '') {
this.setData({ innerValue: '' });
}
this.emitChange();
this.emitChange({ value });
},
onLineChange(event) {
this.$emit('linechange', event.detail);
......@@ -84,11 +87,13 @@ VantComponent({
onKeyboardHeightChange(event) {
this.$emit('keyboardheightchange', event.detail);
},
emitChange() {
this.setData({ value: this.value });
emitChange(detail) {
const { extraEventParams } = this.data;
this.setData({ value: detail.value });
nextTick(() => {
this.$emit('input', this.value);
this.$emit('change', this.value);
const data = extraEventParams ? detail : detail.value;
this.$emit('input', data);
this.$emit('change', data);
});
},
setShowClear() {
......
......@@ -25,6 +25,10 @@ VantComponent({
type: String,
value: 'fill',
},
webp: {
type: Boolean,
value: false,
},
showError: {
type: Boolean,
value: true,
......
......@@ -11,6 +11,7 @@
src="{{ src }}"
mode="{{ computed.mode(fit) }}"
lazy-load="{{ lazyLoad }}"
webp="{{ webp }}"
class="image-class van-image__img"
show-menu-by-longpress="{{ showMenuByLongpress }}"
bind:load="onLoad"
......
import { isFunction } from '../common/validator';
import { getCurrentPage, isDef } from '../common/utils';
function onPageScroll(event) {
const { vanPageScroller = [] } = getCurrentPage();
......@@ -8,29 +9,34 @@ function onPageScroll(event) {
}
});
}
export const pageScrollMixin = (scroller) => Behavior({
attached() {
const page = getCurrentPage();
if (!isDef(page)) {
return;
}
if (Array.isArray(page.vanPageScroller)) {
page.vanPageScroller.push(scroller.bind(this));
}
else {
page.vanPageScroller =
typeof page.onPageScroll === 'function'
? [page.onPageScroll.bind(page), scroller.bind(this)]
: [scroller.bind(this)];
}
page.onPageScroll = onPageScroll;
},
detached() {
var _a;
const page = getCurrentPage();
if (isDef(page)) {
page.vanPageScroller =
((_a = page.vanPageScroller) === null || _a === void 0 ? void 0 : _a.filter((item) => item !== scroller)) || [];
}
},
});
export function pageScrollMixin(scroller) {
return Behavior({
attached() {
const page = getCurrentPage();
if (!isDef(page)) {
return;
}
const _scroller = scroller.bind(this);
const { vanPageScroller = [] } = page;
if (isFunction(page.onPageScroll) && page.onPageScroll !== onPageScroll) {
vanPageScroller.push(page.onPageScroll.bind(page));
}
vanPageScroller.push(_scroller);
page.vanPageScroller = vanPageScroller;
page.onPageScroll = onPageScroll;
this._scroller = _scroller;
},
detached() {
const page = getCurrentPage();
if (!isDef(page) || !isDef(page.vanPageScroller)) {
return;
}
const { vanPageScroller } = page;
const index = vanPageScroller.findIndex((v) => v === this._scroller);
if (index > -1) {
page.vanPageScroller.splice(index, 1);
}
this._scroller = undefined;
},
});
}
......@@ -49,6 +49,9 @@ export function transition(showDefaultValue) {
const { duration, name } = this.data;
const classNames = getClassNames(name);
const currentDuration = isObj(duration) ? duration.enter : duration;
if (this.status === 'enter') {
return;
}
this.status = 'enter';
this.$emit('before-enter');
requestAnimationFrame(() => {
......
<van-transition
wx:if="{{ lockScroll }}"
show="{{ show }}"
custom-class="van-overlay"
custom-class="van-overlay custom-class"
custom-style="z-index: {{ zIndex }}; {{ customStyle }}"
duration="{{ duration }}"
bind:tap="onClick"
......@@ -12,7 +12,7 @@
<van-transition
wx:else
show="{{ show }}"
custom-class="van-overlay"
custom-class="van-overlay custom-class"
custom-style="z-index: {{ zIndex }}; {{ customStyle }}"
duration="{{ duration }}"
bind:tap="onClick"
......
......@@ -53,6 +53,10 @@ VantComponent({
type: Boolean,
value: false,
},
safeAreaTabBar: {
type: Boolean,
value: false,
},
lockScroll: {
type: Boolean,
value: true,
......
......@@ -12,7 +12,7 @@
/>
<view
wx:if="{{ inited }}"
class="custom-class {{ classes }} {{ utils.bem('popup', [position, { round, safe: safeAreaInsetBottom, safeTop: safeAreaInsetTop }]) }}"
class="custom-class {{ classes }} {{ utils.bem('popup', [position, { round, safe: safeAreaInsetBottom, safeTop: safeAreaInsetTop, safeTabBar: safeAreaTabBar }]) }}"
style="{{ computed.popupStyle({ zIndex, currentDuration, display, customStyle }) }}"
bind:transitionend="onTransitionEnd"
>
......
@import '../common/index.wxss';.van-popup{-webkit-overflow-scrolling:touch;animation:ease both;background-color:var(--popup-background-color,#fff);box-sizing:border-box;max-height:100%;overflow-y:auto;position:fixed;transition-timing-function:ease}.van-popup--center{left:50%;top:50%;transform:translate3d(-50%,-50%,0)}.van-popup--center.van-popup--round{border-radius:var(--popup-round-border-radius,16px)}.van-popup--top{left:0;top:0;width:100%}.van-popup--top.van-popup--round{border-radius:0 0 var(--popup-round-border-radius,var(--popup-round-border-radius,16px)) var(--popup-round-border-radius,var(--popup-round-border-radius,16px))}.van-popup--right{right:0;top:50%;transform:translate3d(0,-50%,0)}.van-popup--right.van-popup--round{border-radius:var(--popup-round-border-radius,var(--popup-round-border-radius,16px)) 0 0 var(--popup-round-border-radius,var(--popup-round-border-radius,16px))}.van-popup--bottom{bottom:0;left:0;width:100%}.van-popup--bottom.van-popup--round{border-radius:var(--popup-round-border-radius,var(--popup-round-border-radius,16px)) var(--popup-round-border-radius,var(--popup-round-border-radius,16px)) 0 0}.van-popup--left{left:0;top:50%;transform:translate3d(0,-50%,0)}.van-popup--left.van-popup--round{border-radius:0 var(--popup-round-border-radius,var(--popup-round-border-radius,16px)) var(--popup-round-border-radius,var(--popup-round-border-radius,16px)) 0}.van-popup--bottom.van-popup--safe{padding-bottom:env(safe-area-inset-bottom)}.van-popup--safeTop{padding-top:env(safe-area-inset-top)}.van-popup__close-icon{color:var(--popup-close-icon-color,#969799);font-size:var(--popup-close-icon-size,18px);position:absolute;z-index:var(--popup-close-icon-z-index,1)}.van-popup__close-icon--top-left{left:var(--popup-close-icon-margin,16px);top:var(--popup-close-icon-margin,16px)}.van-popup__close-icon--top-right{right:var(--popup-close-icon-margin,16px);top:var(--popup-close-icon-margin,16px)}.van-popup__close-icon--bottom-left{bottom:var(--popup-close-icon-margin,16px);left:var(--popup-close-icon-margin,16px)}.van-popup__close-icon--bottom-right{bottom:var(--popup-close-icon-margin,16px);right:var(--popup-close-icon-margin,16px)}.van-popup__close-icon:active{opacity:.6}.van-scale-enter-active,.van-scale-leave-active{transition-property:opacity,transform}.van-scale-enter,.van-scale-leave-to{opacity:0;transform:translate3d(-50%,-50%,0) scale(.7)}.van-fade-enter-active,.van-fade-leave-active{transition-property:opacity}.van-fade-enter,.van-fade-leave-to{opacity:0}.van-center-enter-active,.van-center-leave-active{transition-property:opacity}.van-center-enter,.van-center-leave-to{opacity:0}.van-bottom-enter-active,.van-bottom-leave-active,.van-left-enter-active,.van-left-leave-active,.van-right-enter-active,.van-right-leave-active,.van-top-enter-active,.van-top-leave-active{transition-property:transform}.van-bottom-enter,.van-bottom-leave-to{transform:translate3d(0,100%,0)}.van-top-enter,.van-top-leave-to{transform:translate3d(0,-100%,0)}.van-left-enter,.van-left-leave-to{transform:translate3d(-100%,-50%,0)}.van-right-enter,.van-right-leave-to{transform:translate3d(100%,-50%,0)}
\ No newline at end of file
@import '../common/index.wxss';.van-popup{-webkit-overflow-scrolling:touch;animation:ease both;background-color:var(--popup-background-color,#fff);box-sizing:border-box;max-height:100%;overflow-y:auto;position:fixed;transition-timing-function:ease}.van-popup--center{left:50%;top:50%;transform:translate3d(-50%,-50%,0)}.van-popup--center.van-popup--round{border-radius:var(--popup-round-border-radius,16px)}.van-popup--top{left:0;top:0;width:100%}.van-popup--top.van-popup--round{border-radius:0 0 var(--popup-round-border-radius,var(--popup-round-border-radius,16px)) var(--popup-round-border-radius,var(--popup-round-border-radius,16px))}.van-popup--right{right:0;top:50%;transform:translate3d(0,-50%,0)}.van-popup--right.van-popup--round{border-radius:var(--popup-round-border-radius,var(--popup-round-border-radius,16px)) 0 0 var(--popup-round-border-radius,var(--popup-round-border-radius,16px))}.van-popup--bottom{bottom:0;left:0;width:100%}.van-popup--bottom.van-popup--round{border-radius:var(--popup-round-border-radius,var(--popup-round-border-radius,16px)) var(--popup-round-border-radius,var(--popup-round-border-radius,16px)) 0 0}.van-popup--left{left:0;top:50%;transform:translate3d(0,-50%,0)}.van-popup--left.van-popup--round{border-radius:0 var(--popup-round-border-radius,var(--popup-round-border-radius,16px)) var(--popup-round-border-radius,var(--popup-round-border-radius,16px)) 0}.van-popup--bottom.van-popup--safe{padding-bottom:env(safe-area-inset-bottom)}.van-popup--bottom.van-popup--safeTabBar{bottom:var(--tabbar-height,50px)}.van-popup--safeTop{padding-top:env(safe-area-inset-top)}.van-popup__close-icon{color:var(--popup-close-icon-color,#969799);font-size:var(--popup-close-icon-size,18px);position:absolute;z-index:var(--popup-close-icon-z-index,1)}.van-popup__close-icon--top-left{left:var(--popup-close-icon-margin,16px);top:var(--popup-close-icon-margin,16px)}.van-popup__close-icon--top-right{right:var(--popup-close-icon-margin,16px);top:var(--popup-close-icon-margin,16px)}.van-popup__close-icon--bottom-left{bottom:var(--popup-close-icon-margin,16px);left:var(--popup-close-icon-margin,16px)}.van-popup__close-icon--bottom-right{bottom:var(--popup-close-icon-margin,16px);right:var(--popup-close-icon-margin,16px)}.van-popup__close-icon:active{opacity:.6}.van-scale-enter-active,.van-scale-leave-active{transition-property:opacity,transform}.van-scale-enter,.van-scale-leave-to{opacity:0;transform:translate3d(-50%,-50%,0) scale(.7)}.van-fade-enter-active,.van-fade-leave-active{transition-property:opacity}.van-fade-enter,.van-fade-leave-to{opacity:0}.van-center-enter-active,.van-center-leave-active{transition-property:opacity}.van-center-enter,.van-center-leave-to{opacity:0}.van-bottom-enter-active,.van-bottom-leave-active,.van-left-enter-active,.van-left-leave-active,.van-right-enter-active,.van-right-leave-active,.van-top-enter-active,.van-top-leave-active{transition-property:transform}.van-bottom-enter,.van-bottom-leave-to{transform:translate3d(0,100%,0)}.van-top-enter,.van-top-leave-to{transform:translate3d(0,-100%,0)}.van-left-enter,.van-left-leave-to{transform:translate3d(-100%,-50%,0)}.van-right-enter,.van-right-leave-to{transform:translate3d(100%,-50%,0)}
\ No newline at end of file
......@@ -4,6 +4,10 @@ VantComponent({
field: true,
classes: ['field-class', 'input-class', 'cancel-class'],
props: {
value: {
type: String,
value: '',
},
label: String,
focus: Boolean,
error: Boolean,
......@@ -60,7 +64,7 @@ VantComponent({
onCancel() {
/**
* 修复修改输入框值时,输入框失焦和赋值同时触发,赋值失效
* https://github.com/vant-ui/vant-weapp/issues/1768
* https://github.com/youzan/vant-weapp/issues/1768
*/
setTimeout(() => {
if (canIUseModel()) {
......
......@@ -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>
@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
import { VantComponent } from '../common/component';
import { touch } from '../mixins/touch';
import { canIUseModel } from '../common/version';
import { getRect, addUnit } from '../common/utils';
import { getRect, addUnit, nextTick } from '../common/utils';
const DRAG_STATUS = {
START: 'start',
MOVING: 'moving',
END: 'end',
};
VantComponent({
mixins: [touch],
props: {
......@@ -54,16 +59,16 @@ VantComponent({
else {
this.startValue = this.format(this.newValue);
}
this.dragStatus = 'start';
this.dragStatus = DRAG_STATUS.START;
},
onTouchMove(event) {
if (this.data.disabled)
return;
if (this.dragStatus === 'start') {
if (this.dragStatus === DRAG_STATUS.START) {
this.$emit('drag-start');
}
this.touchMove(event);
this.dragStatus = 'draging';
this.dragStatus = DRAG_STATUS.MOVING;
getRect(this, '.van-slider').then((rect) => {
const { vertical } = this.data;
const delta = vertical ? this.deltaY : this.deltaX;
......@@ -82,9 +87,12 @@ VantComponent({
onTouchEnd() {
if (this.data.disabled)
return;
if (this.dragStatus === 'draging') {
this.updateValue(this.newValue, true);
this.$emit('drag-end');
if (this.dragStatus === DRAG_STATUS.MOVING) {
this.dragStatus = DRAG_STATUS.END;
nextTick(() => {
this.updateValue(this.newValue, true);
this.$emit('drag-end');
});
}
},
onClick(event) {
......@@ -163,15 +171,19 @@ VantComponent({
const { max, min } = this.data;
return max - min;
},
getOffsetWidth(current, min) {
const scope = this.getScope();
// 避免最小值小于最小step时出现负数情况
return `${Math.max(((current - min) * 100) / scope, 0)}%`;
},
// 计算选中条的长度百分比
calcMainAxis() {
const { value } = this;
const { min } = this.data;
const scope = this.getScope();
if (this.isRange(value)) {
return `${((value[1] - value[0]) * 100) / scope}%`;
return this.getOffsetWidth(value[1], value[0]);
}
return `${((value - Number(min)) * 100) / scope}%`;
return this.getOffsetWidth(value, Number(min));
},
// 计算选中条的开始位置的偏移量
calcOffset() {
......
......@@ -16,7 +16,6 @@ VantComponent({
props: {
value: {
type: null,
observer: 'observeValue',
},
integer: {
type: Boolean,
......@@ -66,6 +65,11 @@ VantComponent({
data: {
currentValue: '',
},
watch: {
value() {
this.observeValue();
},
},
created() {
this.setData({
currentValue: this.format(this.data.value),
......@@ -73,10 +77,8 @@ VantComponent({
},
methods: {
observeValue() {
const { value, currentValue } = this.data;
if (!equal(value, currentValue)) {
this.setData({ currentValue: this.format(value) });
}
const { value } = this.data;
this.setData({ currentValue: this.format(value) });
},
check() {
const val = this.format(this.data.currentValue);
......@@ -85,7 +87,7 @@ VantComponent({
}
},
isDisabled(type) {
const { disabled, disablePlus, disableMinus, currentValue, max, min, } = this.data;
const { disabled, disablePlus, disableMinus, currentValue, max, min } = this.data;
if (type === 'plus') {
return disabled || disablePlus || currentValue >= max;
}
......@@ -96,6 +98,7 @@ VantComponent({
},
onBlur(event) {
const value = this.format(event.detail.value);
this.setData({ currentValue: value });
this.emitChange(value);
this.$emit('blur', Object.assign(Object.assign({}, event.detail), { value }));
},
......
......@@ -16,7 +16,6 @@
<slot name="minus" />
</view>
<input
always-embed="{{ false }}"
type="{{ integer ? 'number' : 'digit' }}"
class="input-class {{ utils.bem('stepper__input', { disabled: disabled || disableInput }) }}"
style="{{ computed.inputStyle({ buttonSize, inputWidth }) }}"
......
......@@ -20,7 +20,7 @@
wx:if="{{ item.inactiveIcon || inactiveIcon }}"
color="{{ status(index, active) === 'inactive' ? inactiveColor: activeColor }}"
name="{{ item.inactiveIcon || inactiveIcon }}"
custom-class="van-step__icon"
class="van-step__icon"
/>
<view
wx:else
......@@ -29,7 +29,7 @@
/>
</block>
<van-icon wx:else name="{{ item.activeIcon || activeIcon }}" color="{{ activeColor }}" custom-class="van-step__icon" />
<van-icon wx:else name="{{ item.activeIcon || activeIcon }}" color="{{ activeColor }}" class="van-step__icon" />
</view>
<view
wx:if="{{ index !== steps.length - 1 }}"
......
......@@ -6,6 +6,14 @@ VantComponent({
name: null,
icon: String,
dot: Boolean,
url: {
type: String,
value: '',
},
linkType: {
type: String,
value: 'redirectTo',
},
iconPrefix: {
type: String,
value: 'van-icon',
......@@ -27,6 +35,10 @@ VantComponent({
parent.$emit('change', active);
}
}
const { url, linkType } = this.data;
if (url && wx[linkType]) {
return wx[linkType]({ url });
}
this.$emit('click');
},
updateFromParent() {
......
......@@ -5,7 +5,13 @@ import { isDef } from '../common/validator';
import { useChildren } from '../common/relation';
VantComponent({
mixins: [touch],
classes: ['nav-class', 'tab-class', 'tab-active-class', 'line-class'],
classes: [
'nav-class',
'tab-class',
'tab-active-class',
'line-class',
'wrap-class',
],
relation: useChildren('tab', function () {
this.updateTabs();
}),
......@@ -73,6 +79,10 @@ VantComponent({
type: Boolean,
value: true,
},
useBeforeChange: {
type: Boolean,
value: false,
},
},
data: {
tabs: [],
......@@ -83,6 +93,7 @@ VantComponent({
skipTransition: true,
scrollWithAnimation: false,
lineOffsetLeft: 0,
inited: false,
},
mounted() {
requestAnimationFrame(() => {
......@@ -105,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) {
......@@ -191,12 +199,13 @@ VantComponent({
.reduce((prev, curr) => prev + curr.width, 0);
lineOffsetLeft +=
(rect.width - lineRect.width) / 2 + (ellipsis ? 0 : 8);
this.setData({ lineOffsetLeft });
this.setData({ lineOffsetLeft, inited: true });
this.swiping = true;
if (skipTransition) {
nextTick(() => {
// waiting transition end
setTimeout(() => {
this.setData({ skipTransition: false });
});
}, this.data.duration);
}
});
},
......@@ -247,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;
......@@ -266,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,
};
},
},
});
......@@ -9,7 +9,7 @@
container="{{ container }}"
bind:scroll="onTouchScroll"
>
<view class="{{ utils.bem('tabs__wrap', { scrollable }) }} {{ type === 'line' && border ? 'van-hairline--top-bottom' : '' }}">
<view class="{{ utils.bem('tabs__wrap', { scrollable }) }} {{ type === 'line' && border ? 'van-hairline--top-bottom' : '' }} wrap-class">
<slot name="nav-left" />
<scroll-view
......@@ -20,7 +20,7 @@
style="{{ color ? 'border-color: ' + color : '' }}"
>
<view class="{{ utils.bem('tabs__nav', [type, { complete: !ellipsis }]) }} nav-class" style="{{ computed.navStyle(color, type) }}">
<view wx:if="{{ type === 'line' }}" class="van-tabs__line" style="{{ computed.lineStyle({ color, lineOffsetLeft, lineHeight, skipTransition, duration, lineWidth }) }}" />
<view wx:if="{{ type === 'line' }}" class="van-tabs__line" style="{{ computed.lineStyle({ color, lineOffsetLeft, lineHeight, skipTransition, duration, lineWidth, inited }) }}" />
<view
wx:for="{{ tabs }}"
wx:key="index"
......
......@@ -60,6 +60,7 @@ function trackStyle(data) {
function lineStyle(data) {
return style({
width: utils.addUnit(data.lineWidth),
opacity: data.inited ? 1 : 0,
transform: 'translateX(' + data.lineOffsetLeft + 'px)',
'-webkit-transform': 'translateX(' + data.lineOffsetLeft + 'px)',
'background-color': data.color,
......
@import '../common/index.wxss';.van-tabs{-webkit-tap-highlight-color:transparent;position:relative}.van-tabs__wrap{display:flex;overflow:hidden}.van-tabs__wrap--scrollable .van-tab{flex:0 0 22%}.van-tabs__wrap--scrollable .van-tab--complete{flex:1 0 auto!important;padding:0 12px}.van-tabs__wrap--scrollable .van-tabs__nav--complete{padding-left:8px;padding-right:8px}.van-tabs__scroll{background-color:var(--tabs-nav-background-color,#fff)}.van-tabs__scroll--line{box-sizing:initial;height:calc(100% + 15px)}.van-tabs__scroll--card{border:1px solid var(--tabs-default-color,#ee0a24);border-radius:2px;box-sizing:border-box;margin:0 var(--padding-md,16px);width:calc(100% - var(--padding-md, 16px)*2)}.van-tabs__scroll::-webkit-scrollbar{display:none}.van-tabs__nav{display:flex;position:relative;-webkit-user-select:none;user-select:none}.van-tabs__nav--card{box-sizing:border-box;height:var(--tabs-card-height,30px)}.van-tabs__nav--card .van-tab{border-right:1px solid var(--tabs-default-color,#ee0a24);color:var(--tabs-default-color,#ee0a24);line-height:calc(var(--tabs-card-height, 30px) - 2px)}.van-tabs__nav--card .van-tab:last-child{border-right:none}.van-tabs__nav--card .van-tab.van-tab--active{background-color:var(--tabs-default-color,#ee0a24);color:#fff}.van-tabs__nav--card .van-tab--disabled{color:var(--tab-disabled-text-color,#c8c9cc)}.van-tabs__line{background-color:var(--tabs-bottom-bar-color,#ee0a24);border-radius:var(--tabs-bottom-bar-height,3px);bottom:0;height:var(--tabs-bottom-bar-height,3px);left:0;position:absolute;z-index:1}.van-tabs__track{height:100%;position:relative;width:100%}.van-tabs__track--animated{display:flex;transition-property:left}.van-tabs__content{overflow:hidden}.van-tabs--line .van-tabs__wrap{height:var(--tabs-line-height,44px)}.van-tabs--card .van-tabs__wrap{height:var(--tabs-card-height,30px)}.van-tab{box-sizing:border-box;color:var(--tab-text-color,#646566);cursor:pointer;flex:1;font-size:var(--tab-font-size,14px);line-height:var(--tabs-line-height,44px);min-width:0;padding:0 5px;position:relative;text-align:center}.van-tab--active{color:var(--tab-active-text-color,#323233);font-weight:var(--font-weight-bold,500)}.van-tab--disabled{color:var(--tab-disabled-text-color,#c8c9cc)}.van-tab__title__info{display:inline-block;position:relative!important;top:-1px!important;transform:translateX(0)!important}
\ No newline at end of file
@import '../common/index.wxss';.van-tabs{-webkit-tap-highlight-color:transparent;position:relative}.van-tabs__wrap{display:flex;overflow:hidden}.van-tabs__wrap--scrollable .van-tab{flex:0 0 22%}.van-tabs__wrap--scrollable .van-tab--complete{flex:1 0 auto!important;padding:0 12px}.van-tabs__wrap--scrollable .van-tabs__nav--complete{padding-left:8px;padding-right:8px}.van-tabs__scroll{background-color:var(--tabs-nav-background-color,#fff)}.van-tabs__scroll--line{box-sizing:initial;height:calc(100% + 15px)}.van-tabs__scroll--card{border:1px solid var(--tabs-default-color,#ee0a24);border-radius:2px;box-sizing:border-box;margin:0 var(--padding-md,16px);width:calc(100% - var(--padding-md, 16px)*2)}.van-tabs__scroll::-webkit-scrollbar{display:none}.van-tabs__nav{display:flex;position:relative;-webkit-user-select:none;user-select:none}.van-tabs__nav--card{box-sizing:border-box;height:var(--tabs-card-height,30px)}.van-tabs__nav--card .van-tab{border-right:1px solid var(--tabs-default-color,#ee0a24);color:var(--tabs-default-color,#ee0a24);line-height:calc(var(--tabs-card-height, 30px) - 2px)}.van-tabs__nav--card .van-tab:last-child{border-right:none}.van-tabs__nav--card .van-tab.van-tab--active{background-color:var(--tabs-default-color,#ee0a24);color:#fff}.van-tabs__nav--card .van-tab--disabled{color:var(--tab-disabled-text-color,#c8c9cc)}.van-tabs__line{background-color:var(--tabs-bottom-bar-color,#ee0a24);border-radius:var(--tabs-bottom-bar-height,3px);bottom:0;height:var(--tabs-bottom-bar-height,3px);left:0;opacity:0;position:absolute;z-index:1}.van-tabs__track{height:100%;position:relative;width:100%}.van-tabs__track--animated{display:flex;transition-property:left}.van-tabs__content{overflow:hidden}.van-tabs--line .van-tabs__wrap{height:var(--tabs-line-height,44px)}.van-tabs--card .van-tabs__wrap{height:var(--tabs-card-height,30px)}.van-tab{box-sizing:border-box;color:var(--tab-text-color,#646566);cursor:pointer;flex:1;font-size:var(--tab-font-size,14px);line-height:var(--tabs-line-height,44px);min-width:0;padding:0 5px;position:relative;text-align:center}.van-tab--active{color:var(--tab-active-text-color,#323233);font-weight:var(--font-weight-bold,500)}.van-tab--disabled{color:var(--tab-disabled-text-color,#c8c9cc)}.van-tab__title__info{display:inline-block;position:relative!important;top:-1px!important;transform:translateX(0)!important}
\ No newline at end of file
import { VantComponent } from '../common/component';
import { isImageFile, chooseFile, isVideoFile } from './utils';
import { chooseImageProps, chooseVideoProps } from './shared';
import { imageProps, videoProps, mediaProps, messageFileProps } from './shared';
import { isBoolean, isPromise } from '../common/validator';
VantComponent({
props: Object.assign(Object.assign({ disabled: Boolean, multiple: Boolean, uploadText: String, useBeforeRead: Boolean, afterRead: null, beforeRead: null, previewSize: {
props: Object.assign(Object.assign(Object.assign(Object.assign({ disabled: Boolean, multiple: Boolean, uploadText: String, useBeforeRead: Boolean, afterRead: null, beforeRead: null, previewSize: {
type: null,
value: 80,
}, name: {
......@@ -40,7 +40,7 @@ VantComponent({
}, uploadIcon: {
type: String,
value: 'photograph',
} }, chooseImageProps), chooseVideoProps),
} }, imageProps), videoProps), mediaProps), messageFileProps),
data: {
lists: [],
isInCount: true,
......@@ -114,11 +114,12 @@ VantComponent({
if (!this.data.previewFullImage)
return;
const { index } = event.currentTarget.dataset;
const { lists } = this.data;
const { lists, showmenu } = this.data;
const item = lists[index];
wx.previewImage({
urls: lists.filter((item) => isImageFile(item)).map((item) => item.url),
current: item.url,
showmenu,
fail() {
wx.showToast({ title: '预览图片失败', icon: 'none' });
},
......@@ -129,11 +130,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' });
},
......
// props for choose image
export const chooseImageProps = {
// props for image
export const imageProps = {
sizeType: {
type: Array,
value: ['original', 'compressed'],
......@@ -8,9 +8,13 @@ export const chooseImageProps = {
type: Array,
value: ['album', 'camera'],
},
showmenu: {
type: Boolean,
value: true,
},
};
// props for choose video
export const chooseVideoProps = {
// props for video
export const videoProps = {
capture: {
type: Array,
value: ['album', 'camera'],
......@@ -28,3 +32,26 @@ export const chooseVideoProps = {
value: 'back',
},
};
// props for media
export const mediaProps = {
capture: {
type: Array,
value: ['album', 'camera'],
},
mediaType: {
type: Array,
value: ['image', 'video'],
},
maxDuration: {
type: Number,
value: 60,
},
camera: {
type: String,
value: 'back',
},
};
// props for file
export const messageFileProps = {
extension: null,
};
......@@ -38,7 +38,7 @@ function formatMedia(res) {
function formatFile(res) {
return res.tempFiles.map((item) => (Object.assign(Object.assign({}, pickExclude(item, ['path'])), { url: item.path })));
}
export function chooseFile({ accept, multiple, capture, compressed, maxDuration, sizeType, camera, maxCount, }) {
export function chooseFile({ accept, multiple, capture, compressed, maxDuration, sizeType, camera, maxCount, mediaType, extension, }) {
return new Promise((resolve, reject) => {
switch (accept) {
case 'image':
......@@ -53,6 +53,7 @@ export function chooseFile({ accept, multiple, capture, compressed, maxDuration,
case 'media':
wx.chooseMedia({
count: multiple ? Math.min(maxCount, 9) : 1,
mediaType,
sourceType: capture,
maxDuration,
sizeType,
......@@ -72,12 +73,7 @@ export function chooseFile({ accept, multiple, capture, compressed, maxDuration,
});
break;
default:
wx.chooseMessageFile({
count: multiple ? maxCount : 1,
type: accept,
success: (res) => resolve(formatFile(res)),
fail: reject,
});
wx.chooseMessageFile(Object.assign(Object.assign({ count: multiple ? maxCount : 1, type: accept }, (extension ? { extension } : {})), { success: (res) => resolve(formatFile(res)), fail: reject }));
break;
}
});
......
......@@ -44,7 +44,7 @@
"useCompilerPlugins": false
},
"compileType": "miniprogram",
"libVersion": "2.19.4",
"libVersion": "2.25.3",
"appid": "wxcf4f3a217a8bc728",
"projectname": "miniprogram-92",
"condition": {},
......