stellar-ui-v2 1.35.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/common/css/common.scss +61 -0
- package/components/ste-animate/README.md +117 -0
- package/components/ste-animate/animate.scss +247 -0
- package/components/ste-animate/ste-animate.vue +200 -0
- package/components/ste-badge/README.md +171 -0
- package/components/ste-badge/ste-badge.vue +238 -0
- package/components/ste-barcode/README.md +36 -0
- package/components/ste-barcode/encode2.js +317 -0
- package/components/ste-barcode/ste-barcode.vue +213 -0
- package/components/ste-button/README.md +129 -0
- package/components/ste-button/ste-button.vue +345 -0
- package/components/ste-calendar/README.md +304 -0
- package/components/ste-calendar/self-date.js +119 -0
- package/components/ste-calendar/ste-calendar.vue +578 -0
- package/components/ste-checkbox/README.md +297 -0
- package/components/ste-checkbox/ste-checkbox.vue +305 -0
- package/components/ste-checkbox-group/ste-checkbox-group.vue +133 -0
- package/components/ste-code-input/README.md +67 -0
- package/components/ste-code-input/ste-code-input.vue +302 -0
- package/components/ste-date-picker/README.md +135 -0
- package/components/ste-date-picker/ste-date-picker.vue +407 -0
- package/components/ste-drag/README.md +103 -0
- package/components/ste-drag/ste-drag.vue +203 -0
- package/components/ste-dropdown-menu/README.md +358 -0
- package/components/ste-dropdown-menu/ste-dropdown-menu.vue +405 -0
- package/components/ste-dropdown-menu-item/ste-dropdown-menu-item.vue +176 -0
- package/components/ste-icon/README.md +90 -0
- package/components/ste-icon/iconfont.css +8 -0
- package/components/ste-icon/ste-icon.vue +147 -0
- package/components/ste-image/README.md +154 -0
- package/components/ste-image/ste-image.vue +218 -0
- package/components/ste-index-item/ste-index-item.vue +96 -0
- package/components/ste-index-list/README.md +153 -0
- package/components/ste-index-list/ste-index-list.vue +128 -0
- package/components/ste-input/README.md +146 -0
- package/components/ste-input/ste-input.vue +480 -0
- package/components/ste-loading/README.md +81 -0
- package/components/ste-loading/ste-loading.vue +166 -0
- package/components/ste-media-preview/README.md +243 -0
- package/components/ste-media-preview/TouchScaleing.js +102 -0
- package/components/ste-media-preview/ste-media-preview.vue +267 -0
- package/components/ste-message-box/README.md +217 -0
- package/components/ste-message-box/ste-message-box.js +72 -0
- package/components/ste-message-box/ste-message-box.vue +380 -0
- package/components/ste-notice-bar/README.md +129 -0
- package/components/ste-notice-bar/ste-notice-bar.vue +331 -0
- package/components/ste-number-keyboard/README.md +246 -0
- package/components/ste-number-keyboard/keyboard.vue +140 -0
- package/components/ste-number-keyboard/ste-number-keyboard.vue +240 -0
- package/components/ste-picker/ste-picker.vue +258 -0
- package/components/ste-popup/README.md +148 -0
- package/components/ste-popup/ste-popup.vue +337 -0
- package/components/ste-price/README.md +129 -0
- package/components/ste-price/ste-price.vue +258 -0
- package/components/ste-progress/README.md +87 -0
- package/components/ste-progress/ste-progress.vue +200 -0
- package/components/ste-qrcode/README.md +50 -0
- package/components/ste-qrcode/ste-qrcode.vue +164 -0
- package/components/ste-qrcode/uqrcode.js +34 -0
- package/components/ste-radio/README.md +286 -0
- package/components/ste-radio/ste-radio.vue +293 -0
- package/components/ste-radio-group/ste-radio-group.vue +128 -0
- package/components/ste-rate/README.md +115 -0
- package/components/ste-rate/ste-rate.vue +202 -0
- package/components/ste-read-more/README.md +111 -0
- package/components/ste-read-more/ste-read-more.vue +133 -0
- package/components/ste-rich-text/README.md +31 -0
- package/components/ste-rich-text/ste-rich-text.vue +70 -0
- package/components/ste-scroll-to/README.md +68 -0
- package/components/ste-scroll-to/mixin.js +173 -0
- package/components/ste-scroll-to/ste-scroll-to.vue +45 -0
- package/components/ste-scroll-to-item/ste-scroll-to-item.vue +25 -0
- package/components/ste-search/README.md +262 -0
- package/components/ste-search/ste-search.vue +547 -0
- package/components/ste-select/README.md +434 -0
- package/components/ste-select/datapager.vue +62 -0
- package/components/ste-select/datetime.vue +106 -0
- package/components/ste-select/defaultDate.js +142 -0
- package/components/ste-select/ste-select.vue +843 -0
- package/components/ste-signature/README.md +105 -0
- package/components/ste-signature/ste-signature.vue +220 -0
- package/components/ste-slider/README.md +165 -0
- package/components/ste-slider/ste-slider.vue +544 -0
- package/components/ste-step/ste-step.vue +264 -0
- package/components/ste-stepper/README.md +170 -0
- package/components/ste-stepper/ste-stepper.vue +373 -0
- package/components/ste-steps/README.md +132 -0
- package/components/ste-steps/ste-steps.vue +65 -0
- package/components/ste-sticky/README.md +52 -0
- package/components/ste-sticky/ste-sticky.vue +127 -0
- package/components/ste-swipe-action/README.md +197 -0
- package/components/ste-swipe-action/ste-swipe-action.vue +303 -0
- package/components/ste-swipe-action-group/ste-swipe-action-group.vue +104 -0
- package/components/ste-swiper/README.md +173 -0
- package/components/ste-swiper/ste-swiper.vue +462 -0
- package/components/ste-swiper-item/ste-swiper-item.vue +41 -0
- package/components/ste-switch/README.md +110 -0
- package/components/ste-switch/ste-switch.vue +144 -0
- package/components/ste-tab/ste-tab.vue +87 -0
- package/components/ste-table/README.md +785 -0
- package/components/ste-table/common.js +8 -0
- package/components/ste-table/ste-table.vue +666 -0
- package/components/ste-table/utils.js +20 -0
- package/components/ste-table-column/checkbox-icon.vue +65 -0
- package/components/ste-table-column/common.scss +65 -0
- package/components/ste-table-column/radio-icon.vue +110 -0
- package/components/ste-table-column/ste-table-column.vue +255 -0
- package/components/ste-table-column/sub-table.vue +116 -0
- package/components/ste-table-column/table-popover.vue +204 -0
- package/components/ste-table-column/var.scss +1 -0
- package/components/ste-tabs/README.md +475 -0
- package/components/ste-tabs/props.js +212 -0
- package/components/ste-tabs/ste-tabs.vue +758 -0
- package/components/ste-text/README.md +66 -0
- package/components/ste-text/ste-text.vue +72 -0
- package/components/ste-toast/README.md +243 -0
- package/components/ste-toast/ste-toast.js +69 -0
- package/components/ste-toast/ste-toast.vue +231 -0
- package/components/ste-touch-swipe/README.md +104 -0
- package/components/ste-touch-swipe/TouchEvent.js +72 -0
- package/components/ste-touch-swipe/ste-touch-swipe.vue +327 -0
- package/components/ste-touch-swipe-item/ste-touch-swipe-item.vue +33 -0
- package/components/ste-tour/README.md +194 -0
- package/components/ste-tour/ste-tour.vue +355 -0
- package/components/ste-tree/README.md +240 -0
- package/components/ste-tree/ste-tree.vue +350 -0
- package/components/ste-upload/README.md +276 -0
- package/components/ste-upload/ReadFile.js +229 -0
- package/components/ste-upload/ste-upload.vue +526 -0
- package/components/ste-video/README.md +60 -0
- package/components/ste-video/props.js +149 -0
- package/components/ste-video/ste-video.vue +647 -0
- package/config/color.js +22 -0
- package/index.js +2 -0
- package/package.json +19 -0
- package/utils/Color.js +66 -0
- package/utils/System.js +110 -0
- package/utils/dayjs.min.js +1 -0
- package/utils/mixin.js +67 -0
- package/utils/store.js +7 -0
- package/utils/utils.js +604 -0
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="ste-slider-root" :class="cmpRootClass" :style="[cmpRootCssVar]" @click="handleClick">
|
|
3
|
+
<view class="inactive-box" :style="[cmpInactiveStyle]"></view>
|
|
4
|
+
<view class="active-box line" :style="[cmpActiveStyle]"></view>
|
|
5
|
+
|
|
6
|
+
<view
|
|
7
|
+
class="slider-bar-box"
|
|
8
|
+
:class="{ 'range-min': realPercentage == 0, 'range-max': realPercentage == 100 }"
|
|
9
|
+
@touchstart.stop="onTouchStart"
|
|
10
|
+
@touchmove.stop="onTouchMove"
|
|
11
|
+
@touchend.stop="onTouchEnd"
|
|
12
|
+
@touchcancel.stop="onTouchEnd"
|
|
13
|
+
@mousedown="onDown"
|
|
14
|
+
:style="{
|
|
15
|
+
left: vertical ? '50%' : `${realPercentage}%`,
|
|
16
|
+
top: vertical ? `${realPercentage}%` : '50%',
|
|
17
|
+
}"
|
|
18
|
+
>
|
|
19
|
+
<slot :name="range ? 'leftButton' : 'button'">
|
|
20
|
+
<view class="slider-bar"></view>
|
|
21
|
+
</slot>
|
|
22
|
+
</view>
|
|
23
|
+
|
|
24
|
+
<view
|
|
25
|
+
v-if="range"
|
|
26
|
+
class="slider-bar-box range"
|
|
27
|
+
:class="{ 'range-min': realPercentage2 == 0, 'range-max': realPercentage2 == 100 }"
|
|
28
|
+
@touchstart="onTouchStart($event, true)"
|
|
29
|
+
@touchmove.stop="onTouchMove($event, true)"
|
|
30
|
+
@touchend="onTouchEnd($event, true)"
|
|
31
|
+
@touchcancel="onTouchEnd($event, true)"
|
|
32
|
+
@mousedown="onDown($event, true)"
|
|
33
|
+
:style="{
|
|
34
|
+
left: vertical ? '50%' : `${realPercentage2}%`,
|
|
35
|
+
top: vertical ? `${realPercentage2}%` : '50%',
|
|
36
|
+
zIndex: isSecondSlider ? 10 : 8,
|
|
37
|
+
}"
|
|
38
|
+
>
|
|
39
|
+
<slot name="rightButton">
|
|
40
|
+
<view class="slider-bar"></view>
|
|
41
|
+
</slot>
|
|
42
|
+
</view>
|
|
43
|
+
<template v-if="showStops">
|
|
44
|
+
<template v-for="(e, i) in markList">
|
|
45
|
+
<view :key="i" class="mark-box" :style="{ left: e.left, top: e.top }">
|
|
46
|
+
<view class="dot" />
|
|
47
|
+
<view class="marks-label" :style="e.style">{{ e.label }}</view>
|
|
48
|
+
</view>
|
|
49
|
+
</template>
|
|
50
|
+
</template>
|
|
51
|
+
</view>
|
|
52
|
+
</template>
|
|
53
|
+
|
|
54
|
+
<script>
|
|
55
|
+
import utils from '../../utils/utils.js';
|
|
56
|
+
import useColor from '../../config/color.js';
|
|
57
|
+
let color = useColor();
|
|
58
|
+
/**
|
|
59
|
+
* ste-slider 滑块
|
|
60
|
+
* @description 滑块组件
|
|
61
|
+
* @tutorial https://stellar-ui.intecloud.com.cn/pc/index/index?name=ste-slider
|
|
62
|
+
* @property {Number|String|Array} value 当前进度百分比,在双滑块模式下为数组格式(数组的值都是从小到大)
|
|
63
|
+
* @property {Number|String} min 最小值
|
|
64
|
+
* @property {Number|String} max 最大值
|
|
65
|
+
* @property {Number|String} step 步长
|
|
66
|
+
* @property {Number|String} barHeight 进度条高度,默认单位为 rpx
|
|
67
|
+
* @property {Number|String} buttonSize 滑块按钮大小,默认单位为 rpx
|
|
68
|
+
* @property {String} activeColor 进度条激活态颜色
|
|
69
|
+
* @property {String} inactiveColor 进度条非激活态颜色
|
|
70
|
+
* @property {Boolean} range 是否为范围选择
|
|
71
|
+
* @property {Boolean} vertical 是否竖向模式
|
|
72
|
+
* @property {Boolean} disabled 是否禁用滑块
|
|
73
|
+
* @property {Boolean} readonly 是否为只读状态,只读状态下无法修改滑块的值
|
|
74
|
+
* @property {Object} marks 标记, key 的类型必须为 number 且取值在闭区间 [min, max] 内,每个标记可以单独设置样式
|
|
75
|
+
*/
|
|
76
|
+
export default {
|
|
77
|
+
group: '表单组件',
|
|
78
|
+
title: 'Slider 滑块',
|
|
79
|
+
name: 'ste-slider',
|
|
80
|
+
options: {
|
|
81
|
+
virtualHost: true,
|
|
82
|
+
},
|
|
83
|
+
props: {
|
|
84
|
+
value: {
|
|
85
|
+
type: [Number, String, Array, null],
|
|
86
|
+
default: 0,
|
|
87
|
+
},
|
|
88
|
+
min: {
|
|
89
|
+
type: [Number, String, null],
|
|
90
|
+
default: 0,
|
|
91
|
+
},
|
|
92
|
+
max: {
|
|
93
|
+
type: [Number, String, null],
|
|
94
|
+
default: 100,
|
|
95
|
+
},
|
|
96
|
+
step: {
|
|
97
|
+
type: [Number, String, null],
|
|
98
|
+
default: 1,
|
|
99
|
+
},
|
|
100
|
+
barHeight: {
|
|
101
|
+
type: [String, Number, null],
|
|
102
|
+
default: 8,
|
|
103
|
+
},
|
|
104
|
+
buttonSize: {
|
|
105
|
+
type: [String, Number, null],
|
|
106
|
+
default: 40,
|
|
107
|
+
},
|
|
108
|
+
activeColor: {
|
|
109
|
+
type: [String, null],
|
|
110
|
+
default: '',
|
|
111
|
+
},
|
|
112
|
+
inactiveColor: {
|
|
113
|
+
type: [String, null],
|
|
114
|
+
default: '#eeeeee',
|
|
115
|
+
},
|
|
116
|
+
range: {
|
|
117
|
+
type: [Boolean, null],
|
|
118
|
+
default: false,
|
|
119
|
+
},
|
|
120
|
+
vertical: {
|
|
121
|
+
type: [Boolean, null],
|
|
122
|
+
default: false,
|
|
123
|
+
},
|
|
124
|
+
disabled: {
|
|
125
|
+
type: [Boolean, null],
|
|
126
|
+
default: false,
|
|
127
|
+
},
|
|
128
|
+
readonly: {
|
|
129
|
+
type: [Boolean, null],
|
|
130
|
+
default: false,
|
|
131
|
+
},
|
|
132
|
+
showStops: {
|
|
133
|
+
type: [Boolean, null],
|
|
134
|
+
default: false,
|
|
135
|
+
},
|
|
136
|
+
marks: {
|
|
137
|
+
type: [Object, null],
|
|
138
|
+
default: () => {},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
data() {
|
|
142
|
+
return {
|
|
143
|
+
realPercentage: 0,
|
|
144
|
+
realPercentage2: 0, // 范围模式下该值为第二个滑块的值
|
|
145
|
+
sliderRect: {
|
|
146
|
+
left: 0,
|
|
147
|
+
width: 0,
|
|
148
|
+
height: 0,
|
|
149
|
+
bottom: 0,
|
|
150
|
+
},
|
|
151
|
+
isDrag: false,
|
|
152
|
+
startPosition: 0,
|
|
153
|
+
startPercentage: 0,
|
|
154
|
+
markList: [],
|
|
155
|
+
hasMarks: false,
|
|
156
|
+
isMouseDown: false,
|
|
157
|
+
isSecondSlider: false,
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
created() {},
|
|
161
|
+
mounted() {
|
|
162
|
+
this.handleWindowResize();
|
|
163
|
+
uni.onWindowResize(this.handleWindowResize);
|
|
164
|
+
this.calculateStepMarks();
|
|
165
|
+
},
|
|
166
|
+
beforeDestroy() {
|
|
167
|
+
uni.offWindowResize(this.handleWindowResize);
|
|
168
|
+
},
|
|
169
|
+
computed: {
|
|
170
|
+
cmpRootClass() {
|
|
171
|
+
let classStr = '';
|
|
172
|
+
if (this.isDrag) {
|
|
173
|
+
classStr += 'ste-slider-drag ';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (this.range) {
|
|
177
|
+
classStr += 'ste-slider-range ';
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (this.disabled) {
|
|
181
|
+
classStr += 'ste-slider-disabled ';
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (this.vertical) {
|
|
185
|
+
classStr += 'ste-slider-vertical ';
|
|
186
|
+
} else {
|
|
187
|
+
classStr += 'ste-slider-horizontal ';
|
|
188
|
+
}
|
|
189
|
+
return classStr;
|
|
190
|
+
},
|
|
191
|
+
cmpRootCssVar() {
|
|
192
|
+
const style = {
|
|
193
|
+
'--progress-height': utils.addUnit(this.barHeight),
|
|
194
|
+
'--bar-size': utils.addUnit(this.buttonSize),
|
|
195
|
+
'--active-color': this.activeColor ? this.activeColor : color.getColor().steThemeColor,
|
|
196
|
+
};
|
|
197
|
+
return style;
|
|
198
|
+
},
|
|
199
|
+
cmpInactiveStyle() {
|
|
200
|
+
let style = {};
|
|
201
|
+
if (!this.disabled) {
|
|
202
|
+
const bg = utils.bg2style(this.inactiveColor);
|
|
203
|
+
style = { ...style, ...bg };
|
|
204
|
+
}
|
|
205
|
+
return style;
|
|
206
|
+
},
|
|
207
|
+
cmpActiveStyle() {
|
|
208
|
+
let style = {};
|
|
209
|
+
if (!this.disabled) {
|
|
210
|
+
const bg = utils.bg2style(this.activeColor ? this.activeColor : color.getColor().steThemeColor);
|
|
211
|
+
style = { ...style, ...bg };
|
|
212
|
+
}
|
|
213
|
+
if (this.vertical) {
|
|
214
|
+
if (this.range) {
|
|
215
|
+
style.top = this.realPercentage + '%';
|
|
216
|
+
style.height = this.realPercentage2 - this.realPercentage + '%';
|
|
217
|
+
} else {
|
|
218
|
+
style.height = this.realPercentage + '%';
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
221
|
+
if (this.range) {
|
|
222
|
+
style.left = this.realPercentage + '%';
|
|
223
|
+
style.width = this.realPercentage2 - this.realPercentage + '%';
|
|
224
|
+
} else {
|
|
225
|
+
style.width = this.realPercentage + '%';
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return style;
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
watch: {
|
|
232
|
+
value: {
|
|
233
|
+
handler(val) {
|
|
234
|
+
if (Array.isArray(val)) {
|
|
235
|
+
this.realPercentage = this.getRealValue(val[0]);
|
|
236
|
+
this.realPercentage2 = this.getRealValue(val[1]);
|
|
237
|
+
} else {
|
|
238
|
+
this.realPercentage = this.getRealValue(val);
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
immediate: true,
|
|
242
|
+
},
|
|
243
|
+
marks: {
|
|
244
|
+
handler(val) {
|
|
245
|
+
this.hasMarks = Object.keys(val || {}).length > 0;
|
|
246
|
+
},
|
|
247
|
+
immediate: true,
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
methods: {
|
|
251
|
+
handleWindowResize() {
|
|
252
|
+
utils.querySelector('.ste-slider-root', this).then((rect) => {
|
|
253
|
+
this.sliderRect = rect;
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
// #ifdef WEB
|
|
257
|
+
// 适配web端没有touch事件
|
|
258
|
+
onDown(e, isSecond) {
|
|
259
|
+
this.isMouseDown = true;
|
|
260
|
+
this.onTouchStart({ touches: [{ clientX: e.clientX, clientY: e.clientY }] }, isSecond);
|
|
261
|
+
window.addEventListener('mousemove', this.onTouchMove);
|
|
262
|
+
window.addEventListener('mouseup', this.onTouchEnd);
|
|
263
|
+
},
|
|
264
|
+
removeListenner() {
|
|
265
|
+
window.removeEventListener('mousemove', this.onTouchMove);
|
|
266
|
+
window.removeEventListener('mouseup', this.onTouchEnd);
|
|
267
|
+
},
|
|
268
|
+
// onMouseMove(e, isSecond) {
|
|
269
|
+
// this.ont
|
|
270
|
+
// }
|
|
271
|
+
// #endif
|
|
272
|
+
handleClick(e) {
|
|
273
|
+
if (this.readonly || this.disabled || this.range) return;
|
|
274
|
+
let offsetValue;
|
|
275
|
+
if (this.vertical) {
|
|
276
|
+
let clientY = e.detail.y || e.detail.clientY;
|
|
277
|
+
offsetValue = ((clientY - this.sliderRect.top) / this.sliderRect.height) * 100;
|
|
278
|
+
} else {
|
|
279
|
+
let clientX = e.detail.x || e.detail.clientX;
|
|
280
|
+
offsetValue = ((clientX - this.sliderRect.left) / this.sliderRect.width) * 100;
|
|
281
|
+
}
|
|
282
|
+
this.updateWidth(offsetValue, false);
|
|
283
|
+
this.$emit('change', this.range ? [this.realPercentage, this.realPercentage2] : this.realPercentage);
|
|
284
|
+
},
|
|
285
|
+
onTouchStart(e, isSecond) {
|
|
286
|
+
this.isSecondSlider = !!isSecond;
|
|
287
|
+
this.startPosition = this.getPosition(e);
|
|
288
|
+
this.startPercentage = isSecond ? this.realPercentage2 : this.realPercentage;
|
|
289
|
+
this.$emit('dragStart', e);
|
|
290
|
+
},
|
|
291
|
+
onTouchMove(e) {
|
|
292
|
+
if (this.readonly || this.disabled) return;
|
|
293
|
+
let touches = this.getPosition(e);
|
|
294
|
+
let distance = this.vertical
|
|
295
|
+
? touches.clientY - this.startPosition.clientY
|
|
296
|
+
: touches.clientX - this.startPosition.clientX;
|
|
297
|
+
let containerLength = this.vertical ? this.sliderRect.height : this.sliderRect.width;
|
|
298
|
+
let offsetValue = (distance / containerLength) * 100;
|
|
299
|
+
this.updateWidth(offsetValue, true);
|
|
300
|
+
},
|
|
301
|
+
onTouchEnd(e) {
|
|
302
|
+
this.isDrag = false;
|
|
303
|
+
// this.isSecondSlider = false;
|
|
304
|
+
this.$emit('dragEnd', e);
|
|
305
|
+
this.$emit('change', this.range ? [this.realPercentage, this.realPercentage2] : this.realPercentage);
|
|
306
|
+
this.removeListenner && this.removeListenner();
|
|
307
|
+
},
|
|
308
|
+
// 为了保持web端和移动端事件参数数据结构一致
|
|
309
|
+
getPosition(e) {
|
|
310
|
+
if (e.touches) {
|
|
311
|
+
return e.touches[0];
|
|
312
|
+
} else {
|
|
313
|
+
return { clientX: e.clientX, clientY: e.clientY };
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
updateWidth(value, drag) {
|
|
317
|
+
let realValue;
|
|
318
|
+
this.isDrag = drag;
|
|
319
|
+
if (drag) {
|
|
320
|
+
realValue = this.startPercentage + value;
|
|
321
|
+
} else {
|
|
322
|
+
realValue = value;
|
|
323
|
+
}
|
|
324
|
+
const changeValue = this.calculateValue(realValue);
|
|
325
|
+
if (this.isSecondSlider) {
|
|
326
|
+
this.realPercentage2 = changeValue;
|
|
327
|
+
} else {
|
|
328
|
+
this.realPercentage = changeValue;
|
|
329
|
+
}
|
|
330
|
+
this.$emit('input', this.range ? [this.realPercentage, this.realPercentage2] : this.realPercentage);
|
|
331
|
+
},
|
|
332
|
+
// 根据步长和最大最小值来计算每次的滑动
|
|
333
|
+
calculateValue(value) {
|
|
334
|
+
let step = this.hasMarks ? 1 : this.step;
|
|
335
|
+
let min = this.min;
|
|
336
|
+
let max = this.max;
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
*当范围模式下时,两个滑块不允许交替,
|
|
340
|
+
*第一个滑块的最大值就是第二个滑块的当前值,
|
|
341
|
+
* 第二个滑块的最小是就是第一个滑块的当前值
|
|
342
|
+
*/
|
|
343
|
+
if (this.range) {
|
|
344
|
+
if (this.isSecondSlider) {
|
|
345
|
+
min = this.realPercentage;
|
|
346
|
+
} else {
|
|
347
|
+
max = this.realPercentage2;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// 计算出当前值相对于最小值的偏移量
|
|
352
|
+
const offset = value - min;
|
|
353
|
+
// 根据步长计算出应该是哪个步长点
|
|
354
|
+
const targetValue = Math.round(offset / step) * step + min;
|
|
355
|
+
// 确保计算出的值不会超过最大值和低于最小值
|
|
356
|
+
return this.getRealValue(targetValue, max, min);
|
|
357
|
+
},
|
|
358
|
+
// 根据传入的最大最小值来计算传入的值是否在范围内,并给出范围内的值
|
|
359
|
+
getRealValue(value = 0, max = this.max, min = this.min) {
|
|
360
|
+
return Math.max(Math.min(value, max), min);
|
|
361
|
+
},
|
|
362
|
+
calculateStepMarks() {
|
|
363
|
+
if (!this.showStops) return;
|
|
364
|
+
this.markList = [];
|
|
365
|
+
let marksKeys = Object.keys(this.marks || {});
|
|
366
|
+
if (marksKeys.length > 0) {
|
|
367
|
+
marksKeys.forEach((e) => {
|
|
368
|
+
this.markList.push({
|
|
369
|
+
left: this.vertical ? '0' : `${e}%`,
|
|
370
|
+
top: this.vertical ? `${e}%` : '0',
|
|
371
|
+
style: this.marks[e].style,
|
|
372
|
+
label: typeof this.marks[e] === 'string' ? this.marks[e] : this.marks[e].label,
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
} else {
|
|
376
|
+
for (let i = this.min; i <= this.max; i += this.step) {
|
|
377
|
+
// 根据自定义的 marks 对象判断是否需要显示该标记点
|
|
378
|
+
if (i === this.min || i === this.max) {
|
|
379
|
+
continue; // 跳过第一个和最后一个标记点
|
|
380
|
+
}
|
|
381
|
+
const percentage = ((i - this.min) / (this.max - this.min)) * 100;
|
|
382
|
+
this.markList.push({
|
|
383
|
+
left: this.vertical ? '0' : `${percentage}%`,
|
|
384
|
+
top: this.vertical ? `${percentage}%` : '0',
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
};
|
|
391
|
+
</script>
|
|
392
|
+
|
|
393
|
+
<style lang="scss" scoped>
|
|
394
|
+
.ste-slider-root {
|
|
395
|
+
position: relative;
|
|
396
|
+
z-index: 1;
|
|
397
|
+
width: 100%;
|
|
398
|
+
height: var(--progress-height);
|
|
399
|
+
border-radius: 24rpx;
|
|
400
|
+
|
|
401
|
+
&.ste-slider-disabled {
|
|
402
|
+
.active-box {
|
|
403
|
+
background-color: #cccccc;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
.inactive-box {
|
|
407
|
+
background-color: #eeeeee;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
.slider-bar-box {
|
|
411
|
+
.slider-bar {
|
|
412
|
+
border-color: #cccccc;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
&.ste-slider-drag {
|
|
418
|
+
.active-box {
|
|
419
|
+
transition: none !important;
|
|
420
|
+
}
|
|
421
|
+
.slider-bar-box {
|
|
422
|
+
transition: none !important;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
&.ste-slider-vertical {
|
|
426
|
+
display: inline-block;
|
|
427
|
+
margin: 0 16rpx;
|
|
428
|
+
width: var(--progress-height);
|
|
429
|
+
height: 100%;
|
|
430
|
+
|
|
431
|
+
.inactive-box {
|
|
432
|
+
height: 100%;
|
|
433
|
+
width: var(--progress-height);
|
|
434
|
+
}
|
|
435
|
+
.active-box {
|
|
436
|
+
align-items: flex-end;
|
|
437
|
+
justify-content: center;
|
|
438
|
+
width: 100%;
|
|
439
|
+
transition: height 0.3s ease;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
.slider-bar-box {
|
|
443
|
+
transition: top 0.3s ease;
|
|
444
|
+
left: 50%;
|
|
445
|
+
top: 0;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
.mark-box {
|
|
449
|
+
display: flex;
|
|
450
|
+
align-items: center;
|
|
451
|
+
transform: translateY(-50%);
|
|
452
|
+
.dot {
|
|
453
|
+
margin-right: 20rpx;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
&.ste-slider-horizontal {
|
|
458
|
+
margin: 16rpx 0;
|
|
459
|
+
.mark-box {
|
|
460
|
+
transform: translateX(-50%);
|
|
461
|
+
display: flex;
|
|
462
|
+
flex-direction: column;
|
|
463
|
+
justify-content: center;
|
|
464
|
+
align-items: center;
|
|
465
|
+
|
|
466
|
+
.dot {
|
|
467
|
+
margin-bottom: 20rpx;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
.slider-bar-box {
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
.inactive-box {
|
|
475
|
+
width: 100%;
|
|
476
|
+
height: var(--progress-height);
|
|
477
|
+
border-radius: 24rpx;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
.active-box {
|
|
481
|
+
width: 100%;
|
|
482
|
+
height: var(--progress-height);
|
|
483
|
+
border-radius: 24rpx;
|
|
484
|
+
position: absolute;
|
|
485
|
+
left: 0;
|
|
486
|
+
top: 0;
|
|
487
|
+
|
|
488
|
+
display: flex;
|
|
489
|
+
align-items: center;
|
|
490
|
+
justify-content: flex-end;
|
|
491
|
+
transition: width 0.3s ease;
|
|
492
|
+
z-index: 2;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
.slider-bar-box {
|
|
496
|
+
cursor: grab;
|
|
497
|
+
position: absolute;
|
|
498
|
+
left: 0;
|
|
499
|
+
top: 50%;
|
|
500
|
+
transform: translate(-50%, -50%);
|
|
501
|
+
z-index: 9;
|
|
502
|
+
padding: 12rpx;
|
|
503
|
+
|
|
504
|
+
transition: left 0.3s ease;
|
|
505
|
+
white-space: nowrap;
|
|
506
|
+
/* 其他样式 */
|
|
507
|
+
view {
|
|
508
|
+
white-space: nowrap;
|
|
509
|
+
}
|
|
510
|
+
text {
|
|
511
|
+
white-space: nowrap;
|
|
512
|
+
}
|
|
513
|
+
.slider-bar {
|
|
514
|
+
min-width: var(--bar-size);
|
|
515
|
+
height: var(--bar-size);
|
|
516
|
+
width: var(--bar-size);
|
|
517
|
+
border-radius: 50%;
|
|
518
|
+
background-color: #ffffff;
|
|
519
|
+
border: 2rpx solid var(--active-color);
|
|
520
|
+
|
|
521
|
+
display: flex;
|
|
522
|
+
align-items: center;
|
|
523
|
+
justify-content: center;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
.mark-box {
|
|
528
|
+
position: absolute;
|
|
529
|
+
z-index: 3;
|
|
530
|
+
.dot {
|
|
531
|
+
height: var(--progress-height);
|
|
532
|
+
width: var(--progress-height);
|
|
533
|
+
border-radius: 100%;
|
|
534
|
+
background-color: #fff;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
.marks-label {
|
|
538
|
+
white-space: nowrap;
|
|
539
|
+
|
|
540
|
+
font-size: 24rpx;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
</style>
|