@tdesign/uniapp 0.7.3 → 0.8.0
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/CHANGELOG.md +23 -0
- package/README.md +1 -1
- package/dist/action-sheet/README.md +1 -1
- package/dist/action-sheet/action-sheet.vue +158 -150
- package/dist/action-sheet/props.ts +2 -2
- package/dist/action-sheet/type.ts +1 -1
- package/dist/avatar/avatar.vue +89 -87
- package/dist/avatar-group/avatar-group.vue +69 -67
- package/dist/back-top/back-top.vue +60 -58
- package/dist/badge/badge.vue +69 -59
- package/dist/button/button.vue +121 -116
- package/dist/button/props.ts +2 -2
- package/dist/button/type.ts +1 -1
- package/dist/calendar/calendar-header.vue +4 -4
- package/dist/calendar/calendar.vue +308 -297
- package/dist/calendar/template.vue +1 -1
- package/dist/cascader/README.en-US.md +2 -1
- package/dist/cascader/README.md +2 -1
- package/dist/cascader/cascader.vue +340 -328
- package/dist/cascader/props.ts +6 -1
- package/dist/cascader/type.ts +6 -0
- package/dist/cell/cell.vue +127 -121
- package/dist/cell-group/cell-group.vue +32 -30
- package/dist/check-tag/check-tag.vue +73 -71
- package/dist/checkbox/checkbox.vue +127 -127
- package/dist/checkbox/props.ts +6 -6
- package/dist/checkbox/type.ts +3 -3
- package/dist/checkbox-group/checkbox-group.vue +175 -173
- package/dist/checkbox-group/props.ts +6 -6
- package/dist/checkbox-group/type.ts +4 -4
- package/dist/col/col.vue +26 -24
- package/dist/collapse/collapse.vue +83 -81
- package/dist/collapse-panel/collapse-panel.vue +121 -119
- package/dist/collapse-panel/props.ts +4 -4
- package/dist/collapse-panel/type.ts +2 -2
- package/dist/color-picker/README.md +1 -1
- package/dist/color-picker/color-picker.vue +324 -322
- package/dist/color-picker/props.ts +2 -2
- package/dist/color-picker/template.vue +14 -10
- package/dist/common/common.ts +1 -0
- package/dist/common/style/theme/index.css +5 -5
- package/dist/common/utils.js +7 -2
- package/dist/common/validator.js +172 -0
- package/dist/config-provider/README.en-US.md +184 -0
- package/dist/config-provider/README.md +234 -0
- package/dist/config-provider/config-provider.vue +105 -0
- package/dist/config-provider/config-store.js +70 -0
- package/dist/config-provider/props.ts +16 -0
- package/dist/config-provider/reactive-state.js +39 -0
- package/dist/config-provider/type.ts +401 -0
- package/dist/config-provider/use-config.js +29 -0
- package/dist/config-provider/utils.js +29 -0
- package/dist/count-down/count-down.vue +98 -97
- package/dist/date-time-picker/date-time-picker.vue +410 -395
- package/dist/demo/demo.vue +1 -0
- package/dist/dialog/dialog.vue +175 -173
- package/dist/divider/divider.vue +38 -36
- package/dist/draggable/draggable.vue +60 -58
- package/dist/drawer/README.md +1 -1
- package/dist/drawer/drawer.vue +48 -46
- package/dist/dropdown-item/dropdown-item.vue +209 -207
- package/dist/dropdown-item/props.ts +4 -4
- package/dist/dropdown-item/type.ts +3 -3
- package/dist/dropdown-menu/dropdown-menu.vue +93 -99
- package/dist/empty/empty.vue +43 -42
- package/dist/fab/fab.vue +88 -86
- package/dist/footer/footer.vue +36 -34
- package/dist/form/README.en-US.md +17 -24
- package/dist/form/README.md +18 -25
- package/dist/form/form.css +1 -166
- package/dist/form/form.vue +251 -236
- package/dist/form/props.ts +2 -21
- package/dist/form/type.ts +7 -70
- package/dist/form-item/README.en-US.md +4 -5
- package/dist/form-item/README.md +4 -5
- package/dist/form-item/form-item.css +69 -96
- package/dist/form-item/form-item.vue +315 -336
- package/dist/form-item/form-model.ts +125 -173
- package/dist/form-item/props.ts +4 -17
- package/dist/form-item/type.ts +43 -1
- package/dist/grid/grid.vue +53 -51
- package/dist/grid-item/grid-item.vue +121 -119
- package/dist/guide/README.md +1 -1
- package/dist/guide/guide.vue +281 -277
- package/dist/icon/README.md +2 -4
- package/dist/icon/icon.vue +78 -76
- package/dist/image/README.md +1 -1
- package/dist/image/image.vue +103 -101
- package/dist/image-viewer/image-viewer.vue +160 -158
- package/dist/image-viewer/props.ts +2 -2
- package/dist/image-viewer/type.ts +1 -1
- package/dist/index.js +3 -0
- package/dist/indexes/indexes.vue +264 -267
- package/dist/indexes-anchor/indexes-anchor.vue +41 -41
- package/dist/input/input.vue +192 -192
- package/dist/input/props.ts +6 -6
- package/dist/input/type.ts +3 -3
- package/dist/link/link.vue +73 -71
- package/dist/loading/loading.vue +59 -59
- package/dist/locale/ar_KW.ts +157 -0
- package/dist/locale/en_US.ts +146 -0
- package/dist/locale/it_IT.ts +145 -0
- package/dist/locale/ja_JP.ts +132 -0
- package/dist/locale/ko_KR.ts +132 -0
- package/dist/locale/ru_RU.ts +157 -0
- package/dist/locale/zh_CN.ts +133 -0
- package/dist/locale/zh_TW.ts +132 -0
- package/dist/message/message.vue +181 -173
- package/dist/message/props.ts +2 -2
- package/dist/message/type.ts +1 -1
- package/dist/message-item/message-item.vue +192 -184
- package/dist/mixins/using-config.js +39 -0
- package/dist/navbar/navbar.vue +201 -199
- package/dist/notice-bar/notice-bar.vue +175 -171
- package/dist/notice-bar/props.ts +2 -2
- package/dist/notice-bar/type.ts +1 -1
- package/dist/npm/dayjs/esm/locale/ar.js +81 -0
- package/dist/npm/dayjs/esm/locale/it.js +39 -0
- package/dist/overlay/overlay.vue +50 -48
- package/dist/picker/picker.vue +168 -161
- package/dist/picker-item/picker-item.vue +269 -269
- package/dist/popover/README.md +1 -1
- package/dist/popover/popover.vue +262 -261
- package/dist/popover/props.ts +4 -4
- package/dist/popover/type.ts +2 -2
- package/dist/popup/popup.vue +46 -45
- package/dist/progress/README.md +1 -1
- package/dist/progress/progress.vue +76 -76
- package/dist/pull-down-refresh/props.ts +2 -2
- package/dist/pull-down-refresh/pull-down-refresh.vue +240 -234
- package/dist/pull-down-refresh/type.ts +1 -1
- package/dist/qrcode/README.md +1 -1
- package/dist/qrcode/components/qrcode-canvas/qrcode-canvas.vue +340 -338
- package/dist/qrcode/components/qrcode-status/qrcode-status.vue +6 -6
- package/dist/qrcode/qrcode.vue +93 -87
- package/dist/radio/props.ts +6 -6
- package/dist/radio/radio.vue +118 -120
- package/dist/radio/type.ts +3 -3
- package/dist/radio-group/props.ts +4 -4
- package/dist/radio-group/radio-group.vue +136 -134
- package/dist/radio-group/type.ts +4 -4
- package/dist/rate/computed.js +2 -2
- package/dist/rate/props.ts +4 -4
- package/dist/rate/rate.vue +155 -154
- package/dist/rate/type.ts +2 -2
- package/dist/result/result.vue +41 -39
- package/dist/row/row.vue +38 -36
- package/dist/scroll-view/scroll-view.vue +24 -22
- package/dist/search/props.ts +2 -2
- package/dist/search/search.vue +127 -125
- package/dist/search/type.ts +1 -1
- package/dist/side-bar/side-bar.vue +57 -55
- package/dist/side-bar-item/side-bar-item.vue +86 -86
- package/dist/skeleton/skeleton.vue +126 -124
- package/dist/slider/README.md +1 -1
- package/dist/slider/props.ts +2 -2
- package/dist/slider/slider.vue +457 -457
- package/dist/slider/type.ts +1 -1
- package/dist/step-item/step-item.vue +77 -75
- package/dist/stepper/props.ts +2 -2
- package/dist/stepper/stepper.vue +168 -149
- package/dist/stepper/type.ts +1 -1
- package/dist/steps/props.ts +2 -2
- package/dist/steps/steps.vue +83 -81
- package/dist/steps/type.ts +1 -1
- package/dist/sticky/sticky.vue +104 -102
- package/dist/swipe-cell/swipe-cell.vue +91 -89
- package/dist/swiper/README.md +1 -1
- package/dist/swiper/swiper.vue +91 -89
- package/dist/swiper-nav/swiper-nav.vue +38 -36
- package/dist/switch/props.ts +2 -2
- package/dist/switch/switch.vue +62 -62
- package/dist/switch/type.ts +1 -1
- package/dist/tab-bar/tab-bar.vue +88 -86
- package/dist/tab-bar-item/tab-bar-item.vue +85 -82
- package/dist/tab-panel/tab-panel.vue +66 -64
- package/dist/tabs/tabs.vue +294 -287
- package/dist/tag/tag.vue +79 -77
- package/dist/textarea/props.ts +6 -6
- package/dist/textarea/textarea.vue +127 -126
- package/dist/textarea/type.ts +3 -3
- package/dist/toast/toast.vue +107 -106
- package/dist/transition/transition.vue +30 -28
- package/dist/tree-select/tree-select.vue +151 -151
- package/dist/types/config-provider.d.ts +7 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/popover.d.ts +7 -0
- package/dist/upload/README.en-US.md +13 -14
- package/dist/upload/README.md +11 -12
- package/dist/upload/props.ts +2 -4
- package/dist/upload/type.ts +12 -11
- package/dist/upload/upload.css +1 -1
- package/dist/upload/upload.vue +672 -512
- package/dist/watermark/watermark.vue +151 -149
- package/global.d.ts +2 -0
- package/package.json +15 -3
- package/dist/form/form-item-props.ts +0 -56
package/dist/slider/slider.vue
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view
|
|
3
|
-
:style="tools._style([customStyle])"
|
|
4
|
-
:class="
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
(vertical ? classPrefix + '--vertical' : '')
|
|
14
|
-
"
|
|
3
|
+
:style="'' + tools._style([customStyle])"
|
|
4
|
+
:class="'' + tools.cls(classPrefix, [
|
|
5
|
+
['top', label || scaleTextArray.length],
|
|
6
|
+
['disabled', disabled],
|
|
7
|
+
['range', range]
|
|
8
|
+
]) +
|
|
9
|
+
' ' +
|
|
10
|
+
tClass +
|
|
11
|
+
' ' +
|
|
12
|
+
(vertical ? classPrefix + '--vertical' : '')"
|
|
15
13
|
>
|
|
16
14
|
<block v-if="!range">
|
|
17
15
|
<text
|
|
@@ -22,7 +20,7 @@
|
|
|
22
20
|
</text>
|
|
23
21
|
<view
|
|
24
22
|
id="sliderLine"
|
|
25
|
-
:class="tools.cls(classPrefix + '__bar', [['disabled', disabled], theme, ['marks', isScale && theme == 'capsule']]) + ' ' + tClassBar"
|
|
23
|
+
:class="'' + tools.cls(classPrefix + '__bar', [['disabled', disabled], theme, ['marks', isScale && theme == 'capsule']]) + ' ' + tClassBar"
|
|
26
24
|
@click="onSingleLineTap"
|
|
27
25
|
>
|
|
28
26
|
<block v-if="isScale">
|
|
@@ -30,7 +28,7 @@
|
|
|
30
28
|
v-for="(item, index) in scaleArray"
|
|
31
29
|
:key="index"
|
|
32
30
|
:class="
|
|
33
|
-
tools.cls(classPrefix + '__scale-item', [
|
|
31
|
+
'' + tools.cls(classPrefix + '__scale-item', [
|
|
34
32
|
['active', innerValue >= item.val],
|
|
35
33
|
['disabled', disabled],
|
|
36
34
|
theme,
|
|
@@ -42,14 +40,14 @@
|
|
|
42
40
|
>
|
|
43
41
|
<view
|
|
44
42
|
v-if="scaleTextArray.length"
|
|
45
|
-
:class="tools.cls(classPrefix + '__scale-desc', [theme])"
|
|
43
|
+
:class="'' + tools.cls(classPrefix + '__scale-desc', [theme])"
|
|
46
44
|
>
|
|
47
45
|
{{ scaleTextArray[index] }}
|
|
48
46
|
</view>
|
|
49
47
|
</view>
|
|
50
48
|
</block>
|
|
51
49
|
<view
|
|
52
|
-
:class="tools.cls(classPrefix + '__line', [['disabled', disabled], theme, 'single']) + ' ' + tClassBarActive"
|
|
50
|
+
:class="'' + tools.cls(classPrefix + '__line', [['disabled', disabled], theme, 'single']) + ' ' + tClassBarActive"
|
|
53
51
|
:style="(vertical ? 'height' : 'width') + ': ' + lineBarWidth"
|
|
54
52
|
>
|
|
55
53
|
<view
|
|
@@ -62,7 +60,7 @@
|
|
|
62
60
|
>
|
|
63
61
|
<view
|
|
64
62
|
v-if="label || isVisibleToScreenReader"
|
|
65
|
-
:class="tools.cls(classPrefix + '__dot-value', [['sr-only', !label]])"
|
|
63
|
+
:class="'' + tools.cls(classPrefix + '__dot-value', [['sr-only', !label]])"
|
|
66
64
|
aria-role="alert"
|
|
67
65
|
aria-live="assertive"
|
|
68
66
|
:aria-hidden="!isVisibleToScreenReader"
|
|
@@ -97,7 +95,7 @@
|
|
|
97
95
|
</view>
|
|
98
96
|
<view
|
|
99
97
|
id="sliderLine"
|
|
100
|
-
:class="tools.cls(classPrefix + '__bar', [['disabled', disabled], theme, ['marks', isScale && theme == 'capsule']]) + ' ' + tClassBar"
|
|
98
|
+
:class="'' + tools.cls(classPrefix + '__bar', [['disabled', disabled], theme, ['marks', isScale && theme == 'capsule']]) + ' ' + tClassBar"
|
|
101
99
|
@click="onLineTap"
|
|
102
100
|
>
|
|
103
101
|
<block v-if="isScale">
|
|
@@ -105,7 +103,7 @@
|
|
|
105
103
|
v-for="(item, index) in scaleArray"
|
|
106
104
|
:key="index"
|
|
107
105
|
:class="
|
|
108
|
-
tools.cls(classPrefix + '__scale-item', [
|
|
106
|
+
'' + tools.cls(classPrefix + '__scale-item', [
|
|
109
107
|
['active', dotTopValue[1] >= item.val && item.val >= dotTopValue[0]],
|
|
110
108
|
['disabled', disabled],
|
|
111
109
|
theme,
|
|
@@ -117,14 +115,14 @@
|
|
|
117
115
|
>
|
|
118
116
|
<view
|
|
119
117
|
v-if="scaleTextArray.length"
|
|
120
|
-
:class="tools.cls(classPrefix + '__scale-desc', [theme])"
|
|
118
|
+
:class="'' + tools.cls(classPrefix + '__scale-desc', [theme])"
|
|
121
119
|
>
|
|
122
120
|
{{ scaleTextArray[index] }}
|
|
123
121
|
</view>
|
|
124
122
|
</view>
|
|
125
123
|
</block>
|
|
126
124
|
<view
|
|
127
|
-
:class="tools.cls(classPrefix + '__line', [['disabled', disabled], theme]) + ' ' + tClassBarActive"
|
|
125
|
+
:class="'' + tools.cls(classPrefix + '__line', [['disabled', disabled], theme]) + ' ' + tClassBarActive"
|
|
128
126
|
:style="(vertical ? 'top' : 'left') + ': ' + lineLeft + 'px; ' + (vertical ? 'bottom' : 'right') + ': ' + lineRight + 'px'"
|
|
129
127
|
>
|
|
130
128
|
<view
|
|
@@ -137,7 +135,7 @@
|
|
|
137
135
|
>
|
|
138
136
|
<view
|
|
139
137
|
v-if="label || isVisibleToScreenReader"
|
|
140
|
-
:class="tools.cls(classPrefix + '__dot-value', [['sr-only', !label]])"
|
|
138
|
+
:class="'' + tools.cls(classPrefix + '__dot-value', [['sr-only', !label]])"
|
|
141
139
|
aria-role="alert"
|
|
142
140
|
aria-live="assertive"
|
|
143
141
|
:aria-hidden="!isVisibleToScreenReader"
|
|
@@ -164,7 +162,7 @@
|
|
|
164
162
|
>
|
|
165
163
|
<view
|
|
166
164
|
v-if="label || isVisibleToScreenReader"
|
|
167
|
-
:class="tools.cls(classPrefix + '__dot-value', [['sr-only', !label]])"
|
|
165
|
+
:class="'' + tools.cls(classPrefix + '__dot-value', [['sr-only', !label]])"
|
|
168
166
|
aria-role="alert"
|
|
169
167
|
aria-live="assertive"
|
|
170
168
|
:aria-hidden="!isVisibleToScreenReader"
|
|
@@ -206,354 +204,355 @@ import { isString, isFunction } from '../common/validator';
|
|
|
206
204
|
|
|
207
205
|
const name = `${prefix}-slider`;
|
|
208
206
|
|
|
209
|
-
export default
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
controlledProps: [
|
|
215
|
-
{
|
|
216
|
-
key: 'value',
|
|
217
|
-
event: 'change',
|
|
207
|
+
export default {
|
|
208
|
+
...uniComponent({
|
|
209
|
+
name,
|
|
210
|
+
options: {
|
|
211
|
+
styleIsolation: 'shared',
|
|
218
212
|
},
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
`${prefix}-class-bar-active`,
|
|
224
|
-
`${prefix}-class-bar-disabled`,
|
|
225
|
-
`${prefix}-class-cursor`,
|
|
226
|
-
],
|
|
227
|
-
props: {
|
|
228
|
-
...props,
|
|
229
|
-
},
|
|
230
|
-
data() {
|
|
231
|
-
return {
|
|
232
|
-
// 按钮样式列表
|
|
233
|
-
sliderStyles: '',
|
|
234
|
-
classPrefix: name,
|
|
235
|
-
initialLeft: null,
|
|
236
|
-
initialRight: null,
|
|
237
|
-
activeLeft: 0,
|
|
238
|
-
activeRight: 0,
|
|
239
|
-
maxRange: 0,
|
|
240
|
-
lineLeft: 0,
|
|
241
|
-
lineRight: 0,
|
|
242
|
-
dotTopValue: [0, 0],
|
|
243
|
-
innerValue: 0,
|
|
244
|
-
blockSize: 20,
|
|
245
|
-
isScale: false,
|
|
246
|
-
scaleArray: [],
|
|
247
|
-
scaleTextArray: [],
|
|
248
|
-
prefix,
|
|
249
|
-
realLabel: '',
|
|
250
|
-
extremeLabel: [],
|
|
251
|
-
isVisibleToScreenReader: false,
|
|
252
|
-
identifier: [-1, -1],
|
|
253
|
-
__inited: false,
|
|
254
|
-
tools,
|
|
255
|
-
|
|
256
|
-
lineBarWidth: 0,
|
|
257
|
-
};
|
|
258
|
-
},
|
|
259
|
-
watch: {
|
|
260
|
-
value: {
|
|
261
|
-
handler(newValue) {
|
|
262
|
-
this.handlePropsChange(newValue);
|
|
213
|
+
controlledProps: [
|
|
214
|
+
{
|
|
215
|
+
key: 'value',
|
|
216
|
+
event: 'change',
|
|
263
217
|
},
|
|
264
|
-
|
|
265
|
-
|
|
218
|
+
],
|
|
219
|
+
externalClasses: [
|
|
220
|
+
`${prefix}-class`,
|
|
221
|
+
`${prefix}-class-bar`,
|
|
222
|
+
`${prefix}-class-bar-active`,
|
|
223
|
+
`${prefix}-class-bar-disabled`,
|
|
224
|
+
`${prefix}-class-cursor`,
|
|
225
|
+
],
|
|
226
|
+
props: {
|
|
227
|
+
...props,
|
|
266
228
|
},
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
229
|
+
data() {
|
|
230
|
+
return {
|
|
231
|
+
// 按钮样式列表
|
|
232
|
+
sliderStyles: '',
|
|
233
|
+
classPrefix: name,
|
|
234
|
+
initialLeft: null,
|
|
235
|
+
initialRight: null,
|
|
236
|
+
activeLeft: 0,
|
|
237
|
+
activeRight: 0,
|
|
238
|
+
maxRange: 0,
|
|
239
|
+
lineLeft: 0,
|
|
240
|
+
lineRight: 0,
|
|
241
|
+
dotTopValue: [0, 0],
|
|
242
|
+
innerValue: 0,
|
|
243
|
+
blockSize: 20,
|
|
244
|
+
isScale: false,
|
|
245
|
+
scaleArray: [],
|
|
246
|
+
scaleTextArray: [],
|
|
247
|
+
prefix,
|
|
248
|
+
realLabel: '',
|
|
249
|
+
extremeLabel: [],
|
|
250
|
+
isVisibleToScreenReader: false,
|
|
251
|
+
identifier: [-1, -1],
|
|
252
|
+
__inited: false,
|
|
253
|
+
tools,
|
|
254
|
+
|
|
255
|
+
lineBarWidth: 0,
|
|
256
|
+
};
|
|
274
257
|
},
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
258
|
+
watch: {
|
|
259
|
+
value: {
|
|
260
|
+
handler(newValue) {
|
|
261
|
+
this.handlePropsChange(newValue);
|
|
262
|
+
},
|
|
263
|
+
// immediate: true,
|
|
264
|
+
deep: true,
|
|
278
265
|
},
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
266
|
+
innerValue: {
|
|
267
|
+
handler(newValue) {
|
|
268
|
+
this.bus.on('initial', () => this.renderLine(newValue));
|
|
269
|
+
this.toggleA11yTips();
|
|
270
|
+
},
|
|
271
|
+
// immediate: true,
|
|
272
|
+
deep: true,
|
|
273
|
+
},
|
|
274
|
+
marks: {
|
|
275
|
+
handler(val) {
|
|
276
|
+
this.bus.on('initial', () => this.handleMark(val));
|
|
277
|
+
},
|
|
278
|
+
// immediate: true,
|
|
279
|
+
deep: true,
|
|
285
280
|
},
|
|
286
|
-
|
|
281
|
+
label: {
|
|
282
|
+
handler(val) {
|
|
283
|
+
this.isShowLabel = Boolean(val);
|
|
284
|
+
},
|
|
285
|
+
immediate: true,
|
|
286
|
+
},
|
|
287
|
+
showExtremeValue: 'getwExtremeLabel',
|
|
288
|
+
min: 'getwExtremeLabel',
|
|
289
|
+
max: 'getwExtremeLabel',
|
|
287
290
|
},
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
this.bus.on('initial', () => {
|
|
296
|
-
nextTick().then(() => {
|
|
297
|
-
this.renderLine(this.innerValue);
|
|
291
|
+
created() {
|
|
292
|
+
this.bus = new Bus();
|
|
293
|
+
this.bus.on('initial', () => this.handleMark(this.marks));
|
|
294
|
+
this.bus.on('initial', () => {
|
|
295
|
+
nextTick().then(() => {
|
|
296
|
+
this.renderLine(this.innerValue);
|
|
297
|
+
});
|
|
298
298
|
});
|
|
299
|
-
|
|
300
|
-
this.toggleA11yTips();
|
|
301
|
-
},
|
|
302
|
-
mounted() {
|
|
303
|
-
const { value, defaultValue } = this;
|
|
304
|
-
// if (!value)
|
|
305
|
-
this.handlePropsChange(coalesce(value, defaultValue, 0));
|
|
306
|
-
this.init();
|
|
307
|
-
this.injectPageScroll();
|
|
308
|
-
},
|
|
309
|
-
|
|
310
|
-
methods: {
|
|
311
|
-
getValue,
|
|
312
|
-
getwExtremeLabel() {
|
|
313
|
-
const { showExtremeValue, min, max } = this;
|
|
314
|
-
if (!showExtremeValue) return;
|
|
315
|
-
|
|
316
|
-
this.extremeLabel = [this.getLabelByValue(Number(min), 'min'), this.getLabelByValue(Number(max), 'max')];
|
|
299
|
+
this.toggleA11yTips();
|
|
317
300
|
},
|
|
318
|
-
|
|
319
|
-
const {
|
|
320
|
-
if (!
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
curPage = pages[pages.length - 1];
|
|
325
|
-
}
|
|
326
|
-
if (!curPage) return;
|
|
327
|
-
const originPageScroll = curPage?.onPageScroll;
|
|
328
|
-
curPage.onPageScroll = (rest) => {
|
|
329
|
-
originPageScroll?.call(this, rest);
|
|
330
|
-
this.observerScrollTop(rest);
|
|
331
|
-
};
|
|
301
|
+
mounted() {
|
|
302
|
+
const { value, defaultValue } = this;
|
|
303
|
+
// if (!value)
|
|
304
|
+
this.handlePropsChange(coalesce(value, defaultValue, 0));
|
|
305
|
+
this.init();
|
|
306
|
+
this.injectPageScroll();
|
|
332
307
|
},
|
|
333
308
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
309
|
+
methods: {
|
|
310
|
+
getValue,
|
|
311
|
+
getwExtremeLabel() {
|
|
312
|
+
const { showExtremeValue, min, max } = this;
|
|
313
|
+
if (!showExtremeValue) return;
|
|
338
314
|
|
|
339
|
-
|
|
340
|
-
|
|
315
|
+
this.extremeLabel = [this.getLabelByValue(Number(min), 'min'), this.getLabelByValue(Number(max), 'max')];
|
|
316
|
+
},
|
|
317
|
+
injectPageScroll() {
|
|
318
|
+
const { range, vertical } = this;
|
|
319
|
+
if (!range || !vertical) return;
|
|
320
|
+
const pages = getCurrentPages() || [];
|
|
321
|
+
let curPage = null;
|
|
322
|
+
if (pages && pages.length - 1 >= 0) {
|
|
323
|
+
curPage = pages[pages.length - 1];
|
|
324
|
+
}
|
|
325
|
+
if (!curPage) return;
|
|
326
|
+
const originPageScroll = curPage?.onPageScroll;
|
|
327
|
+
curPage.onPageScroll = (rest) => {
|
|
328
|
+
originPageScroll?.call(this, rest);
|
|
329
|
+
this.observerScrollTop(rest);
|
|
330
|
+
};
|
|
331
|
+
},
|
|
341
332
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
333
|
+
observerScrollTop(rest) {
|
|
334
|
+
const { scrollTop } = rest || {};
|
|
335
|
+
this.pageScrollTop = scrollTop;
|
|
336
|
+
},
|
|
346
337
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const { maxRange } = this;
|
|
350
|
-
|
|
351
|
-
if (range) {
|
|
352
|
-
const left = (maxRange * (val[0] - Number(min))) / (Number(max) - Number(min));
|
|
353
|
-
const right = (maxRange * (Number(max) - val[1])) / (Number(max) - Number(min));
|
|
354
|
-
// 因为要计算点相对于线的绝对定位,所以要取整条线的长度而非可滑动的范围
|
|
355
|
-
this.setLineStyle(left, right);
|
|
356
|
-
} else {
|
|
357
|
-
this.setSingleBarWidth(val);
|
|
358
|
-
}
|
|
359
|
-
},
|
|
338
|
+
toggleA11yTips() {
|
|
339
|
+
this.isVisibleToScreenReader = true;
|
|
360
340
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
});
|
|
341
|
+
setTimeout(() => {
|
|
342
|
+
this.isVisibleToScreenReader = false;
|
|
343
|
+
}, 2000);
|
|
344
|
+
},
|
|
366
345
|
|
|
367
|
-
|
|
368
|
-
|
|
346
|
+
renderLine(val) {
|
|
347
|
+
const { min, max, range } = this;
|
|
348
|
+
const { maxRange } = this;
|
|
369
349
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
350
|
+
if (range) {
|
|
351
|
+
const left = (maxRange * (val[0] - Number(min))) / (Number(max) - Number(min));
|
|
352
|
+
const right = (maxRange * (Number(max) - val[1])) / (Number(max) - Number(min));
|
|
353
|
+
// 因为要计算点相对于线的绝对定位,所以要取整条线的长度而非可滑动的范围
|
|
354
|
+
this.setLineStyle(left, right);
|
|
355
|
+
} else {
|
|
356
|
+
this.setSingleBarWidth(val);
|
|
357
|
+
}
|
|
358
|
+
},
|
|
377
359
|
|
|
378
|
-
|
|
379
|
-
|
|
360
|
+
triggerValue(value) {
|
|
361
|
+
const { min, max, range } = this;
|
|
362
|
+
const trimmedValue = trimValue(value, {
|
|
363
|
+
min, max, range,
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
if (JSON.stringify(this.preval) === JSON.stringify(trimmedValue)) return;
|
|
367
|
+
this.preval = value;
|
|
368
|
+
|
|
369
|
+
this._trigger('change', {
|
|
370
|
+
value: trimmedValue,
|
|
371
|
+
});
|
|
372
|
+
if (this._selfControlled) {
|
|
373
|
+
this.innerValue = trimmedValue;
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
|
|
377
|
+
getLabelByValue(value, position) {
|
|
378
|
+
const { label } = this;
|
|
379
|
+
|
|
380
|
+
if (isString(label)) {
|
|
381
|
+
let text = String(value);
|
|
382
|
+
try {
|
|
383
|
+
const rule = /\${value}%/g;
|
|
384
|
+
const enableToReplace = rule.test(label);
|
|
385
|
+
if (enableToReplace) {
|
|
386
|
+
text = label.replace(rule, String(value));
|
|
387
|
+
} else {
|
|
388
|
+
text = label;
|
|
389
|
+
throw new Error();
|
|
390
|
+
}
|
|
391
|
+
} catch (e) {
|
|
380
392
|
|
|
381
|
-
if (isString(label)) {
|
|
382
|
-
let text = String(value);
|
|
383
|
-
try {
|
|
384
|
-
const rule = /\${value}%/g;
|
|
385
|
-
const enableToReplace = rule.test(label);
|
|
386
|
-
if (enableToReplace) {
|
|
387
|
-
text = label.replace(rule, String(value));
|
|
388
|
-
} else {
|
|
389
|
-
text = label;
|
|
390
|
-
throw new Error();
|
|
391
393
|
}
|
|
392
|
-
|
|
394
|
+
return text;
|
|
395
|
+
}
|
|
393
396
|
|
|
397
|
+
if (isFunction(label)) {
|
|
398
|
+
return label(value, position);
|
|
394
399
|
}
|
|
395
|
-
return text;
|
|
396
|
-
}
|
|
397
400
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
}
|
|
401
|
+
return String(value);
|
|
402
|
+
},
|
|
401
403
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
+
handlePropsChange(newValue) {
|
|
405
|
+
const { min, max, range } = this;
|
|
404
406
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
+
const value = trimValue(newValue, {
|
|
408
|
+
min, max, range,
|
|
409
|
+
});
|
|
407
410
|
|
|
408
|
-
|
|
409
|
-
min, max, range,
|
|
410
|
-
});
|
|
411
|
+
const realLabel = this.getLabelByValue(value);
|
|
411
412
|
|
|
412
|
-
|
|
413
|
+
// 避免受控模式下死循环,同时不影响初始化后的首次点击
|
|
414
|
+
if (this.preval !== undefined) {
|
|
415
|
+
this.preval = value;
|
|
416
|
+
}
|
|
413
417
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
+
const setValueAndTrigger = () => {
|
|
419
|
+
this.innerValue = value;
|
|
420
|
+
this.realLabel = realLabel;
|
|
421
|
+
};
|
|
418
422
|
|
|
419
|
-
|
|
420
|
-
this.
|
|
421
|
-
|
|
422
|
-
|
|
423
|
+
// 基本样式未初始化,等待初始化后在改变数据。
|
|
424
|
+
if (this.maxRange === 0) {
|
|
425
|
+
this.init().then(setValueAndTrigger);
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
423
428
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
this.init().then(setValueAndTrigger);
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
+
setValueAndTrigger();
|
|
430
|
+
},
|
|
429
431
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
+
valueToPosition(value) {
|
|
433
|
+
const { min, max, theme } = this;
|
|
434
|
+
const { blockSize, maxRange } = this;
|
|
435
|
+
const halfBlock = (theme) === 'capsule' ? Number(blockSize) / 2 : 0;
|
|
432
436
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
const { blockSize, maxRange } = this;
|
|
436
|
-
const halfBlock = (theme) === 'capsule' ? Number(blockSize) / 2 : 0;
|
|
437
|
+
return Math.round(((Number(value) - Number(min)) / (Number(max) - Number(min))) * maxRange) + halfBlock;
|
|
438
|
+
},
|
|
437
439
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
+
handleMark(marks) {
|
|
441
|
+
const calcPos = arr => arr.map(item => ({
|
|
442
|
+
val: item,
|
|
443
|
+
left: this.valueToPosition(item),
|
|
444
|
+
}));
|
|
440
445
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
if (marks?.length && Array.isArray(marks)) {
|
|
448
|
-
this.isScale = true;
|
|
449
|
-
this.scaleArray = calcPos(marks);
|
|
450
|
-
this.scaleTextArray = [];
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
if (Object.prototype.toString.call(marks) === '[object Object]') {
|
|
454
|
-
const scaleArray = Object.keys(marks).map(item => Number(item));
|
|
455
|
-
const scaleTextArray = scaleArray.map(item => marks[item]);
|
|
456
|
-
|
|
457
|
-
this.isScale = scaleArray.length > 0;
|
|
458
|
-
this.scaleArray = calcPos(scaleArray);
|
|
459
|
-
this.scaleTextArray = scaleTextArray;
|
|
460
|
-
}
|
|
461
|
-
},
|
|
446
|
+
if (marks?.length && Array.isArray(marks)) {
|
|
447
|
+
this.isScale = true;
|
|
448
|
+
this.scaleArray = calcPos(marks);
|
|
449
|
+
this.scaleTextArray = [];
|
|
450
|
+
}
|
|
462
451
|
|
|
463
|
-
|
|
464
|
-
|
|
452
|
+
if (Object.prototype.toString.call(marks) === '[object Object]') {
|
|
453
|
+
const scaleArray = Object.keys(marks).map(item => Number(item));
|
|
454
|
+
const scaleTextArray = scaleArray.map(item => marks[item]);
|
|
465
455
|
|
|
466
|
-
|
|
467
|
-
|
|
456
|
+
this.isScale = scaleArray.length > 0;
|
|
457
|
+
this.scaleArray = calcPos(scaleArray);
|
|
458
|
+
this.scaleTextArray = scaleTextArray;
|
|
459
|
+
}
|
|
460
|
+
},
|
|
468
461
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
await this.getInitialInfo();
|
|
472
|
-
this.__inited = true;
|
|
473
|
-
this.bus.emit('initial');
|
|
474
|
-
},
|
|
462
|
+
setSingleBarWidth(value) {
|
|
463
|
+
const width = this.valueToPosition(value);
|
|
475
464
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
const { blockSize } = this;
|
|
479
|
-
const { theme, vertical } = this;
|
|
480
|
-
const halfBlock = Number(blockSize) / 2;
|
|
481
|
-
const { top, bottom, right, left } = line;
|
|
482
|
-
let maxRange = vertical ? bottom - top : right - left;
|
|
483
|
-
let initialLeft = vertical ? top : left;
|
|
484
|
-
let initialRight = vertical ? bottom : right;
|
|
485
|
-
if (initialLeft === 0 && initialRight === 0) return;
|
|
486
|
-
|
|
487
|
-
if ((theme) === 'capsule') {
|
|
488
|
-
maxRange = maxRange - Number(blockSize) - 6; // 6 是边框宽度
|
|
489
|
-
initialLeft -= halfBlock;
|
|
490
|
-
initialRight -= halfBlock;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
this.maxRange = maxRange;
|
|
494
|
-
this.initialLeft = initialLeft;
|
|
495
|
-
this.initialRight = initialRight;
|
|
496
|
-
},
|
|
465
|
+
this.lineBarWidth = `${width}px`;
|
|
466
|
+
},
|
|
497
467
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
Number(max),
|
|
505
|
-
);
|
|
506
|
-
return closestStep;
|
|
507
|
-
},
|
|
468
|
+
async init() {
|
|
469
|
+
if (this.__inited) return;
|
|
470
|
+
await this.getInitialInfo();
|
|
471
|
+
this.__inited = true;
|
|
472
|
+
this.bus.emit('initial');
|
|
473
|
+
},
|
|
508
474
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
475
|
+
async getInitialInfo() {
|
|
476
|
+
const line = await getRect(this, '#sliderLine');
|
|
477
|
+
const { blockSize } = this;
|
|
478
|
+
const { theme, vertical } = this;
|
|
479
|
+
const halfBlock = Number(blockSize) / 2;
|
|
480
|
+
const { top, bottom, right, left } = line;
|
|
481
|
+
let maxRange = vertical ? bottom - top : right - left;
|
|
482
|
+
let initialLeft = vertical ? top : left;
|
|
483
|
+
let initialRight = vertical ? bottom : right;
|
|
484
|
+
if (initialLeft === 0 && initialRight === 0) return;
|
|
485
|
+
|
|
486
|
+
if ((theme) === 'capsule') {
|
|
487
|
+
maxRange = maxRange - Number(blockSize) - 6; // 6 是边框宽度
|
|
488
|
+
initialLeft -= halfBlock;
|
|
489
|
+
initialRight -= halfBlock;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
this.maxRange = maxRange;
|
|
493
|
+
this.initialLeft = initialLeft;
|
|
494
|
+
this.initialRight = initialRight;
|
|
495
|
+
},
|
|
496
|
+
|
|
497
|
+
stepValue(value) {
|
|
498
|
+
const { step, min, max } = this;
|
|
499
|
+
const decimal = String(step).indexOf('.') > -1 ? String(step).length - String(step).indexOf('.') - 1 : 0;
|
|
500
|
+
const closestStep = trimSingleValue(
|
|
501
|
+
Number((Math.round(value / Number(step)) * Number(step)).toFixed(decimal)),
|
|
502
|
+
Number(min),
|
|
503
|
+
Number(max),
|
|
504
|
+
);
|
|
505
|
+
return closestStep;
|
|
506
|
+
},
|
|
526
507
|
|
|
527
|
-
|
|
508
|
+
// 点击滑动条的事件
|
|
509
|
+
async onSingleLineTap(e) {
|
|
510
|
+
await this.getInitialInfo();
|
|
511
|
+
const { disabled } = this;
|
|
512
|
+
if (disabled) return;
|
|
513
|
+
const isSingleLineTap = this.identifier[0] === -1; // 区分点击滑动条和单游标的滑动
|
|
514
|
+
if (isSingleLineTap) {
|
|
515
|
+
const [touch] = e.changedTouches;
|
|
516
|
+
this.identifier[0] = touch.identifier;
|
|
517
|
+
}
|
|
518
|
+
const value = await this.getSingleChangeValue(e);
|
|
519
|
+
|
|
520
|
+
if (isSingleLineTap) {
|
|
521
|
+
this.identifier[0] = -1;
|
|
522
|
+
}
|
|
523
|
+
this.triggerValue(value);
|
|
524
|
+
},
|
|
525
|
+
|
|
526
|
+
async getSingleChangeValue(e) {
|
|
528
527
|
// await this.getInitialInfo();
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
528
|
+
const { min, max, theme, vertical } = this;
|
|
529
|
+
const { initialLeft, maxRange, blockSize } = this;
|
|
530
|
+
const touch = e.changedTouches.find(item => item.identifier === this.identifier[0]);
|
|
531
|
+
if (!touch) return;
|
|
532
|
+
const pagePosition = this.getPagePosition(touch);
|
|
533
|
+
|
|
534
|
+
let offset = 0;
|
|
535
|
+
if ((theme) === 'capsule') {
|
|
536
|
+
offset = Number(blockSize);
|
|
537
|
+
if (vertical) {
|
|
538
|
+
}
|
|
539
|
+
offset += 3;
|
|
540
|
+
} else if (vertical) {
|
|
539
541
|
}
|
|
540
|
-
offset += 3;
|
|
541
|
-
} else if (vertical) {
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
const currentLeft = pagePosition - initialLeft - offset;
|
|
545
|
-
let value = 0;
|
|
546
|
-
if (currentLeft <= 0) {
|
|
547
|
-
value = Number(min);
|
|
548
|
-
} else if (currentLeft >= maxRange) {
|
|
549
|
-
value = Number(max);
|
|
550
|
-
} else {
|
|
551
|
-
value = (currentLeft / maxRange) * (Number(max) - Number(min)) + Number(min);
|
|
552
|
-
}
|
|
553
|
-
return this.stepValue(value);
|
|
554
|
-
},
|
|
555
542
|
|
|
556
|
-
|
|
543
|
+
const currentLeft = pagePosition - initialLeft - offset;
|
|
544
|
+
let value = 0;
|
|
545
|
+
if (currentLeft <= 0) {
|
|
546
|
+
value = Number(min);
|
|
547
|
+
} else if (currentLeft >= maxRange) {
|
|
548
|
+
value = Number(max);
|
|
549
|
+
} else {
|
|
550
|
+
value = (currentLeft / maxRange) * (Number(max) - Number(min)) + Number(min);
|
|
551
|
+
}
|
|
552
|
+
return this.stepValue(value);
|
|
553
|
+
},
|
|
554
|
+
|
|
555
|
+
/**
|
|
557
556
|
* 将位置转换为值
|
|
558
557
|
*
|
|
559
558
|
* @param {number} posValue 位置数据
|
|
@@ -561,157 +560,158 @@ export default uniComponent({
|
|
|
561
560
|
* @return {number}
|
|
562
561
|
* @memberof Slider
|
|
563
562
|
*/
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
563
|
+
convertPosToValue(posValue, dir) {
|
|
564
|
+
const { maxRange } = this;
|
|
565
|
+
const { max, min } = this;
|
|
566
|
+
return dir === 0
|
|
567
|
+
? (posValue / maxRange) * (Number(max) - Number(min)) + Number(min)
|
|
568
|
+
: Number(max) - (posValue / maxRange) * (Number(max) - Number(min));
|
|
569
|
+
},
|
|
571
570
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
const [touch] = e.changedTouches;
|
|
579
|
-
const pagePosition = this.getPagePosition(touch);
|
|
580
|
-
const halfBlock = (theme) === 'capsule' ? Number(blockSize) / 2 : 0;
|
|
581
|
-
|
|
582
|
-
const currentLeft = pagePosition - initialLeft;
|
|
583
|
-
const currentRight = -(pagePosition - initialRight);
|
|
584
|
-
if (currentLeft < 0 || currentRight > maxRange + Number(blockSize)) return;
|
|
585
|
-
|
|
586
|
-
Promise.all([getRect(this, '#leftDot'), getRect(this, '#rightDot')]).then(([leftDot, rightDot]) => {
|
|
587
|
-
const pageScrollTop = this.pageScrollTop || 0;
|
|
588
|
-
// 点击处-halfblock 与 leftDot左侧的距离(绝对值)
|
|
589
|
-
const leftDotPosition = vertical ? leftDot.top + pageScrollTop : leftDot.left;
|
|
590
|
-
const distanceLeft = Math.abs(pagePosition - leftDotPosition - halfBlock);
|
|
591
|
-
// 点击处-halfblock 与 rightDot左侧的距离(绝对值)
|
|
592
|
-
const rightDotPosition = vertical ? rightDot.top + pageScrollTop : rightDot.left;
|
|
593
|
-
const distanceRight = Math.abs(rightDotPosition - pagePosition + halfBlock);
|
|
594
|
-
// 哪个绝对值小就移动哪个Dot
|
|
595
|
-
const isMoveLeft = distanceLeft < distanceRight;
|
|
571
|
+
// 点击范围选择滑动条的事件
|
|
572
|
+
onLineTap(e) {
|
|
573
|
+
const { disabled, theme, vertical } = this;
|
|
574
|
+
const { initialLeft, initialRight, maxRange, blockSize } = this;
|
|
575
|
+
if (disabled) return;
|
|
596
576
|
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
577
|
+
const [touch] = e.changedTouches;
|
|
578
|
+
const pagePosition = this.getPagePosition(touch);
|
|
579
|
+
const halfBlock = (theme) === 'capsule' ? Number(blockSize) / 2 : 0;
|
|
580
|
+
|
|
581
|
+
const currentLeft = pagePosition - initialLeft;
|
|
582
|
+
const currentRight = -(pagePosition - initialRight);
|
|
583
|
+
if (currentLeft < 0 || currentRight > maxRange + Number(blockSize)) return;
|
|
584
|
+
|
|
585
|
+
Promise.all([getRect(this, '#leftDot'), getRect(this, '#rightDot')]).then(([leftDot, rightDot]) => {
|
|
586
|
+
const pageScrollTop = this.pageScrollTop || 0;
|
|
587
|
+
// 点击处-halfblock 与 leftDot左侧的距离(绝对值)
|
|
588
|
+
const leftDotPosition = vertical ? leftDot.top + pageScrollTop : leftDot.left;
|
|
589
|
+
const distanceLeft = Math.abs(pagePosition - leftDotPosition - halfBlock);
|
|
590
|
+
// 点击处-halfblock 与 rightDot左侧的距离(绝对值)
|
|
591
|
+
const rightDotPosition = vertical ? rightDot.top + pageScrollTop : rightDot.left;
|
|
592
|
+
const distanceRight = Math.abs(rightDotPosition - pagePosition + halfBlock);
|
|
593
|
+
// 哪个绝对值小就移动哪个Dot
|
|
594
|
+
const isMoveLeft = distanceLeft < distanceRight;
|
|
595
|
+
|
|
596
|
+
let offset = 0;
|
|
597
|
+
if ((theme) === 'capsule') {
|
|
598
|
+
offset = Number(blockSize);
|
|
599
|
+
if (vertical) {
|
|
600
|
+
offset *= 2;
|
|
601
|
+
}
|
|
602
|
+
offset += 6;
|
|
603
|
+
} else if (vertical) {
|
|
604
|
+
offset = Number(blockSize);
|
|
602
605
|
}
|
|
603
|
-
offset += 6;
|
|
604
|
-
} else if (vertical) {
|
|
605
|
-
offset = Number(blockSize);
|
|
606
|
-
}
|
|
607
606
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
607
|
+
if (isMoveLeft) {
|
|
608
|
+
// 当前leftdot中心 + 左侧偏移量 = 目标左侧中心距离
|
|
609
|
+
const left = pagePosition - initialLeft - offset;
|
|
610
|
+
const leftValue = this.convertPosToValue(left, 0);
|
|
611
|
+
this.triggerValue([this.stepValue(leftValue), this.innerValue[1]]);
|
|
612
|
+
} else {
|
|
613
|
+
let right = -(pagePosition - initialRight);
|
|
614
|
+
if (vertical) {
|
|
615
|
+
right += offset / 2;
|
|
616
|
+
}
|
|
617
|
+
const rightValue = this.convertPosToValue(right, 1);
|
|
618
|
+
|
|
619
|
+
this.triggerValue([this.innerValue[0], this.stepValue(rightValue)]);
|
|
617
620
|
}
|
|
618
|
-
|
|
621
|
+
});
|
|
622
|
+
},
|
|
619
623
|
|
|
620
|
-
|
|
624
|
+
async onTouchStart(e) {
|
|
625
|
+
await this.getInitialInfo();
|
|
626
|
+
this.$emit('dragstart', { e });
|
|
627
|
+
const [touch] = e.changedTouches;
|
|
628
|
+
if (e.currentTarget.id === 'rightDot') {
|
|
629
|
+
this.identifier[1] = touch.identifier;
|
|
630
|
+
} else {
|
|
631
|
+
this.identifier[0] = touch.identifier;
|
|
621
632
|
}
|
|
622
|
-
}
|
|
623
|
-
},
|
|
633
|
+
},
|
|
624
634
|
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
if (e.currentTarget.id === 'rightDot') {
|
|
630
|
-
this.identifier[1] = touch.identifier;
|
|
631
|
-
} else {
|
|
632
|
-
this.identifier[0] = touch.identifier;
|
|
633
|
-
}
|
|
634
|
-
},
|
|
635
|
+
onTouchMoveLeft(e) {
|
|
636
|
+
const { disabled, theme } = this;
|
|
637
|
+
const { initialLeft, innerValue, blockSize } = this;
|
|
638
|
+
if (disabled) return;
|
|
635
639
|
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
+
const touch = e.changedTouches.find(item => item.identifier === this.identifier[0]);
|
|
641
|
+
if (!touch) return;
|
|
642
|
+
const pagePosition = this.getPagePosition(touch);
|
|
643
|
+
let offset = 0;
|
|
644
|
+
if ((theme) === 'capsule') {
|
|
645
|
+
offset = Number(blockSize) + 3;
|
|
646
|
+
}
|
|
647
|
+
const currentLeft = pagePosition - initialLeft - offset;
|
|
640
648
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
const pagePosition = this.getPagePosition(touch);
|
|
644
|
-
let offset = 0;
|
|
645
|
-
if ((theme) === 'capsule') {
|
|
646
|
-
offset = Number(blockSize) + 3;
|
|
647
|
-
}
|
|
648
|
-
const currentLeft = pagePosition - initialLeft - offset;
|
|
649
|
+
const newData = [...(innerValue)];
|
|
650
|
+
const leftValue = this.convertPosToValue(currentLeft, 0);
|
|
649
651
|
|
|
650
|
-
|
|
651
|
-
const leftValue = this.convertPosToValue(currentLeft, 0);
|
|
652
|
+
newData[0] = this.stepValue(leftValue);
|
|
652
653
|
|
|
653
|
-
|
|
654
|
+
this.triggerValue(newData);
|
|
655
|
+
},
|
|
654
656
|
|
|
655
|
-
|
|
656
|
-
|
|
657
|
+
onTouchMoveRight(e) {
|
|
658
|
+
const { disabled, vertical, theme } = this;
|
|
659
|
+
const { initialRight, innerValue } = this;
|
|
660
|
+
if (disabled) return;
|
|
657
661
|
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
const { initialRight, innerValue } = this;
|
|
661
|
-
if (disabled) return;
|
|
662
|
+
const touch = e.changedTouches.find(item => item.identifier === this.identifier[1]);
|
|
663
|
+
if (!touch) return;
|
|
662
664
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
+
const pagePosition = this.getPagePosition(touch);
|
|
666
|
+
let offset = 0;
|
|
667
|
+
if ((theme) === 'capsule') {
|
|
668
|
+
offset -= 3;
|
|
669
|
+
} else if (vertical) {
|
|
670
|
+
}
|
|
671
|
+
const currentRight = -(pagePosition - initialRight - offset);
|
|
665
672
|
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
offset -= 3;
|
|
670
|
-
} else if (vertical) {
|
|
671
|
-
}
|
|
672
|
-
const currentRight = -(pagePosition - initialRight - offset);
|
|
673
|
+
const newData = [...(innerValue)];
|
|
674
|
+
const rightValue = this.convertPosToValue(currentRight, 1);
|
|
675
|
+
newData[1] = this.stepValue(rightValue);
|
|
673
676
|
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
newData[1] = this.stepValue(rightValue);
|
|
677
|
+
this.triggerValue(newData);
|
|
678
|
+
},
|
|
677
679
|
|
|
678
|
-
|
|
679
|
-
|
|
680
|
+
setLineStyle(left, right) {
|
|
681
|
+
const { theme } = this;
|
|
682
|
+
const { blockSize, maxRange } = this;
|
|
683
|
+
const halfBlock = (theme) === 'capsule' ? Number(blockSize) / 2 : 0;
|
|
684
|
+
const [a, b] = this.innerValue ;
|
|
685
|
+
const cut = v => parseInt(v, 10);
|
|
680
686
|
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
const { blockSize, maxRange } = this;
|
|
684
|
-
const halfBlock = (theme) === 'capsule' ? Number(blockSize) / 2 : 0;
|
|
685
|
-
const [a, b] = this.innerValue ;
|
|
686
|
-
const cut = v => parseInt(v, 10);
|
|
687
|
-
|
|
688
|
-
this.dotTopValue = [a, b];
|
|
689
|
-
this.realLabel = [this.getLabelByValue(a, 'start'), this.getLabelByValue(b, 'end')];
|
|
690
|
-
|
|
691
|
-
if (left + right <= maxRange) {
|
|
692
|
-
this.lineLeft = cut(left + halfBlock);
|
|
693
|
-
this.lineRight = cut(right + halfBlock);
|
|
694
|
-
} else {
|
|
695
|
-
this.lineLeft = cut(maxRange + halfBlock - right);
|
|
696
|
-
this.lineRight = cut(maxRange - left + halfBlock * 1.5);
|
|
697
|
-
}
|
|
698
|
-
},
|
|
687
|
+
this.dotTopValue = [a, b];
|
|
688
|
+
this.realLabel = [this.getLabelByValue(a, 'start'), this.getLabelByValue(b, 'end')];
|
|
699
689
|
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
690
|
+
if (left + right <= maxRange) {
|
|
691
|
+
this.lineLeft = cut(left + halfBlock);
|
|
692
|
+
this.lineRight = cut(right + halfBlock);
|
|
693
|
+
} else {
|
|
694
|
+
this.lineLeft = cut(maxRange + halfBlock - right);
|
|
695
|
+
this.lineRight = cut(maxRange - left + halfBlock * 1.5);
|
|
696
|
+
}
|
|
697
|
+
},
|
|
708
698
|
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
699
|
+
onTouchEnd(e) {
|
|
700
|
+
this.$emit('dragend', { e, value: this.innerValue });
|
|
701
|
+
if (e.currentTarget.id === 'rightDot') {
|
|
702
|
+
this.identifier[1] = -1;
|
|
703
|
+
} else {
|
|
704
|
+
this.identifier[0] = -1;
|
|
705
|
+
}
|
|
706
|
+
},
|
|
707
|
+
|
|
708
|
+
getPagePosition(touch) {
|
|
709
|
+
const { clientX, clientY } = touch;
|
|
710
|
+
const { vertical } = this;
|
|
711
|
+
return vertical ? clientY : clientX;
|
|
712
|
+
},
|
|
713
713
|
},
|
|
714
|
-
},
|
|
715
|
-
}
|
|
714
|
+
}),
|
|
715
|
+
};
|
|
716
716
|
</script>
|
|
717
717
|
<style scoped src="./slider.css"></style>
|