hy-app 0.3.0 → 0.3.2
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/README.md +6 -3
- package/common/shakeService.ts +31 -29
- package/components/avatar.zip +0 -0
- package/components/hy-action-sheet/hy-action-sheet.vue +71 -46
- package/components/hy-address-picker/hy-address-picker.vue +94 -83
- package/components/hy-avatar/hy-avatar.vue +84 -85
- package/components/hy-back-top/hy-back-top.vue +8 -6
- package/components/hy-badge/hy-badge.vue +47 -46
- package/components/hy-button/hy-button.vue +117 -93
- package/components/hy-calendar/hy-calendar.vue +168 -160
- package/components/hy-card/hy-card.vue +50 -43
- package/components/hy-card/typing.d.ts +33 -32
- package/components/hy-cell/hy-cell.vue +73 -51
- package/components/hy-check-button/hy-check-button.vue +54 -47
- package/components/hy-checkbox/hy-checkbox.vue +97 -105
- package/components/hy-code-input/hy-code-input.vue +80 -89
- package/components/hy-config-provider/hy-config-provider.vue +20 -21
- package/components/hy-count-down/hy-count-down.vue +66 -67
- package/components/hy-count-to/hy-count-to.vue +105 -99
- package/components/hy-count-to/typing.d.ts +13 -12
- package/components/hy-datetime-picker/hy-datetime-picker.vue +261 -253
- package/components/hy-datetime-picker/typing.d.ts +42 -40
- package/components/hy-divider/hy-divider.vue +68 -73
- package/components/hy-dropdown/hy-dropdown.vue +20 -19
- package/components/hy-dropdown-item/hy-dropdown-item.vue +66 -61
- package/components/hy-dropdown-item/typing.d.ts +9 -9
- package/components/hy-empty/hy-empty.vue +42 -42
- package/components/hy-flex/hy-flex.vue +99 -0
- package/components/hy-flex/index.scss +8 -0
- package/components/hy-flex/typing.d.ts +23 -0
- package/components/hy-float-button/hy-float-button.vue +218 -210
- package/components/hy-folding-panel/hy-folding-panel.vue +32 -33
- package/components/hy-form/hy-form.vue +264 -252
- package/components/hy-form/typing.d.ts +4 -0
- package/components/hy-form-group/hy-form-group.vue +114 -183
- package/components/hy-form-item/hy-form-item.vue +12 -10
- package/components/hy-form-item/index.scss +2 -2
- package/components/hy-form-item/typing.d.ts +3 -6
- package/components/hy-grid/hy-grid.vue +44 -43
- package/components/hy-icon/hy-icon.vue +61 -67
- package/components/hy-image/hy-image.vue +112 -88
- package/components/hy-image/typing.d.ts +27 -23
- package/components/hy-input/hy-input.vue +157 -127
- package/components/hy-input/typing.d.ts +53 -47
- package/components/hy-line/hy-line.vue +26 -26
- package/components/hy-line-progress/hy-line-progress.vue +42 -35
- package/components/hy-list/hy-list.vue +76 -85
- package/components/hy-loading/hy-loading.vue +26 -23
- package/components/hy-login/TheUserLogin.vue +1 -1
- package/components/hy-menu/hy-menu.vue +48 -43
- package/components/hy-menu/typing.d.ts +18 -17
- package/components/hy-modal/hy-modal.vue +39 -35
- package/components/hy-navbar/hy-navbar.vue +25 -25
- package/components/hy-navbar/typing.d.ts +24 -22
- package/components/hy-notice-bar/hy-notice-bar.vue +26 -27
- package/components/hy-notify/hy-notify.vue +53 -53
- package/components/hy-number-step/hy-number-step.vue +134 -146
- package/components/hy-number-step/typing.d.ts +35 -35
- package/components/hy-overlay/hy-overlay.vue +23 -21
- package/components/hy-pagination/hy-pagination.vue +41 -36
- package/components/hy-picker/hy-picker.vue +184 -154
- package/components/hy-picker/typing.d.ts +39 -39
- package/components/hy-popover/hy-popover.vue +97 -77
- package/components/hy-popup/hy-popup.vue +107 -98
- package/components/hy-price/hy-price.vue +38 -34
- package/components/hy-qrcode/hy-qrcode.vue +50 -51
- package/components/hy-radio/hy-radio.vue +101 -113
- package/components/hy-rate/hy-rate.vue +107 -88
- package/components/hy-read-more/hy-read-more.vue +64 -49
- package/components/hy-scroll-list/hy-scroll-list.vue +45 -48
- package/components/hy-search/hy-search.vue +73 -66
- package/components/hy-search/typing.d.ts +36 -35
- package/components/hy-signature/hy-signature.vue +282 -240
- package/components/hy-slider/hy-slider.vue +195 -153
- package/components/hy-slider/typing.d.ts +21 -21
- package/components/hy-steps/hy-steps.vue +118 -90
- package/components/hy-steps/index.scss +31 -21
- package/components/hy-submit-bar/hy-submit-bar.vue +61 -70
- package/components/hy-subsection/hy-subsection.vue +99 -102
- package/components/hy-subsection/typing.d.ts +19 -19
- package/components/hy-swipe-action/hy-swipe-action.vue +131 -118
- package/components/hy-swiper/hy-swiper.vue +85 -71
- package/components/hy-switch/hy-switch.vue +67 -72
- package/components/hy-switch/typing.d.ts +21 -19
- package/components/hy-tabs/hy-tabs.vue +168 -113
- package/components/hy-tag/hy-tag.vue +90 -86
- package/components/hy-tag/typing.d.ts +26 -21
- package/components/hy-text/hy-text.vue +119 -111
- package/components/hy-textarea/hy-textarea.vue +100 -93
- package/components/hy-textarea/typing.d.ts +36 -31
- package/components/hy-toast/hy-toast.vue +77 -67
- package/components/hy-tooltip/hy-tooltip.vue +109 -91
- package/components/hy-transition/hy-transition.vue +62 -66
- package/components/hy-upload/hy-upload.vue +294 -152
- package/components/hy-upload/typing.d.ts +41 -36
- package/components/hy-warn/hy-warn.vue +34 -27
- package/components/hy-waterfall/hy-waterfall.vue +83 -74
- package/components/hy-watermark/hy-watermark.vue +134 -115
- package/components/index.ts +1 -1
- package/composables/usePopover.ts +236 -221
- package/composables/useQueue.ts +53 -52
- package/global.d.ts +1 -0
- package/package.json +2 -2
- package/store/index.ts +9 -1
- package/theme.scss +5 -5
- package/typing/index.ts +0 -1
- package/typing/modules/common.d.ts +0 -2
- package/web-types.json +1 -1
|
@@ -4,14 +4,17 @@
|
|
|
4
4
|
<view
|
|
5
5
|
ref="hy-slider-inner"
|
|
6
6
|
class="hy-slider-inner"
|
|
7
|
-
@
|
|
7
|
+
@tap="onClick"
|
|
8
8
|
@onTouchStart="onTouchStart2($event, 1)"
|
|
9
9
|
@touchmove="onTouchMove2($event, 1)"
|
|
10
10
|
@touchend="onTouchEnd2($event, 1)"
|
|
11
11
|
@touchcancel="onTouchEnd2($event, 1)"
|
|
12
12
|
:class="[disabled ? 'hy-slider--disabled' : '']"
|
|
13
13
|
:style="{
|
|
14
|
-
height:
|
|
14
|
+
height:
|
|
15
|
+
isRange && showValue
|
|
16
|
+
? addUnit(getPx(blockSize) + 24)
|
|
17
|
+
: addUnit(blockSize),
|
|
15
18
|
}"
|
|
16
19
|
>
|
|
17
20
|
<view
|
|
@@ -25,7 +28,7 @@
|
|
|
25
28
|
]"
|
|
26
29
|
></view>
|
|
27
30
|
<view
|
|
28
|
-
@
|
|
31
|
+
@tap="onClick"
|
|
29
32
|
class="hy-slider__gap"
|
|
30
33
|
:style="[
|
|
31
34
|
barStyle,
|
|
@@ -118,7 +121,9 @@
|
|
|
118
121
|
></view>
|
|
119
122
|
</view>
|
|
120
123
|
</view>
|
|
121
|
-
<view class="hy-slider__show-value" v-if="showValue && !isRange">{{
|
|
124
|
+
<view class="hy-slider__show-value" v-if="showValue && !isRange">{{
|
|
125
|
+
modelValue
|
|
126
|
+
}}</view>
|
|
122
127
|
</template>
|
|
123
128
|
<slider
|
|
124
129
|
class="hy-slider__native"
|
|
@@ -129,7 +134,7 @@
|
|
|
129
134
|
:value="modelValue"
|
|
130
135
|
:activeColor="activeColor"
|
|
131
136
|
:backgroundColor="inactiveColor"
|
|
132
|
-
:blockSize="
|
|
137
|
+
:blockSize="blockSize"
|
|
133
138
|
:blockColor="blockColor"
|
|
134
139
|
:showValue="showValue"
|
|
135
140
|
:disabled="disabled"
|
|
@@ -141,26 +146,37 @@
|
|
|
141
146
|
|
|
142
147
|
<script lang="ts">
|
|
143
148
|
export default {
|
|
144
|
-
name:
|
|
149
|
+
name: "hy-slider",
|
|
145
150
|
options: {
|
|
146
151
|
addGlobalClass: true,
|
|
147
152
|
virtualHost: true,
|
|
148
|
-
styleIsolation:
|
|
153
|
+
styleIsolation: "shared",
|
|
149
154
|
},
|
|
150
|
-
}
|
|
155
|
+
};
|
|
151
156
|
</script>
|
|
152
157
|
|
|
153
158
|
<script setup lang="ts">
|
|
154
|
-
import {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
159
|
+
import {
|
|
160
|
+
computed,
|
|
161
|
+
getCurrentInstance,
|
|
162
|
+
onMounted,
|
|
163
|
+
ref,
|
|
164
|
+
toRefs,
|
|
165
|
+
watch,
|
|
166
|
+
} from "vue";
|
|
167
|
+
import type { CSSProperties, PropType } from "vue";
|
|
168
|
+
import { addUnit, error, getRect, getPx } from "../../utils";
|
|
169
|
+
import type { ISliderEmits } from "./typing";
|
|
170
|
+
import type {
|
|
171
|
+
MovableViewOnChange,
|
|
172
|
+
SliderOnChangingEvent,
|
|
173
|
+
} from "@uni-helper/uni-types";
|
|
158
174
|
|
|
159
175
|
/**
|
|
160
176
|
* 一般用于表单中,手动选择一个区间范围的场景。
|
|
161
177
|
* @displayName hy-slider
|
|
162
178
|
*/
|
|
163
|
-
defineOptions({})
|
|
179
|
+
defineOptions({});
|
|
164
180
|
|
|
165
181
|
// const props = withDefaults(defineProps<IProps>(), defaultProps);
|
|
166
182
|
const props = defineProps({
|
|
@@ -171,7 +187,7 @@ const props = defineProps({
|
|
|
171
187
|
},
|
|
172
188
|
/** 滑块的大小,取值范围为 12 - 28 */
|
|
173
189
|
blockSize: {
|
|
174
|
-
type:
|
|
190
|
+
type: Number,
|
|
175
191
|
default: 18,
|
|
176
192
|
},
|
|
177
193
|
/** 最小值 */
|
|
@@ -235,261 +251,287 @@ const props = defineProps({
|
|
|
235
251
|
},
|
|
236
252
|
/** 自定义外部类名 */
|
|
237
253
|
customClass: String,
|
|
238
|
-
})
|
|
239
|
-
const
|
|
240
|
-
const emit = defineEmits<ISliderEmits>()
|
|
254
|
+
});
|
|
255
|
+
const emit = defineEmits<ISliderEmits>();
|
|
241
256
|
|
|
242
|
-
const startX = ref(0)
|
|
243
|
-
const status = ref(
|
|
244
|
-
const newValue = ref(0)
|
|
245
|
-
const distanceX = ref(0)
|
|
246
|
-
const startValue0 = ref(0)
|
|
247
|
-
const startValue = ref(0)
|
|
248
|
-
const barStyle0 = ref<CSSProperties>()
|
|
249
|
-
const barStyle = ref<CSSProperties>()
|
|
257
|
+
const startX = ref(0);
|
|
258
|
+
const status = ref("end");
|
|
259
|
+
const newValue = ref(0);
|
|
260
|
+
const distanceX = ref(0);
|
|
261
|
+
const startValue0 = ref(0);
|
|
262
|
+
const startValue = ref(0);
|
|
263
|
+
const barStyle0 = ref<CSSProperties>();
|
|
264
|
+
const barStyle = ref<CSSProperties>();
|
|
250
265
|
const sliderRect = ref<UniNamespace.NodeInfo>({
|
|
251
266
|
left: 0,
|
|
252
267
|
width: 0,
|
|
253
|
-
})
|
|
254
|
-
const instance = getCurrentInstance()
|
|
268
|
+
});
|
|
269
|
+
const instance = getCurrentInstance();
|
|
255
270
|
|
|
256
271
|
const blockLeft = computed(() => {
|
|
257
|
-
return (
|
|
272
|
+
return (
|
|
273
|
+
slideWidth: string | number | undefined,
|
|
274
|
+
blockWidth: string | number,
|
|
275
|
+
): string => {
|
|
258
276
|
if (slideWidth) {
|
|
259
|
-
return addUnit(getPx(slideWidth) + getPx(blockWidth) / 2)
|
|
277
|
+
return addUnit(getPx(slideWidth) + getPx(blockWidth) / 2);
|
|
260
278
|
}
|
|
261
|
-
return
|
|
262
|
-
}
|
|
263
|
-
})
|
|
279
|
+
return "0px";
|
|
280
|
+
};
|
|
281
|
+
});
|
|
264
282
|
|
|
265
283
|
watch(
|
|
266
|
-
() => modelValue
|
|
284
|
+
() => props.modelValue,
|
|
267
285
|
(newValue) => {
|
|
268
286
|
// 只有在非滑动状态时,才可以通过value更新滑块值,这里监听,是为了让用户触发
|
|
269
|
-
if (status.value ===
|
|
287
|
+
if (status.value === "end") updateValue(newValue, false);
|
|
270
288
|
},
|
|
271
|
-
)
|
|
289
|
+
);
|
|
272
290
|
|
|
273
291
|
watch(
|
|
274
|
-
() => rangeValue
|
|
292
|
+
() => props.rangeValue,
|
|
275
293
|
(newValue) => {
|
|
276
|
-
if (status.value ===
|
|
277
|
-
updateValue(newValue[0], false, 0)
|
|
278
|
-
updateValue(newValue[1], false, 1)
|
|
294
|
+
if (status.value === "end") {
|
|
295
|
+
updateValue(newValue[0], false, 0);
|
|
296
|
+
updateValue(newValue[1], false, 1);
|
|
279
297
|
}
|
|
280
298
|
},
|
|
281
299
|
{ deep: true },
|
|
282
|
-
)
|
|
300
|
+
);
|
|
283
301
|
|
|
284
302
|
onMounted(async () => {
|
|
285
303
|
// 获取滑块条的尺寸信息
|
|
286
|
-
if (!useNative
|
|
304
|
+
if (!props.useNative) {
|
|
287
305
|
// #ifndef APP-NVUE
|
|
288
|
-
sliderRect.value = (await getRect(
|
|
306
|
+
sliderRect.value = (await getRect(
|
|
307
|
+
".hy-slider__base",
|
|
308
|
+
false,
|
|
309
|
+
instance,
|
|
310
|
+
)) as UniNamespace.NodeInfo;
|
|
289
311
|
// console.log('sliderRect', sliderRect.value)
|
|
290
312
|
if (sliderRect.value.width == 0) {
|
|
291
|
-
error(
|
|
313
|
+
error("如在弹窗等元素中使用,请使用v-if来显示滑块,否则无法计算长度。");
|
|
292
314
|
}
|
|
293
|
-
init()
|
|
315
|
+
init();
|
|
294
316
|
// #endif
|
|
295
317
|
}
|
|
296
|
-
})
|
|
318
|
+
});
|
|
297
319
|
|
|
298
320
|
const init = () => {
|
|
299
|
-
if (isRange
|
|
300
|
-
updateValue(rangeValue
|
|
301
|
-
updateValue(rangeValue
|
|
321
|
+
if (props.isRange) {
|
|
322
|
+
updateValue(props.rangeValue[0], false, 0);
|
|
323
|
+
updateValue(props.rangeValue[1], false, 1);
|
|
302
324
|
} else {
|
|
303
|
-
updateValue(modelValue
|
|
325
|
+
updateValue(props.modelValue, false);
|
|
304
326
|
}
|
|
305
|
-
}
|
|
327
|
+
};
|
|
328
|
+
|
|
306
329
|
// native拖动过程中触发
|
|
307
|
-
const changingHandler = (e:
|
|
308
|
-
const { value } = e.detail
|
|
330
|
+
const changingHandler = (e: SliderOnChangingEvent) => {
|
|
331
|
+
const { value } = e.detail;
|
|
309
332
|
// 更新v-model的值
|
|
310
|
-
emit(
|
|
333
|
+
emit("update:modelValue", value);
|
|
311
334
|
// 触发事件
|
|
312
|
-
emit(
|
|
313
|
-
}
|
|
335
|
+
emit("changing", value);
|
|
336
|
+
};
|
|
337
|
+
|
|
314
338
|
// native滑动结束时触发
|
|
315
|
-
const changeHandler = (e:
|
|
316
|
-
const { value } = e.detail
|
|
339
|
+
const changeHandler = (e: SliderOnChangingEvent) => {
|
|
340
|
+
const { value } = e.detail;
|
|
317
341
|
// 更新v-model的值
|
|
318
|
-
emit(
|
|
342
|
+
emit("update:modelValue", value);
|
|
319
343
|
// 触发事件
|
|
320
|
-
emit(
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
344
|
+
emit("change", value);
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
const onTouchStart = (e: TouchEvent, index = 1) => {
|
|
348
|
+
if (props.disabled) return;
|
|
349
|
+
startX.value = 0;
|
|
325
350
|
// 触摸点集
|
|
326
|
-
let touches =
|
|
351
|
+
let touches = e.touches[0];
|
|
327
352
|
// 触摸点到屏幕左边的距离
|
|
328
|
-
startX.value = touches.clientX
|
|
353
|
+
startX.value = touches.clientX;
|
|
329
354
|
// 此处的this.modelValue虽为props值,但是通过$emit('update:modelValue')进行了修改
|
|
330
|
-
if (isRange
|
|
331
|
-
startValue0.value = format(rangeValue
|
|
332
|
-
startValue.value = format(rangeValue
|
|
355
|
+
if (props.isRange) {
|
|
356
|
+
startValue0.value = format(props.rangeValue[0], 0);
|
|
357
|
+
startValue.value = format(props.rangeValue[1], 1);
|
|
333
358
|
} else {
|
|
334
|
-
startValue.value = format(modelValue
|
|
359
|
+
startValue.value = format(props.modelValue);
|
|
335
360
|
}
|
|
336
361
|
// 标示当前的状态为开始触摸滑动
|
|
337
|
-
status.value =
|
|
362
|
+
status.value = "start";
|
|
338
363
|
|
|
339
|
-
let clientX = 0
|
|
364
|
+
let clientX = 0;
|
|
340
365
|
// #ifndef APP-NVUE
|
|
341
|
-
clientX = touches.clientX
|
|
366
|
+
clientX = touches.clientX;
|
|
342
367
|
// #endif
|
|
343
368
|
// #ifdef APP-NVUE
|
|
344
|
-
clientX = touches.screenX
|
|
369
|
+
clientX = touches.screenX;
|
|
345
370
|
// #endif
|
|
346
|
-
distanceX.value = clientX - sliderRect.value.left
|
|
371
|
+
distanceX.value = clientX - sliderRect.value.left!;
|
|
347
372
|
// 获得移动距离对整个滑块的值,此为带有多位小数的值,不能用此更新视图
|
|
348
373
|
// 否则造成通信阻塞,需要每改变一个step值时修改一次视图
|
|
349
|
-
newValue.value =
|
|
350
|
-
|
|
374
|
+
newValue.value =
|
|
375
|
+
(distanceX.value / sliderRect.value.width!) * (props.max - props.min) +
|
|
376
|
+
props.min;
|
|
377
|
+
status.value = "moving";
|
|
351
378
|
// 发出moving事件
|
|
352
|
-
let $crtFmtValue = updateValue(newValue.value, true, index)
|
|
353
|
-
emit(
|
|
354
|
-
}
|
|
355
|
-
const onTouchMove = (
|
|
356
|
-
if (disabled
|
|
379
|
+
let $crtFmtValue = updateValue(newValue.value, true, index);
|
|
380
|
+
emit("changing", $crtFmtValue);
|
|
381
|
+
};
|
|
382
|
+
const onTouchMove = (e: TouchEvent, index = 1) => {
|
|
383
|
+
if (props.disabled) return;
|
|
357
384
|
// 连续触摸的过程会一直触发本方法,但只有手指触发且移动了才被认为是拖动了,才发出事件
|
|
358
385
|
// 触摸后第一次移动已经将status设置为moving状态,故触摸第二次移动不会触发本事件
|
|
359
|
-
if (status.value ==
|
|
360
|
-
let touches =
|
|
386
|
+
if (status.value == "start") emit("start");
|
|
387
|
+
let touches = e.touches[0];
|
|
361
388
|
// console.log('touchs', touches)
|
|
362
389
|
// 滑块的左边不一定跟屏幕左边接壤,所以需要减去最外层父元素的左边值
|
|
363
|
-
let clientX = 0
|
|
390
|
+
let clientX = 0;
|
|
364
391
|
// #ifndef APP-NVUE
|
|
365
|
-
clientX = touches.clientX
|
|
392
|
+
clientX = touches.clientX;
|
|
366
393
|
// #endif
|
|
367
394
|
// #ifdef APP-NVUE
|
|
368
|
-
clientX = touches.screenX
|
|
395
|
+
clientX = touches.screenX;
|
|
369
396
|
// #endif
|
|
370
|
-
distanceX.value = clientX - sliderRect.value.left
|
|
397
|
+
distanceX.value = clientX - sliderRect.value.left!;
|
|
371
398
|
// 获得移动距离对整个滑块的值,此为带有多位小数的值,不能用此更新视图
|
|
372
399
|
// 否则造成通信阻塞,需要每改变一个step值时修改一次视图
|
|
373
|
-
newValue.value =
|
|
374
|
-
|
|
400
|
+
newValue.value =
|
|
401
|
+
(distanceX.value / sliderRect.value.width!) * (props.max - props.min) +
|
|
402
|
+
props.min;
|
|
403
|
+
status.value = "moving";
|
|
375
404
|
// 发出moving事件
|
|
376
|
-
let $crtFmtValue = updateValue(newValue.value, true, index)
|
|
377
|
-
emit(
|
|
378
|
-
}
|
|
379
|
-
const onTouchEnd = (
|
|
380
|
-
if (disabled
|
|
381
|
-
if (status.value ===
|
|
382
|
-
let $crtFmtValue = updateValue(newValue.value, false, index)
|
|
383
|
-
emit(
|
|
405
|
+
let $crtFmtValue = updateValue(newValue.value, true, index);
|
|
406
|
+
emit("changing", $crtFmtValue);
|
|
407
|
+
};
|
|
408
|
+
const onTouchEnd = (e: TouchEvent, index = 1) => {
|
|
409
|
+
if (props.disabled) return;
|
|
410
|
+
if (status.value === "moving") {
|
|
411
|
+
let $crtFmtValue = updateValue(newValue.value, false, index);
|
|
412
|
+
emit("change", $crtFmtValue);
|
|
384
413
|
}
|
|
385
|
-
status.value =
|
|
386
|
-
}
|
|
387
|
-
const onTouchStart2 = (
|
|
388
|
-
if (!isRange
|
|
414
|
+
status.value = "end";
|
|
415
|
+
};
|
|
416
|
+
const onTouchStart2 = (e: TouchEvent, index = 1) => {
|
|
417
|
+
if (!props.isRange) {
|
|
389
418
|
// this.onChangeStart(event, index);
|
|
390
419
|
}
|
|
391
|
-
}
|
|
392
|
-
const onTouchMove2 = (
|
|
393
|
-
if (!isRange
|
|
420
|
+
};
|
|
421
|
+
const onTouchMove2 = (e: TouchEvent, index = 1) => {
|
|
422
|
+
if (!props.isRange) {
|
|
394
423
|
// this.onTouchMove(event, index);
|
|
395
424
|
}
|
|
396
|
-
}
|
|
397
|
-
const onTouchEnd2 = (
|
|
398
|
-
if (!isRange
|
|
425
|
+
};
|
|
426
|
+
const onTouchEnd2 = (e: TouchEvent, index = 1) => {
|
|
427
|
+
if (!props.isRange) {
|
|
399
428
|
// this.onTouchEnd(event, index);
|
|
400
429
|
}
|
|
401
|
-
}
|
|
402
|
-
const onClick = (
|
|
403
|
-
// if (isRange
|
|
404
|
-
if (disabled
|
|
430
|
+
};
|
|
431
|
+
const onClick = (e: TouchEvent) => {
|
|
432
|
+
// if (props.isRange) return;
|
|
433
|
+
if (props.disabled) return;
|
|
405
434
|
// 直接点击滑块的情况,计算方式与onTouchMove方法相同
|
|
406
435
|
// console.log('click', event)
|
|
407
436
|
// #ifndef APP-NVUE
|
|
408
437
|
// nvue下暂时无法获取坐标
|
|
409
|
-
let clientX =
|
|
410
|
-
newValue.value =
|
|
411
|
-
|
|
438
|
+
let clientX = e.detail.x - sliderRect.value.left!;
|
|
439
|
+
newValue.value =
|
|
440
|
+
(clientX / sliderRect.value.width!) * (props.max - props.min) + props.min;
|
|
441
|
+
updateValue(newValue.value, false, 1);
|
|
412
442
|
// #endif
|
|
413
|
-
}
|
|
414
|
-
const updateValue = (
|
|
443
|
+
};
|
|
444
|
+
const updateValue = (
|
|
445
|
+
value: number,
|
|
446
|
+
drag: boolean,
|
|
447
|
+
index: number = 1,
|
|
448
|
+
): number | number[] => {
|
|
415
449
|
// 去掉小数部分,同时也是对step步进的处理
|
|
416
|
-
let valueFormat = format(value, index)
|
|
450
|
+
let valueFormat = format(value, index);
|
|
417
451
|
// 不允许滑动的值超过max最大值
|
|
418
|
-
if (valueFormat > max
|
|
419
|
-
valueFormat = max
|
|
452
|
+
if (valueFormat > props.max) {
|
|
453
|
+
valueFormat = props.max;
|
|
420
454
|
}
|
|
421
455
|
// 设置移动的距离,不能用百分比,因为NVUE不支持。
|
|
422
456
|
let width = Math.min(
|
|
423
|
-
((valueFormat - min
|
|
457
|
+
((valueFormat - props.min) / (props.max - props.min)) *
|
|
458
|
+
sliderRect.value.width!,
|
|
424
459
|
sliderRect.value.width!,
|
|
425
|
-
)
|
|
460
|
+
);
|
|
426
461
|
let barStyle_1: CSSProperties = {
|
|
427
|
-
width: width +
|
|
428
|
-
}
|
|
462
|
+
width: width + "px",
|
|
463
|
+
};
|
|
429
464
|
// 移动期间无需过渡动画
|
|
430
465
|
if (drag) {
|
|
431
|
-
barStyle_1.transition =
|
|
466
|
+
barStyle_1.transition = "none";
|
|
432
467
|
} else {
|
|
433
468
|
// 非移动期间,删掉对过渡为空的声明,让css中的声明起效
|
|
434
|
-
delete barStyle_1.transition
|
|
469
|
+
delete barStyle_1.transition;
|
|
435
470
|
}
|
|
436
471
|
// 修改value值
|
|
437
|
-
if (isRange
|
|
438
|
-
rangeValue
|
|
439
|
-
emit(
|
|
472
|
+
if (props.isRange) {
|
|
473
|
+
props.rangeValue[index] = valueFormat;
|
|
474
|
+
emit("update:modelValue", props.rangeValue);
|
|
440
475
|
} else {
|
|
441
|
-
emit(
|
|
476
|
+
emit("update:modelValue", valueFormat);
|
|
442
477
|
}
|
|
443
478
|
|
|
444
479
|
switch (index) {
|
|
445
480
|
case 0:
|
|
446
|
-
barStyle0.value = barStyle_1
|
|
447
|
-
break
|
|
481
|
+
barStyle0.value = barStyle_1;
|
|
482
|
+
break;
|
|
448
483
|
case 1:
|
|
449
|
-
barStyle.value = barStyle_1
|
|
450
|
-
break
|
|
484
|
+
barStyle.value = barStyle_1;
|
|
485
|
+
break;
|
|
451
486
|
default:
|
|
452
|
-
break
|
|
487
|
+
break;
|
|
453
488
|
}
|
|
454
|
-
if (isRange
|
|
455
|
-
return rangeValue
|
|
489
|
+
if (props.isRange) {
|
|
490
|
+
return props.rangeValue;
|
|
456
491
|
} else {
|
|
457
|
-
return valueFormat
|
|
492
|
+
return valueFormat;
|
|
458
493
|
}
|
|
459
|
-
}
|
|
494
|
+
};
|
|
460
495
|
const format = (value: number, index = 1): number => {
|
|
461
496
|
// 将小数变成整数,为了减少对视图的更新,造成视图层与逻辑层的阻塞
|
|
462
|
-
if (isRange
|
|
497
|
+
if (props.isRange) {
|
|
463
498
|
switch (index) {
|
|
464
499
|
case 0:
|
|
465
500
|
return (
|
|
466
501
|
Math.round(
|
|
467
|
-
Math.max(
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
502
|
+
Math.max(
|
|
503
|
+
props.min,
|
|
504
|
+
Math.min(value, props.rangeValue[1] - props.step, props.max),
|
|
505
|
+
) / props.step,
|
|
506
|
+
) * props.step
|
|
507
|
+
);
|
|
471
508
|
case 1:
|
|
472
509
|
return (
|
|
473
510
|
Math.round(
|
|
474
|
-
Math.max(
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
511
|
+
Math.max(
|
|
512
|
+
props.min,
|
|
513
|
+
props.rangeValue[0] + props.step,
|
|
514
|
+
Math.min(value, props.max),
|
|
515
|
+
) / props.step,
|
|
516
|
+
) * props.step
|
|
517
|
+
);
|
|
478
518
|
default:
|
|
479
|
-
return 0
|
|
519
|
+
return 0;
|
|
480
520
|
}
|
|
481
521
|
} else {
|
|
482
522
|
// 解决精度丢失
|
|
483
523
|
return (
|
|
484
|
-
(Math.round(
|
|
524
|
+
(Math.round(
|
|
525
|
+
Math.max(props.min, Math.min(value, props.max)) / props.step,
|
|
526
|
+
) *
|
|
485
527
|
1000 *
|
|
486
|
-
step
|
|
528
|
+
props.step) /
|
|
487
529
|
1000
|
|
488
|
-
)
|
|
530
|
+
);
|
|
489
531
|
}
|
|
490
|
-
}
|
|
532
|
+
};
|
|
491
533
|
</script>
|
|
492
534
|
|
|
493
535
|
<style lang="scss" scoped>
|
|
494
|
-
@import
|
|
536
|
+
@import "./index.scss";
|
|
495
537
|
</style>
|
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
import type { CSSProperties } from
|
|
1
|
+
import type { CSSProperties } from "vue";
|
|
2
2
|
|
|
3
3
|
export default interface HySliderProps {
|
|
4
4
|
/**
|
|
5
5
|
* @description 滑块默认值(默认0)
|
|
6
6
|
* */
|
|
7
|
-
modelValue?: number
|
|
7
|
+
modelValue?: number;
|
|
8
8
|
/**
|
|
9
9
|
* @description 滑块的大小,取值范围为 12 - 28
|
|
10
10
|
* */
|
|
11
|
-
blockSize?: number | string
|
|
11
|
+
blockSize?: number | string;
|
|
12
12
|
/**
|
|
13
13
|
* @description 最小值(默认0)
|
|
14
14
|
* */
|
|
15
|
-
min?: number
|
|
15
|
+
min?: number;
|
|
16
16
|
/**
|
|
17
17
|
* @description 最大值(默认100)
|
|
18
18
|
* */
|
|
19
|
-
max?: number
|
|
19
|
+
max?: number;
|
|
20
20
|
/**
|
|
21
21
|
* @description 步长(默认1)
|
|
22
22
|
* */
|
|
23
|
-
step?: number
|
|
23
|
+
step?: number;
|
|
24
24
|
/**
|
|
25
25
|
* @description 底部选择部分的背景颜色(默认#2979ff)
|
|
26
26
|
* */
|
|
27
|
-
activeColor?: string
|
|
27
|
+
activeColor?: string;
|
|
28
28
|
/**
|
|
29
29
|
* @description 底部条背景颜色(默认#c0c4cc)
|
|
30
30
|
* */
|
|
31
|
-
inactiveColor?: string
|
|
31
|
+
inactiveColor?: string;
|
|
32
32
|
/**
|
|
33
33
|
* @description 滑块颜色(默认#ffffff)
|
|
34
34
|
* */
|
|
35
|
-
blockColor?: string
|
|
35
|
+
blockColor?: string;
|
|
36
36
|
/**
|
|
37
37
|
* @description 是否显示当前的选择值
|
|
38
38
|
* */
|
|
39
|
-
showValue?: boolean
|
|
39
|
+
showValue?: boolean;
|
|
40
40
|
/**
|
|
41
41
|
* @description 是否禁用滑块(默认为false)
|
|
42
42
|
* */
|
|
43
|
-
disabled?: boolean
|
|
43
|
+
disabled?: boolean;
|
|
44
44
|
/**
|
|
45
45
|
* @description 给滑块自定义样式,对象形式
|
|
46
46
|
* */
|
|
47
|
-
blockStyle?: CSSProperties
|
|
47
|
+
blockStyle?: CSSProperties;
|
|
48
48
|
/**
|
|
49
49
|
* @description 是否渲染uni-app框架内置组件(默认false)
|
|
50
50
|
* */
|
|
51
|
-
useNative?: boolean
|
|
51
|
+
useNative?: boolean;
|
|
52
52
|
/**
|
|
53
53
|
* @description 滑块条高度,单位rpx(默认6)
|
|
54
54
|
* */
|
|
55
|
-
height?: string | number
|
|
55
|
+
height?: string | number;
|
|
56
56
|
/**
|
|
57
57
|
* @description 双滑块时值
|
|
58
58
|
* */
|
|
59
|
-
rangeValue?: number[]
|
|
59
|
+
rangeValue?: number[];
|
|
60
60
|
/**
|
|
61
61
|
* @description 是否区间的模式
|
|
62
62
|
* */
|
|
63
|
-
isRange?: boolean
|
|
63
|
+
isRange?: boolean;
|
|
64
64
|
/**
|
|
65
65
|
* @description 自定义样式
|
|
66
66
|
* */
|
|
67
|
-
customStyle?: CSSProperties
|
|
67
|
+
customStyle?: CSSProperties;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
export interface ISliderEmits {
|
|
71
71
|
/** 开始滑动触发 */
|
|
72
|
-
(e:
|
|
72
|
+
(e: "start"): void;
|
|
73
73
|
/** 触发事件(拖动过程中) */
|
|
74
|
-
(e:
|
|
74
|
+
(e: "changing", value: number | number[]): void;
|
|
75
75
|
/** 触发事件 */
|
|
76
|
-
(e:
|
|
76
|
+
(e: "change", value: number | number[]): void;
|
|
77
77
|
/** 数值改变触发 */
|
|
78
|
-
(e:
|
|
78
|
+
(e: "update:modelValue", value: number | number[]): void;
|
|
79
79
|
}
|