mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2026-06-05 01:58:11 +08:00
Compare commits
8 Commits
b5ab3bee64
...
6bf19926a4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bf19926a4 | ||
|
|
0707986854 | ||
|
|
6f85ec453e | ||
|
|
8be5c5694f | ||
|
|
7cfe300ed8 | ||
|
|
3e42951387 | ||
|
|
0d1f370059 | ||
|
|
9e17b13164 |
21
dist/field/index.js
vendored
21
dist/field/index.js
vendored
@ -36,6 +36,10 @@ VantComponent({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
observer: 'setShowClear',
|
observer: 'setShowClear',
|
||||||
},
|
},
|
||||||
|
clearTrigger: {
|
||||||
|
type: String,
|
||||||
|
value: 'focus',
|
||||||
|
},
|
||||||
border: {
|
border: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: true,
|
value: true,
|
||||||
@ -44,6 +48,10 @@ VantComponent({
|
|||||||
type: String,
|
type: String,
|
||||||
value: '6.2em',
|
value: '6.2em',
|
||||||
},
|
},
|
||||||
|
clearIcon: {
|
||||||
|
type: String,
|
||||||
|
value: 'clear',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
data: {
|
data: {
|
||||||
@ -115,11 +123,16 @@ VantComponent({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
setShowClear() {
|
setShowClear() {
|
||||||
const { clearable, readonly } = this.data;
|
const { clearable, readonly, clearTrigger } = this.data;
|
||||||
const { focused, value } = this;
|
const { focused, value } = this;
|
||||||
this.setData({
|
let showClear = false;
|
||||||
showClear: !!clearable && !!focused && !!value && !readonly,
|
if (clearable && !readonly) {
|
||||||
});
|
const hasValue = !!value;
|
||||||
|
const trigger =
|
||||||
|
clearTrigger === 'always' || (clearTrigger === 'focus' && focused);
|
||||||
|
showClear = hasValue && trigger;
|
||||||
|
}
|
||||||
|
this.setData({ showClear });
|
||||||
},
|
},
|
||||||
noop() {},
|
noop() {},
|
||||||
},
|
},
|
||||||
|
|||||||
2
dist/field/index.wxml
vendored
2
dist/field/index.wxml
vendored
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
<van-icon
|
<van-icon
|
||||||
wx:if="{{ showClear }}"
|
wx:if="{{ showClear }}"
|
||||||
name="clear"
|
name="{{ clearIcon }}"
|
||||||
class="van-field__clear-root van-field__icon-root"
|
class="van-field__clear-root van-field__icon-root"
|
||||||
catch:touchstart="onClear"
|
catch:touchstart="onClear"
|
||||||
/>
|
/>
|
||||||
|
|||||||
12
dist/mixins/page-scroll.js
vendored
12
dist/mixins/page-scroll.js
vendored
@ -1,4 +1,4 @@
|
|||||||
import { getCurrentPage } from '../common/utils';
|
import { getCurrentPage, isDef } from '../common/utils';
|
||||||
function onPageScroll(event) {
|
function onPageScroll(event) {
|
||||||
const { vanPageScroller = [] } = getCurrentPage();
|
const { vanPageScroller = [] } = getCurrentPage();
|
||||||
vanPageScroller.forEach((scroller) => {
|
vanPageScroller.forEach((scroller) => {
|
||||||
@ -25,9 +25,11 @@ export const pageScrollMixin = (scroller) =>
|
|||||||
detached() {
|
detached() {
|
||||||
var _a;
|
var _a;
|
||||||
const page = getCurrentPage();
|
const page = getCurrentPage();
|
||||||
page.vanPageScroller =
|
if (!isDef(page)) {
|
||||||
((_a = page.vanPageScroller) === null || _a === void 0
|
page.vanPageScroller =
|
||||||
? void 0
|
((_a = page.vanPageScroller) === null || _a === void 0
|
||||||
: _a.filter((item) => item !== scroller)) || [];
|
? void 0
|
||||||
|
: _a.filter((item) => item !== scroller)) || [];
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
8
dist/search/index.js
vendored
8
dist/search/index.js
vendored
@ -41,6 +41,14 @@ VantComponent({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: true,
|
value: true,
|
||||||
},
|
},
|
||||||
|
clearTrigger: {
|
||||||
|
type: String,
|
||||||
|
value: 'focus',
|
||||||
|
},
|
||||||
|
clearIcon: {
|
||||||
|
type: String,
|
||||||
|
value: 'clear',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onChange(event) {
|
onChange(event) {
|
||||||
|
|||||||
2
dist/search/index.wxml
vendored
2
dist/search/index.wxml
vendored
@ -21,6 +21,8 @@
|
|||||||
disabled="{{ disabled }}"
|
disabled="{{ disabled }}"
|
||||||
readonly="{{ readonly }}"
|
readonly="{{ readonly }}"
|
||||||
clearable="{{ clearable }}"
|
clearable="{{ clearable }}"
|
||||||
|
clear-trigger="{{ clearTrigger }}"
|
||||||
|
clear-icon="{{ clearIcon }}"
|
||||||
maxlength="{{ maxlength }}"
|
maxlength="{{ maxlength }}"
|
||||||
input-align="{{ inputAlign }}"
|
input-align="{{ inputAlign }}"
|
||||||
input-class="input-class"
|
input-class="input-class"
|
||||||
|
|||||||
65
dist/slider/index.js
vendored
65
dist/slider/index.js
vendored
@ -5,6 +5,7 @@ import { getRect } from '../common/utils';
|
|||||||
VantComponent({
|
VantComponent({
|
||||||
mixins: [touch],
|
mixins: [touch],
|
||||||
props: {
|
props: {
|
||||||
|
range: Boolean,
|
||||||
disabled: Boolean,
|
disabled: Boolean,
|
||||||
useButtonSlot: Boolean,
|
useButtonSlot: Boolean,
|
||||||
activeColor: String,
|
activeColor: String,
|
||||||
@ -24,6 +25,7 @@ VantComponent({
|
|||||||
value: {
|
value: {
|
||||||
type: Number,
|
type: Number,
|
||||||
value: 0,
|
value: 0,
|
||||||
|
optionalTypes: [Array],
|
||||||
observer(val) {
|
observer(val) {
|
||||||
if (val !== this.value) {
|
if (val !== this.value) {
|
||||||
this.updateValue(val);
|
this.updateValue(val);
|
||||||
@ -38,8 +40,18 @@ VantComponent({
|
|||||||
methods: {
|
methods: {
|
||||||
onTouchStart(event) {
|
onTouchStart(event) {
|
||||||
if (this.data.disabled) return;
|
if (this.data.disabled) return;
|
||||||
|
const { index } = event.currentTarget.dataset;
|
||||||
|
if (typeof index === 'number') {
|
||||||
|
this.buttonIndex = index;
|
||||||
|
}
|
||||||
this.touchStart(event);
|
this.touchStart(event);
|
||||||
this.startValue = this.format(this.value);
|
this.startValue = this.format(this.value);
|
||||||
|
this.newValue = this.value;
|
||||||
|
if (this.isRange(this.newValue)) {
|
||||||
|
this.startValue = this.newValue.map((val) => this.format(val));
|
||||||
|
} else {
|
||||||
|
this.startValue = this.format(this.newValue);
|
||||||
|
}
|
||||||
this.dragStatus = 'start';
|
this.dragStatus = 'start';
|
||||||
},
|
},
|
||||||
onTouchMove(event) {
|
onTouchMove(event) {
|
||||||
@ -51,7 +63,12 @@ VantComponent({
|
|||||||
this.dragStatus = 'draging';
|
this.dragStatus = 'draging';
|
||||||
getRect(this, '.van-slider').then((rect) => {
|
getRect(this, '.van-slider').then((rect) => {
|
||||||
const diff = (this.deltaX / rect.width) * this.getRange();
|
const diff = (this.deltaX / rect.width) * this.getRange();
|
||||||
this.newValue = this.startValue + diff;
|
if (this.isRange(this.startValue)) {
|
||||||
|
this.newValue[this.buttonIndex] =
|
||||||
|
this.startValue[this.buttonIndex] + diff;
|
||||||
|
} else {
|
||||||
|
this.newValue = this.startValue + diff;
|
||||||
|
}
|
||||||
this.updateValue(this.newValue, false, true);
|
this.updateValue(this.newValue, false, true);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -68,17 +85,40 @@ VantComponent({
|
|||||||
getRect(this, '.van-slider').then((rect) => {
|
getRect(this, '.van-slider').then((rect) => {
|
||||||
const value =
|
const value =
|
||||||
((event.detail.x - rect.left) / rect.width) * this.getRange() + min;
|
((event.detail.x - rect.left) / rect.width) * this.getRange() + min;
|
||||||
this.updateValue(value, true);
|
if (this.isRange(this.value)) {
|
||||||
|
const [left, right] = this.value;
|
||||||
|
const middle = (left + right) / 2;
|
||||||
|
if (value <= middle) {
|
||||||
|
this.updateValue([value, right], true);
|
||||||
|
} else {
|
||||||
|
this.updateValue([left, value], true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.updateValue(value, true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
isRange(val) {
|
||||||
|
const { range } = this.data;
|
||||||
|
return range && Array.isArray(val);
|
||||||
|
},
|
||||||
|
handleOverlap(value) {
|
||||||
|
if (value[0] > value[1]) {
|
||||||
|
return value.slice(0).reverse();
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
},
|
||||||
updateValue(value, end, drag) {
|
updateValue(value, end, drag) {
|
||||||
value = this.format(value);
|
if (this.isRange(value)) {
|
||||||
const { min } = this.data;
|
value = this.handleOverlap(value).map((val) => this.format(val));
|
||||||
const width = `${((value - min) * 100) / this.getRange()}%`;
|
} else {
|
||||||
|
value = this.format(value);
|
||||||
|
}
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.setData({
|
this.setData({
|
||||||
barStyle: `
|
barStyle: `
|
||||||
width: ${width};
|
width: ${this.calcMainAxis()};
|
||||||
|
left: ${this.isRange(value) ? `${value[0]}%` : 0};
|
||||||
${drag ? 'transition: none;' : ''}
|
${drag ? 'transition: none;' : ''}
|
||||||
`,
|
`,
|
||||||
});
|
});
|
||||||
@ -92,10 +132,23 @@ VantComponent({
|
|||||||
this.setData({ value });
|
this.setData({ value });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
getScope() {
|
||||||
|
return Number(this.data.max) - Number(this.data.min);
|
||||||
|
},
|
||||||
getRange() {
|
getRange() {
|
||||||
const { max, min } = this.data;
|
const { max, min } = this.data;
|
||||||
return max - min;
|
return max - min;
|
||||||
},
|
},
|
||||||
|
// 计算选中条的长度百分比
|
||||||
|
calcMainAxis() {
|
||||||
|
const { value } = this;
|
||||||
|
const { min } = this.data;
|
||||||
|
const scope = this.getScope();
|
||||||
|
if (this.isRange(value)) {
|
||||||
|
return `${((value[1] - value[0]) * 100) / scope}%`;
|
||||||
|
}
|
||||||
|
return `${((value - Number(min)) * 100) / scope}%`;
|
||||||
|
},
|
||||||
format(value) {
|
format(value) {
|
||||||
const { max, min, step } = this.data;
|
const { max, min, step } = this.data;
|
||||||
return Math.round(Math.max(min, Math.min(value, max)) / step) * step;
|
return Math.round(Math.max(min, Math.min(value, max)) / step) * step;
|
||||||
|
|||||||
38
dist/slider/index.wxml
vendored
38
dist/slider/index.wxml
vendored
@ -11,6 +11,44 @@
|
|||||||
style="{{ barStyle }}; {{ style({ backgroundColor: activeColor }) }}"
|
style="{{ barStyle }}; {{ style({ backgroundColor: activeColor }) }}"
|
||||||
>
|
>
|
||||||
<view
|
<view
|
||||||
|
wx:if="{{ range }}"
|
||||||
|
class="{{ utils.bem('slider__button-wrapper-left') }}"
|
||||||
|
data-index="{{ 0 }}"
|
||||||
|
bind:touchstart="onTouchStart"
|
||||||
|
catch:touchmove="onTouchMove"
|
||||||
|
bind:touchend="onTouchEnd"
|
||||||
|
bind:touchcancel="onTouchEnd"
|
||||||
|
>
|
||||||
|
<slot
|
||||||
|
wx:if="{{ useButtonSlot }}"
|
||||||
|
name="left-button"
|
||||||
|
/>
|
||||||
|
<view
|
||||||
|
wx:else
|
||||||
|
class="{{ utils.bem('slider__button') }}"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
<view
|
||||||
|
wx:if="{{ range }}"
|
||||||
|
class="{{ utils.bem('slider__button-wrapper-right') }}"
|
||||||
|
data-index="{{ 1 }}"
|
||||||
|
bind:touchstart="onTouchStart"
|
||||||
|
catch:touchmove="onTouchMove"
|
||||||
|
bind:touchend="onTouchEnd"
|
||||||
|
bind:touchcancel="onTouchEnd"
|
||||||
|
>
|
||||||
|
<slot
|
||||||
|
wx:if="{{ useButtonSlot }}"
|
||||||
|
name="right-button"
|
||||||
|
/>
|
||||||
|
<view
|
||||||
|
wx:else
|
||||||
|
class="{{ utils.bem('slider__button') }}"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view
|
||||||
|
wx:if="{{ !range }}"
|
||||||
class="{{ utils.bem('slider__button-wrapper') }}"
|
class="{{ utils.bem('slider__button-wrapper') }}"
|
||||||
bind:touchstart="onTouchStart"
|
bind:touchstart="onTouchStart"
|
||||||
catch:touchmove="onTouchMove"
|
catch:touchmove="onTouchMove"
|
||||||
|
|||||||
2
dist/slider/index.wxss
vendored
2
dist/slider/index.wxss
vendored
@ -1 +1 @@
|
|||||||
@import '../common/index.wxss';.van-slider{position:relative;height:2px;height:var(--slider-bar-height,2px);border-radius:999px;border-radius:var(--border-radius-max,999px);background-color:#ebedf0;background-color:var(--slider-inactive-background-color,#ebedf0)}.van-slider:before{position:absolute;right:0;left:0;content:"";top:-8px;top:-var(--padding-xs,8px);bottom:-8px;bottom:-var(--padding-xs,8px)}.van-slider__bar{position:relative;width:100%;height:100%;background-color:#1989fa;background-color:var(--slider-active-background-color,#1989fa);border-radius:inherit;transition:all .2s;transition:all var(--animation-duration-fast,.2s)}.van-slider__button{width:24px;width:var(--slider-button-width,24px);height:24px;height:var(--slider-button-height,24px);border-radius:50%;border-radius:var(--slider-button-border-radius,50%);box-shadow:0 1px 2px rgba(0,0,0,.5);box-shadow:var(--slider-button-box-shadow,0 1px 2px rgba(0,0,0,.5));background-color:#fff;background-color:var(--slider-button-background-color,#fff)}.van-slider__button-wrapper{position:absolute;top:50%;right:0;transform:translate3d(50%,-50%,0)}.van-slider--disabled{opacity:.5;opacity:var(--slider-disabled-opacity,.5)}
|
@import '../common/index.wxss';.van-slider{position:relative;height:2px;height:var(--slider-bar-height,2px);border-radius:999px;border-radius:var(--border-radius-max,999px);background-color:#ebedf0;background-color:var(--slider-inactive-background-color,#ebedf0)}.van-slider:before{position:absolute;right:0;left:0;content:"";top:-8px;top:-var(--padding-xs,8px);bottom:-8px;bottom:-var(--padding-xs,8px)}.van-slider__bar{position:relative;width:100%;height:100%;background-color:#1989fa;background-color:var(--slider-active-background-color,#1989fa);border-radius:inherit;transition:all .2s;transition:all var(--animation-duration-fast,.2s)}.van-slider__button{width:24px;width:var(--slider-button-width,24px);height:24px;height:var(--slider-button-height,24px);border-radius:50%;border-radius:var(--slider-button-border-radius,50%);box-shadow:0 1px 2px rgba(0,0,0,.5);box-shadow:var(--slider-button-box-shadow,0 1px 2px rgba(0,0,0,.5));background-color:#fff;background-color:var(--slider-button-background-color,#fff)}.van-slider__button-wrapper,.van-slider__button-wrapper-right{position:absolute;top:50%;right:0;transform:translate3d(50%,-50%,0)}.van-slider__button-wrapper-left{position:absolute;top:50%;left:0;transform:translate3d(-50%,-50%,0)}.van-slider--disabled{opacity:.5;opacity:var(--slider-disabled-opacity,.5)}
|
||||||
@ -1,5 +1,20 @@
|
|||||||
# 更新日志
|
# 更新日志
|
||||||
|
|
||||||
|
### [1.8.4](https://github.com/youzan/vant-weapp/compare/v1.8.3...v1.8.4)
|
||||||
|
|
||||||
|
`2021-09-07`
|
||||||
|
|
||||||
|
**Bug Fixes**
|
||||||
|
|
||||||
|
- page-scroll: 修复 getCurrentPage 为空时报错 [#4458](https://github.com/youzan/vant-weapp/issues/4458)
|
||||||
|
|
||||||
|
**Features**
|
||||||
|
|
||||||
|
- Field: 新增 clear-trigger 属性 [#4461](https://github.com/youzan/vant-weapp/issues/4461)
|
||||||
|
- Search: 新增 clear-icon 属性 [#4463](https://github.com/youzan/vant-weapp/issues/4463)
|
||||||
|
- Search: 新增 clear-trigger 属性 [9e17b13](https://github.com/youzan/vant-weapp/commit/9e17b13164e57ff09140d755870853f702a89a39)
|
||||||
|
- Slider: 新增 range 属性 [#4442](https://github.com/youzan/vant-weapp/issues/4442)
|
||||||
|
|
||||||
### [v1.8.3](https://github.com/youzan/vant-weapp/compare/v1.8.2...v1.8.3)
|
### [v1.8.3](https://github.com/youzan/vant-weapp/compare/v1.8.2...v1.8.3)
|
||||||
|
|
||||||
`2021-08-30`
|
`2021-08-30`
|
||||||
|
|||||||
@ -53,6 +53,10 @@ component_1.VantComponent({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
observer: 'setShowClear',
|
observer: 'setShowClear',
|
||||||
},
|
},
|
||||||
|
clearTrigger: {
|
||||||
|
type: String,
|
||||||
|
value: 'focus',
|
||||||
|
},
|
||||||
border: {
|
border: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: true,
|
value: true,
|
||||||
@ -61,6 +65,10 @@ component_1.VantComponent({
|
|||||||
type: String,
|
type: String,
|
||||||
value: '6.2em',
|
value: '6.2em',
|
||||||
},
|
},
|
||||||
|
clearIcon: {
|
||||||
|
type: String,
|
||||||
|
value: 'clear',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
data: {
|
data: {
|
||||||
@ -138,13 +146,19 @@ component_1.VantComponent({
|
|||||||
setShowClear: function () {
|
setShowClear: function () {
|
||||||
var _a = this.data,
|
var _a = this.data,
|
||||||
clearable = _a.clearable,
|
clearable = _a.clearable,
|
||||||
readonly = _a.readonly;
|
readonly = _a.readonly,
|
||||||
|
clearTrigger = _a.clearTrigger;
|
||||||
var _b = this,
|
var _b = this,
|
||||||
focused = _b.focused,
|
focused = _b.focused,
|
||||||
value = _b.value;
|
value = _b.value;
|
||||||
this.setData({
|
var showClear = false;
|
||||||
showClear: !!clearable && !!focused && !!value && !readonly,
|
if (clearable && !readonly) {
|
||||||
});
|
var hasValue = !!value;
|
||||||
|
var trigger =
|
||||||
|
clearTrigger === 'always' || (clearTrigger === 'focus' && focused);
|
||||||
|
showClear = hasValue && trigger;
|
||||||
|
}
|
||||||
|
this.setData({ showClear: showClear });
|
||||||
},
|
},
|
||||||
noop: function () {},
|
noop: function () {},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
<van-icon
|
<van-icon
|
||||||
wx:if="{{ showClear }}"
|
wx:if="{{ showClear }}"
|
||||||
name="clear"
|
name="{{ clearIcon }}"
|
||||||
class="van-field__clear-root van-field__icon-root"
|
class="van-field__clear-root van-field__icon-root"
|
||||||
catch:touchstart="onClear"
|
catch:touchstart="onClear"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -29,12 +29,14 @@ var pageScrollMixin = function (scroller) {
|
|||||||
detached: function () {
|
detached: function () {
|
||||||
var _a;
|
var _a;
|
||||||
var page = utils_1.getCurrentPage();
|
var page = utils_1.getCurrentPage();
|
||||||
page.vanPageScroller =
|
if (!utils_1.isDef(page)) {
|
||||||
((_a = page.vanPageScroller) === null || _a === void 0
|
page.vanPageScroller =
|
||||||
? void 0
|
((_a = page.vanPageScroller) === null || _a === void 0
|
||||||
: _a.filter(function (item) {
|
? void 0
|
||||||
return item !== scroller;
|
: _a.filter(function (item) {
|
||||||
})) || [];
|
return item !== scroller;
|
||||||
|
})) || [];
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -43,6 +43,14 @@ component_1.VantComponent({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: true,
|
value: true,
|
||||||
},
|
},
|
||||||
|
clearTrigger: {
|
||||||
|
type: String,
|
||||||
|
value: 'focus',
|
||||||
|
},
|
||||||
|
clearIcon: {
|
||||||
|
type: String,
|
||||||
|
value: 'clear',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onChange: function (event) {
|
onChange: function (event) {
|
||||||
|
|||||||
@ -21,6 +21,8 @@
|
|||||||
disabled="{{ disabled }}"
|
disabled="{{ disabled }}"
|
||||||
readonly="{{ readonly }}"
|
readonly="{{ readonly }}"
|
||||||
clearable="{{ clearable }}"
|
clearable="{{ clearable }}"
|
||||||
|
clear-trigger="{{ clearTrigger }}"
|
||||||
|
clear-icon="{{ clearIcon }}"
|
||||||
maxlength="{{ maxlength }}"
|
maxlength="{{ maxlength }}"
|
||||||
input-align="{{ inputAlign }}"
|
input-align="{{ inputAlign }}"
|
||||||
input-class="input-class"
|
input-class="input-class"
|
||||||
|
|||||||
@ -7,6 +7,7 @@ var utils_1 = require('../common/utils');
|
|||||||
component_1.VantComponent({
|
component_1.VantComponent({
|
||||||
mixins: [touch_1.touch],
|
mixins: [touch_1.touch],
|
||||||
props: {
|
props: {
|
||||||
|
range: Boolean,
|
||||||
disabled: Boolean,
|
disabled: Boolean,
|
||||||
useButtonSlot: Boolean,
|
useButtonSlot: Boolean,
|
||||||
activeColor: String,
|
activeColor: String,
|
||||||
@ -26,6 +27,7 @@ component_1.VantComponent({
|
|||||||
value: {
|
value: {
|
||||||
type: Number,
|
type: Number,
|
||||||
value: 0,
|
value: 0,
|
||||||
|
optionalTypes: [Array],
|
||||||
observer: function (val) {
|
observer: function (val) {
|
||||||
if (val !== this.value) {
|
if (val !== this.value) {
|
||||||
this.updateValue(val);
|
this.updateValue(val);
|
||||||
@ -39,9 +41,22 @@ component_1.VantComponent({
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onTouchStart: function (event) {
|
onTouchStart: function (event) {
|
||||||
|
var _this = this;
|
||||||
if (this.data.disabled) return;
|
if (this.data.disabled) return;
|
||||||
|
var index = event.currentTarget.dataset.index;
|
||||||
|
if (typeof index === 'number') {
|
||||||
|
this.buttonIndex = index;
|
||||||
|
}
|
||||||
this.touchStart(event);
|
this.touchStart(event);
|
||||||
this.startValue = this.format(this.value);
|
this.startValue = this.format(this.value);
|
||||||
|
this.newValue = this.value;
|
||||||
|
if (this.isRange(this.newValue)) {
|
||||||
|
this.startValue = this.newValue.map(function (val) {
|
||||||
|
return _this.format(val);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.startValue = this.format(this.newValue);
|
||||||
|
}
|
||||||
this.dragStatus = 'start';
|
this.dragStatus = 'start';
|
||||||
},
|
},
|
||||||
onTouchMove: function (event) {
|
onTouchMove: function (event) {
|
||||||
@ -54,7 +69,12 @@ component_1.VantComponent({
|
|||||||
this.dragStatus = 'draging';
|
this.dragStatus = 'draging';
|
||||||
utils_1.getRect(this, '.van-slider').then(function (rect) {
|
utils_1.getRect(this, '.van-slider').then(function (rect) {
|
||||||
var diff = (_this.deltaX / rect.width) * _this.getRange();
|
var diff = (_this.deltaX / rect.width) * _this.getRange();
|
||||||
_this.newValue = _this.startValue + diff;
|
if (_this.isRange(_this.startValue)) {
|
||||||
|
_this.newValue[_this.buttonIndex] =
|
||||||
|
_this.startValue[_this.buttonIndex] + diff;
|
||||||
|
} else {
|
||||||
|
_this.newValue = _this.startValue + diff;
|
||||||
|
}
|
||||||
_this.updateValue(_this.newValue, false, true);
|
_this.updateValue(_this.newValue, false, true);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -72,18 +92,47 @@ component_1.VantComponent({
|
|||||||
utils_1.getRect(this, '.van-slider').then(function (rect) {
|
utils_1.getRect(this, '.van-slider').then(function (rect) {
|
||||||
var value =
|
var value =
|
||||||
((event.detail.x - rect.left) / rect.width) * _this.getRange() + min;
|
((event.detail.x - rect.left) / rect.width) * _this.getRange() + min;
|
||||||
_this.updateValue(value, true);
|
if (_this.isRange(_this.value)) {
|
||||||
|
var _a = _this.value,
|
||||||
|
left = _a[0],
|
||||||
|
right = _a[1];
|
||||||
|
var middle = (left + right) / 2;
|
||||||
|
if (value <= middle) {
|
||||||
|
_this.updateValue([value, right], true);
|
||||||
|
} else {
|
||||||
|
_this.updateValue([left, value], true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_this.updateValue(value, true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
isRange: function (val) {
|
||||||
|
var range = this.data.range;
|
||||||
|
return range && Array.isArray(val);
|
||||||
|
},
|
||||||
|
handleOverlap: function (value) {
|
||||||
|
if (value[0] > value[1]) {
|
||||||
|
return value.slice(0).reverse();
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
},
|
||||||
updateValue: function (value, end, drag) {
|
updateValue: function (value, end, drag) {
|
||||||
value = this.format(value);
|
var _this = this;
|
||||||
var min = this.data.min;
|
if (this.isRange(value)) {
|
||||||
var width = ((value - min) * 100) / this.getRange() + '%';
|
value = this.handleOverlap(value).map(function (val) {
|
||||||
|
return _this.format(val);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
value = this.format(value);
|
||||||
|
}
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.setData({
|
this.setData({
|
||||||
barStyle:
|
barStyle:
|
||||||
'\n width: ' +
|
'\n width: ' +
|
||||||
width +
|
this.calcMainAxis() +
|
||||||
|
';\n left: ' +
|
||||||
|
(this.isRange(value) ? value[0] + '%' : 0) +
|
||||||
';\n ' +
|
';\n ' +
|
||||||
(drag ? 'transition: none;' : '') +
|
(drag ? 'transition: none;' : '') +
|
||||||
'\n ',
|
'\n ',
|
||||||
@ -98,12 +147,25 @@ component_1.VantComponent({
|
|||||||
this.setData({ value: value });
|
this.setData({ value: value });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
getScope: function () {
|
||||||
|
return Number(this.data.max) - Number(this.data.min);
|
||||||
|
},
|
||||||
getRange: function () {
|
getRange: function () {
|
||||||
var _a = this.data,
|
var _a = this.data,
|
||||||
max = _a.max,
|
max = _a.max,
|
||||||
min = _a.min;
|
min = _a.min;
|
||||||
return max - min;
|
return max - min;
|
||||||
},
|
},
|
||||||
|
// 计算选中条的长度百分比
|
||||||
|
calcMainAxis: function () {
|
||||||
|
var value = this.value;
|
||||||
|
var min = this.data.min;
|
||||||
|
var scope = this.getScope();
|
||||||
|
if (this.isRange(value)) {
|
||||||
|
return ((value[1] - value[0]) * 100) / scope + '%';
|
||||||
|
}
|
||||||
|
return ((value - Number(min)) * 100) / scope + '%';
|
||||||
|
},
|
||||||
format: function (value) {
|
format: function (value) {
|
||||||
var _a = this.data,
|
var _a = this.data,
|
||||||
max = _a.max,
|
max = _a.max,
|
||||||
|
|||||||
@ -11,6 +11,44 @@
|
|||||||
style="{{ barStyle }}; {{ style({ backgroundColor: activeColor }) }}"
|
style="{{ barStyle }}; {{ style({ backgroundColor: activeColor }) }}"
|
||||||
>
|
>
|
||||||
<view
|
<view
|
||||||
|
wx:if="{{ range }}"
|
||||||
|
class="{{ utils.bem('slider__button-wrapper-left') }}"
|
||||||
|
data-index="{{ 0 }}"
|
||||||
|
bind:touchstart="onTouchStart"
|
||||||
|
catch:touchmove="onTouchMove"
|
||||||
|
bind:touchend="onTouchEnd"
|
||||||
|
bind:touchcancel="onTouchEnd"
|
||||||
|
>
|
||||||
|
<slot
|
||||||
|
wx:if="{{ useButtonSlot }}"
|
||||||
|
name="left-button"
|
||||||
|
/>
|
||||||
|
<view
|
||||||
|
wx:else
|
||||||
|
class="{{ utils.bem('slider__button') }}"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
<view
|
||||||
|
wx:if="{{ range }}"
|
||||||
|
class="{{ utils.bem('slider__button-wrapper-right') }}"
|
||||||
|
data-index="{{ 1 }}"
|
||||||
|
bind:touchstart="onTouchStart"
|
||||||
|
catch:touchmove="onTouchMove"
|
||||||
|
bind:touchend="onTouchEnd"
|
||||||
|
bind:touchcancel="onTouchEnd"
|
||||||
|
>
|
||||||
|
<slot
|
||||||
|
wx:if="{{ useButtonSlot }}"
|
||||||
|
name="right-button"
|
||||||
|
/>
|
||||||
|
<view
|
||||||
|
wx:else
|
||||||
|
class="{{ utils.bem('slider__button') }}"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view
|
||||||
|
wx:if="{{ !range }}"
|
||||||
class="{{ utils.bem('slider__button-wrapper') }}"
|
class="{{ utils.bem('slider__button-wrapper') }}"
|
||||||
bind:touchstart="onTouchStart"
|
bind:touchstart="onTouchStart"
|
||||||
catch:touchmove="onTouchMove"
|
catch:touchmove="onTouchMove"
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
@import '../common/index.wxss';.van-slider{position:relative;height:2px;height:var(--slider-bar-height,2px);border-radius:999px;border-radius:var(--border-radius-max,999px);background-color:#ebedf0;background-color:var(--slider-inactive-background-color,#ebedf0)}.van-slider:before{position:absolute;right:0;left:0;content:"";top:-8px;top:-var(--padding-xs,8px);bottom:-8px;bottom:-var(--padding-xs,8px)}.van-slider__bar{position:relative;width:100%;height:100%;background-color:#1989fa;background-color:var(--slider-active-background-color,#1989fa);border-radius:inherit;transition:all .2s;transition:all var(--animation-duration-fast,.2s)}.van-slider__button{width:24px;width:var(--slider-button-width,24px);height:24px;height:var(--slider-button-height,24px);border-radius:50%;border-radius:var(--slider-button-border-radius,50%);box-shadow:0 1px 2px rgba(0,0,0,.5);box-shadow:var(--slider-button-box-shadow,0 1px 2px rgba(0,0,0,.5));background-color:#fff;background-color:var(--slider-button-background-color,#fff)}.van-slider__button-wrapper{position:absolute;top:50%;right:0;transform:translate3d(50%,-50%,0)}.van-slider--disabled{opacity:.5;opacity:var(--slider-disabled-opacity,.5)}
|
@import '../common/index.wxss';.van-slider{position:relative;height:2px;height:var(--slider-bar-height,2px);border-radius:999px;border-radius:var(--border-radius-max,999px);background-color:#ebedf0;background-color:var(--slider-inactive-background-color,#ebedf0)}.van-slider:before{position:absolute;right:0;left:0;content:"";top:-8px;top:-var(--padding-xs,8px);bottom:-8px;bottom:-var(--padding-xs,8px)}.van-slider__bar{position:relative;width:100%;height:100%;background-color:#1989fa;background-color:var(--slider-active-background-color,#1989fa);border-radius:inherit;transition:all .2s;transition:all var(--animation-duration-fast,.2s)}.van-slider__button{width:24px;width:var(--slider-button-width,24px);height:24px;height:var(--slider-button-height,24px);border-radius:50%;border-radius:var(--slider-button-border-radius,50%);box-shadow:0 1px 2px rgba(0,0,0,.5);box-shadow:var(--slider-button-box-shadow,0 1px 2px rgba(0,0,0,.5));background-color:#fff;background-color:var(--slider-button-background-color,#fff)}.van-slider__button-wrapper,.van-slider__button-wrapper-right{position:absolute;top:50%;right:0;transform:translate3d(50%,-50%,0)}.van-slider__button-wrapper-left{position:absolute;top:50%;left:0;transform:translate3d(-50%,-50%,0)}.van-slider--disabled{opacity:.5;opacity:var(--slider-disabled-opacity,.5)}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@vant/weapp",
|
"name": "@vant/weapp",
|
||||||
"version": "1.8.3",
|
"version": "1.8.4",
|
||||||
"author": "youzan",
|
"author": "youzan",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"miniprogram": "lib",
|
"miniprogram": "lib",
|
||||||
|
|||||||
@ -111,50 +111,51 @@ Page({
|
|||||||
|
|
||||||
### Props
|
### Props
|
||||||
|
|
||||||
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
| 参数 | 说明 | 类型 | 默认值 |
|
||||||
| --- | --- | --- | --- | --- |
|
| ---------------------- | ------------------------------------------------------------------------------------------------- | ------------------ | --- |
|
||||||
| name | 在表单内提交时的标识符 | _string_ | - | - |
|
| name | 在表单内提交时的标识符 | _string_ | - |
|
||||||
| label | 搜索框左侧文本 | _string_ | - | - |
|
| label | 搜索框左侧文本 | _string_ | - |
|
||||||
| shape | 形状,可选值为 `round` | _string_ | `square` | - |
|
| shape | 形状,可选值为 `round` | _string_ | `square` |
|
||||||
| value | 当前输入的值 | _string \| number_ | - | - |
|
| value | 当前输入的值 | _string \| number_ | - |
|
||||||
| background | 搜索框背景色 | _string_ | `#f2f2f2` | - |
|
| background | 搜索框背景色 | _string_ | `#f2f2f2` |
|
||||||
| show-action | 是否在搜索框右侧显示取消按钮 | _boolean_ | `false` | - |
|
| show-action | 是否在搜索框右侧显示取消按钮 | _boolean_ | `false` |
|
||||||
| action-text | 取消按钮文字 | _boolean_ | `取消` | 1.0.0 |
|
| action-text `v1.0.0` | 取消按钮文字 | _boolean_ | `取消` |
|
||||||
| focus | 获取焦点 | _boolean_ | `false` | - |
|
| focus | 获取焦点 | _boolean_ | `false` |
|
||||||
| error | 是否将输入内容标红 | _boolean_ | `false` | - |
|
| error | 是否将输入内容标红 | _boolean_ | `false` |
|
||||||
| disabled | 是否禁用输入框 | _boolean_ | `false` | - |
|
| disabled | 是否禁用输入框 | _boolean_ | `false` |
|
||||||
| readonly | 是否只读 | _boolean_ | `false` | - |
|
| readonly | 是否只读 | _boolean_ | `false` |
|
||||||
| clearable | 是否启用清除控件 | _boolean_ | `true` | - |
|
| clearable | 是否启用清除控件 | _boolean_ | `true` |
|
||||||
| maxlength | 最大输入长度,设置为 -1 的时候不限制最大长度 | _number_ | `-1` | - |
|
| clear-trigger `v1.8.4` | 显示清除图标的时机,`always` 表示输入框不为空时展示,<br>`focus` 表示输入框聚焦且不为空时展示 | _string_ | `focus` |
|
||||||
| use-action-slot | 是否使用 action slot | _boolean_ | `false` | - |
|
| clear-icon `v1.8.4` | 清除[图标名称](#/icon)或图片链接 | _string_ | `clear` |
|
||||||
| placeholder | 输入框为空时占位符 | _string_ | - | - |
|
| maxlength | 最大输入长度,设置为 -1 的时候不限制最大长度 | _number_ | `-1` |
|
||||||
| placeholder-style | 指定占位符的样式 | _string_ | - | - |
|
| use-action-slot | 是否使用 action slot | _boolean_ | `false` |
|
||||||
| input-align | 输入框内容对齐方式,可选值为 `center` `right` | _string_ | `left` | - |
|
| placeholder | 输入框为空时占位符 | _string_ | - |
|
||||||
| use-left-icon-slot | 是否使用输入框左侧图标 slot | _boolean_ | `false` | - |
|
| placeholder-style | 指定占位符的样式 | _string_ | - |
|
||||||
| use-right-icon-slot | 是否使用输入框右侧图标 slot | _boolean_ | `false` | - |
|
| input-align | 输入框内容对齐方式,可选值为 `center` `right` | _string_ | `left` |
|
||||||
| left-icon | 输入框左侧图标名称或图片链接,可选值见 Icon 组件(如果设置了 use-left-icon-slot,则该属性无效) | _string_ | `search` | - |
|
| use-left-icon-slot | 是否使用输入框左侧图标 slot | _boolean_ | `false` |
|
||||||
| right-icon | 输入框右侧图标名称或图片链接,可选值见 Icon 组件(如果设置了 use-right-icon-slot,则该属性无效) | _string_ | - | - |
|
| use-right-icon-slot | 是否使用输入框右侧图标 slot | _boolean_ | `false` |
|
||||||
| clear-icon `v1.8.4` | 清除[图标名称](#/icon)或图片链接 | _string_ | `clear` |
|
| left-icon | 输入框左侧图标名称或图片链接,可选值见 Icon 组件(如果设置了 use-left-icon-slot,则该属性无效) | _string_ | `search` |
|
||||||
|
| right-icon | 输入框右侧图标名称或图片链接,可选值见 Icon 组件(如果设置了 use-right-icon-slot,则该属性无效) | _string_ | - |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
| 事件名 | 说明 | 参数 |
|
| 事件名 | 说明 | 参数 |
|
||||||
| ----------- | ------------------ | ------------------------ |
|
| ---------------- | ------------------ | ------------------------ |
|
||||||
| bind:search | 确定搜索时触发 | event.detail: 当前输入值 |
|
| bind:search | 确定搜索时触发 | event.detail: 当前输入值 |
|
||||||
| bind:change | 输入内容变化时触发 | event.detail: 当前输入值 |
|
| bind:change | 输入内容变化时触发 | event.detail: 当前输入值 |
|
||||||
| bind:cancel | 取消搜索搜索时触发 | - |
|
| bind:cancel | 取消搜索搜索时触发 | - |
|
||||||
| bind:focus | 输入框聚焦时触发 | - |
|
| bind:focus | 输入框聚焦时触发 | - |
|
||||||
| bind:blur | 输入框失焦时触发 | - |
|
| bind:blur | 输入框失焦时触发 | - |
|
||||||
| bind:clear | 点击清空控件时触发 | - |
|
| bind:clear | 点击清空控件时触发 | - |
|
||||||
| bind:click-input | 点击搜索区域时触发 | - |
|
| bind:click-input | 点击搜索区域时触发 | - |
|
||||||
|
|
||||||
### Slot
|
### Slot
|
||||||
|
|
||||||
| 名称 | 说明 |
|
| 名称 | 说明 |
|
||||||
| --- | --- |
|
| ---------- | ------------------------------------------------------------------- |
|
||||||
| action | 自定义搜索框右侧按钮,需要在`use-action-slot`为 true 时才会显示 |
|
| action | 自定义搜索框右侧按钮,需要在`use-action-slot`为 true 时才会显示 |
|
||||||
| label | 自定义搜索框左侧文本 |
|
| label | 自定义搜索框左侧文本 |
|
||||||
| left-icon | 自定义输入框左侧图标,需要在`use-left-icon-slot`为 true 时才会显示 |
|
| left-icon | 自定义输入框左侧图标,需要在`use-left-icon-slot`为 true 时才会显示 |
|
||||||
| right-icon | 自定义输入框右侧图标,需要在`use-right-icon-slot`为 true 时才会显示 |
|
| right-icon | 自定义输入框右侧图标,需要在`use-right-icon-slot`为 true 时才会显示 |
|
||||||
|
|
||||||
### 外部样式类
|
### 外部样式类
|
||||||
|
|||||||
@ -44,6 +44,10 @@ VantComponent({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: true,
|
value: true,
|
||||||
},
|
},
|
||||||
|
clearTrigger: {
|
||||||
|
type: String,
|
||||||
|
value: 'focus',
|
||||||
|
},
|
||||||
clearIcon: {
|
clearIcon: {
|
||||||
type: String,
|
type: String,
|
||||||
value: 'clear',
|
value: 'clear',
|
||||||
|
|||||||
@ -21,6 +21,7 @@
|
|||||||
disabled="{{ disabled }}"
|
disabled="{{ disabled }}"
|
||||||
readonly="{{ readonly }}"
|
readonly="{{ readonly }}"
|
||||||
clearable="{{ clearable }}"
|
clearable="{{ clearable }}"
|
||||||
|
clear-trigger="{{ clearTrigger }}"
|
||||||
clear-icon="{{ clearIcon }}"
|
clear-icon="{{ clearIcon }}"
|
||||||
maxlength="{{ maxlength }}"
|
maxlength="{{ maxlength }}"
|
||||||
input-align="{{ inputAlign }}"
|
input-align="{{ inputAlign }}"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user