mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2026-06-04 09:38:10 +08:00
Compare commits
No commits in common. "2c020698082d7715496ba1438c00d1abc7fede9d" and "84113ffd17175ea804f74586b339410c70f2905e" have entirely different histories.
2c02069808
...
84113ffd17
@ -94,7 +94,7 @@ PS:关于 `van-area` Area 省市区选择组件,地区数据初始化可以
|
|||||||
|
|
||||||
## 基础库版本
|
## 基础库版本
|
||||||
|
|
||||||
Vant Weapp 最低支持到小程序基础库 2.6.5 版本
|
Vant Weapp 最低支持到小程序基础库 2.2.3 版本
|
||||||
|
|
||||||
## 链接
|
## 链接
|
||||||
|
|
||||||
|
|||||||
@ -6,15 +6,6 @@
|
|||||||
/>
|
/>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
|
|
||||||
<demo-block title="双滑块">
|
|
||||||
<van-slider
|
|
||||||
range
|
|
||||||
value="{{ [20, 60 ] }}"
|
|
||||||
custom-class="slider"
|
|
||||||
bind:change="onChange"
|
|
||||||
/>
|
|
||||||
</demo-block>
|
|
||||||
|
|
||||||
<demo-block title="指定选择范围">
|
<demo-block title="指定选择范围">
|
||||||
<van-slider
|
<van-slider
|
||||||
custom-class="slider"
|
custom-class="slider"
|
||||||
|
|||||||
@ -41,7 +41,7 @@
|
|||||||
},
|
},
|
||||||
"compileType": "miniprogram",
|
"compileType": "miniprogram",
|
||||||
"cloudfunctionRoot": "functions/",
|
"cloudfunctionRoot": "functions/",
|
||||||
"libVersion": "2.6.5",
|
"libVersion": "2.3.2",
|
||||||
"appid": "wx1c01b35002d3ba14",
|
"appid": "wx1c01b35002d3ba14",
|
||||||
"projectname": "vant-weapp",
|
"projectname": "vant-weapp",
|
||||||
"debugOptions": {
|
"debugOptions": {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { getCurrentPage, isDef } from '../common/utils';
|
import { getCurrentPage } from '../common/utils';
|
||||||
|
|
||||||
type IPageScrollOption = WechatMiniprogram.Page.IPageScrollOption;
|
type IPageScrollOption = WechatMiniprogram.Page.IPageScrollOption;
|
||||||
type Scroller = (
|
type Scroller = (
|
||||||
@ -38,9 +38,7 @@ export const pageScrollMixin = (scroller: Scroller) =>
|
|||||||
|
|
||||||
detached() {
|
detached() {
|
||||||
const page = getCurrentPage<{ vanPageScroller: Scroller[] }>();
|
const page = getCurrentPage<{ vanPageScroller: Scroller[] }>();
|
||||||
if (!isDef(page)) {
|
page.vanPageScroller =
|
||||||
page.vanPageScroller =
|
page.vanPageScroller?.filter((item) => item !== scroller) || [];
|
||||||
page.vanPageScroller?.filter((item) => item !== scroller) || [];
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -85,18 +85,16 @@ Page({
|
|||||||
|
|
||||||
### Props
|
### Props
|
||||||
|
|
||||||
| 参数 | 说明 | 类型 | 默认值 |
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
||||||
| --------------- | ---------------------------------------- | -------------------- | --------- |
|
| -------------- | -------------------------------- | ------------------ | --------- | ---- |
|
||||||
| value | 当前进度百分比,在双滑块模式下为数组格式 | _number \| number[]_ | `0` |
|
| value | 当前进度百分比,取值范围为 0-100 | _number_ | `0` | - |
|
||||||
| disabled | 是否禁用滑块 | _boolean_ | `false` |
|
| disabled | 是否禁用滑块 | _boolean_ | `false` | - |
|
||||||
| max | 最大值 | _number_ | `100` |
|
| max | 最大值 | _number_ | `100` | - |
|
||||||
| min | 最小值 | _number_ | `0` |
|
| min | 最小值 | _number_ | `0` | - |
|
||||||
| step | 步长 | _number_ | `1` |
|
| step | 步长 | _number_ | `1` | - |
|
||||||
| bar-height | 进度条高度,默认单位为 `px` | _string \| number_ | `2px` |
|
| bar-height | 进度条高度,默认单位为 `px` | _string \| number_ | `2px` | - |
|
||||||
| active-color | 进度条激活态颜色 | _string_ | `#1989fa` |
|
| active-color | 进度条激活态颜色 | _string_ | `#1989fa` | - |
|
||||||
| inactive-color | 进度条默认颜色 | _string_ | `#e5e5e5` |
|
| inactive-color | 进度条默认颜色 | _string_ | `#e5e5e5` | - |
|
||||||
| use-slot-button | 是否使用钮插槽 | _boolean_ | `false` |
|
|
||||||
| range `v1.8.4` | 是否开启双滑块模式 | _boolean_ | `false` |
|
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
@ -112,11 +110,3 @@ Page({
|
|||||||
| 类名 | 说明 |
|
| 类名 | 说明 |
|
||||||
| ------------ | ------------ |
|
| ------------ | ------------ |
|
||||||
| custom-class | 根节点样式类 |
|
| custom-class | 根节点样式类 |
|
||||||
|
|
||||||
### Slots
|
|
||||||
|
|
||||||
| 名称 | 说明 | 参数 |
|
|
||||||
| --------------------- | ----------------------------------- | ------------------- |
|
|
||||||
| button | 自定义滑块按钮 | _{ value: number }_ |
|
|
||||||
| left-button `v1.8.4` | 自定义左侧滑块按钮(双滑块模式下) | _{ value: number }_ |
|
|
||||||
| right-button `v1.8.4` | 自定义右侧滑块按钮 (双滑块模式下) | _{ value: number }_ |
|
|
||||||
|
|||||||
@ -34,20 +34,12 @@
|
|||||||
.theme(box-shadow, '@slider-button-box-shadow');
|
.theme(box-shadow, '@slider-button-box-shadow');
|
||||||
.theme(background-color, '@slider-button-background-color');
|
.theme(background-color, '@slider-button-background-color');
|
||||||
|
|
||||||
&-wrapper,
|
&-wrapper {
|
||||||
&-wrapper-right {
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
right: 0;
|
right: 0;
|
||||||
transform: translate3d(50%, -50%, 0);
|
transform: translate3d(50%, -50%, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
&-wrapper-left {
|
|
||||||
position: absolute;
|
|
||||||
top: 50%;
|
|
||||||
left: 0;
|
|
||||||
transform: translate3d(-50%, -50%, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&--disabled {
|
&--disabled {
|
||||||
|
|||||||
@ -3,13 +3,10 @@ import { touch } from '../mixins/touch';
|
|||||||
import { canIUseModel } from '../common/version';
|
import { canIUseModel } from '../common/version';
|
||||||
import { getRect } from '../common/utils';
|
import { getRect } from '../common/utils';
|
||||||
|
|
||||||
type SliderValue = number | [number, number];
|
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
mixins: [touch],
|
mixins: [touch],
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
range: Boolean,
|
|
||||||
disabled: Boolean,
|
disabled: Boolean,
|
||||||
useButtonSlot: Boolean,
|
useButtonSlot: Boolean,
|
||||||
activeColor: String,
|
activeColor: String,
|
||||||
@ -29,7 +26,6 @@ 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);
|
||||||
@ -47,23 +43,8 @@ VantComponent({
|
|||||||
onTouchStart(event: WechatMiniprogram.TouchEvent) {
|
onTouchStart(event: WechatMiniprogram.TouchEvent) {
|
||||||
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)) as [
|
|
||||||
number,
|
|
||||||
number
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
this.startValue = this.format(this.newValue);
|
|
||||||
}
|
|
||||||
this.dragStatus = 'start';
|
this.dragStatus = 'start';
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -79,13 +60,7 @@ VantComponent({
|
|||||||
|
|
||||||
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 as [number, number])[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);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -107,50 +82,20 @@ 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: unknown): val is [number, number] {
|
updateValue(value: number, end?: boolean, drag?: boolean) {
|
||||||
const { range } = this.data;
|
value = this.format(value);
|
||||||
return range && Array.isArray(val);
|
const { min } = this.data;
|
||||||
},
|
const width = `${((value - min) * 100) / this.getRange()}%`;
|
||||||
|
|
||||||
handleOverlap(value: [number, number]) {
|
|
||||||
if (value[0] > value[1]) {
|
|
||||||
return value.slice(0).reverse();
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
},
|
|
||||||
|
|
||||||
updateValue(value: SliderValue, end?: boolean, drag?: boolean) {
|
|
||||||
if (this.isRange(value)) {
|
|
||||||
value = this.handleOverlap(value).map((val) => this.format(val)) as [
|
|
||||||
number,
|
|
||||||
number
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
value = this.format(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
|
||||||
this.setData({
|
this.setData({
|
||||||
barStyle: `
|
barStyle: `
|
||||||
width: ${this.calcMainAxis()};
|
width: ${width};
|
||||||
left: ${this.isRange(value) ? `${value[0]}%` : 0};
|
|
||||||
${drag ? 'transition: none;' : ''}
|
${drag ? 'transition: none;' : ''}
|
||||||
`,
|
`,
|
||||||
});
|
});
|
||||||
@ -168,26 +113,11 @@ VantComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
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: number) {
|
format(value: number) {
|
||||||
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;
|
||||||
|
|||||||
@ -11,44 +11,6 @@
|
|||||||
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"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user