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