hy-app 0.4.13 → 0.5.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/components/hy-action-sheet/hy-action-sheet.vue +155 -238
- package/components/hy-action-sheet/props.ts +68 -15
- package/components/hy-action-sheet/typing.d.ts +115 -115
- package/components/hy-address-picker/hy-address-picker.vue +185 -289
- package/components/hy-address-picker/props.ts +97 -21
- package/components/hy-address-picker/typing.d.ts +90 -89
- package/components/hy-avatar/hy-avatar.vue +121 -204
- package/components/hy-avatar/props.ts +76 -18
- package/components/hy-avatar/typing.d.ts +63 -62
- package/components/hy-back-top/hy-back-top.vue +65 -120
- package/components/hy-back-top/props.ts +57 -16
- package/components/hy-back-top/typing.d.ts +43 -42
- package/components/hy-badge/hy-badge.vue +66 -138
- package/components/hy-badge/props.ts +73 -17
- package/components/hy-badge/typing.d.ts +59 -58
- package/components/hy-button/hy-button.vue +226 -375
- package/components/hy-button/props.ts +129 -158
- package/components/hy-calendar/header.vue +48 -64
- package/components/hy-calendar/hy-calendar.vue +274 -438
- package/components/hy-calendar/month.vue +508 -516
- package/components/hy-calendar/props.ts +157 -35
- package/components/hy-calendar/typing.d.ts +129 -128
- package/components/hy-card/hy-card.vue +118 -240
- package/components/hy-card/index.scss +1 -2
- package/components/hy-card/props.ts +122 -27
- package/components/hy-card/typing.d.ts +119 -118
- package/components/hy-cell/hy-cell.vue +176 -258
- package/components/hy-cell/props.ts +71 -17
- package/components/hy-cell/typing.d.ts +87 -86
- package/components/hy-check-button/hy-check-button.vue +69 -139
- package/components/hy-check-button/props.ts +72 -18
- package/components/hy-check-button/typing.d.ts +74 -73
- package/components/hy-checkbox/hy-checkbox.vue +170 -263
- package/components/hy-checkbox/props.ts +94 -24
- package/components/hy-checkbox/typing.d.ts +72 -72
- package/components/hy-checkbox-group/hy-checkbox-group.vue +25 -100
- package/components/hy-checkbox-group/props.ts +80 -0
- package/components/hy-checkbox-group/typing.d.ts +65 -65
- package/components/hy-checkbox-item/hy-checkbox-item.vue +140 -177
- package/components/hy-checkbox-item/props.ts +24 -0
- package/components/hy-checkbox-item/typing.d.ts +4 -3
- package/components/hy-code-input/hy-code-input.vue +179 -262
- package/components/hy-code-input/props.ts +84 -18
- package/components/hy-code-input/typing.d.ts +71 -71
- package/components/hy-config-provider/hy-config-provider.vue +28 -50
- package/components/hy-config-provider/props.ts +26 -11
- package/components/hy-config-provider/typing.d.ts +20 -20
- package/components/hy-count-down/hy-count-down.vue +103 -131
- package/components/hy-count-down/props.ts +30 -8
- package/components/hy-count-down/typing.d.ts +25 -25
- package/components/hy-count-to/hy-count-to.vue +148 -213
- package/components/hy-count-to/props.ts +60 -15
- package/components/hy-count-to/typing.d.ts +46 -46
- package/components/hy-coupon/README.md +133 -0
- package/components/hy-coupon/hy-coupon.vue +180 -0
- package/components/hy-coupon/index.scss +553 -0
- package/components/hy-coupon/props.ts +129 -0
- package/components/hy-coupon/typing.d.ts +146 -0
- package/components/hy-datetime-picker/hy-datetime-picker.vue +415 -580
- package/components/hy-datetime-picker/props.ts +142 -32
- package/components/hy-datetime-picker/typing.d.ts +132 -132
- package/components/hy-divider/hy-divider.vue +90 -169
- package/components/hy-divider/props.ts +78 -19
- package/components/hy-divider/typing.d.ts +60 -60
- package/components/hy-dropdown/hy-dropdown.vue +37 -71
- package/components/hy-dropdown/props.ts +38 -15
- package/components/hy-dropdown/typing.d.ts +44 -44
- package/components/hy-dropdown-item/hy-dropdown-item.vue +141 -173
- package/components/hy-dropdown-item/props.ts +19 -8
- package/components/hy-empty/hy-empty.vue +75 -129
- package/components/hy-empty/props.ts +57 -15
- package/components/hy-empty/typing.d.ts +84 -84
- package/components/hy-flex/hy-flex.vue +33 -88
- package/components/hy-flex/props.ts +58 -0
- package/components/hy-flex/typing.d.ts +14 -16
- package/components/hy-float-button/hy-float-button.vue +289 -406
- package/components/hy-float-button/props.ts +109 -25
- package/components/hy-folding-panel/hy-folding-panel.vue +86 -374
- package/components/hy-folding-panel/props.ts +40 -15
- package/components/hy-folding-panel/typing.d.ts +52 -63
- package/components/hy-folding-panel-item/hy-folding-panel-item.vue +186 -228
- package/components/hy-folding-panel-item/index.scss +87 -0
- package/components/hy-folding-panel-item/props.ts +81 -0
- package/components/hy-folding-panel-item/typing.d.ts +23 -0
- package/components/hy-form/hy-form.vue +172 -212
- package/components/hy-form/props.ts +37 -0
- package/components/hy-form/typing.d.ts +68 -61
- package/components/hy-form-group/typing.d.ts +74 -74
- package/components/hy-form-item/hy-form-item.vue +100 -129
- package/components/hy-form-item/props.ts +25 -0
- package/components/hy-form-item/typing.d.ts +40 -37
- package/components/hy-grid/hy-grid.vue +76 -132
- package/components/hy-grid/props.ts +58 -16
- package/components/hy-grid/typing.d.ts +66 -66
- package/components/hy-icon/hy-icon.vue +84 -161
- package/components/hy-icon/props.ts +76 -22
- package/components/hy-icon/typing.d.ts +83 -82
- package/components/hy-image/hy-image.vue +142 -272
- package/components/hy-image/props.ts +105 -23
- package/components/hy-image/typing.d.ts +84 -87
- package/components/hy-input/hy-input.vue +230 -421
- package/components/hy-input/props.ts +183 -35
- package/components/hy-input/typing.d.ts +169 -169
- package/components/hy-line/hy-line.vue +34 -72
- package/components/hy-line/props.ts +41 -10
- package/components/hy-line/typing.d.ts +29 -29
- package/components/hy-line-progress/hy-line-progress.vue +66 -101
- package/components/hy-line-progress/props.ts +31 -10
- package/components/hy-line-progress/typing.d.ts +29 -29
- package/components/hy-list/hy-list.vue +151 -220
- package/components/hy-list/props.ts +67 -16
- package/components/hy-list/typing.d.ts +52 -52
- package/components/hy-loading/hy-loading.vue +63 -119
- package/components/hy-loading/props.ts +63 -15
- package/components/hy-loading/typing.d.ts +49 -49
- package/components/hy-menu/hy-menu.vue +124 -166
- package/components/hy-menu/props.ts +42 -10
- package/components/hy-menu/typing.d.ts +60 -60
- package/components/hy-modal/hy-modal.vue +127 -218
- package/components/hy-modal/props.ts +89 -24
- package/components/hy-navbar/hy-navbar.vue +104 -177
- package/components/hy-navbar/props.ts +76 -22
- package/components/hy-navbar/typing.d.ts +81 -81
- package/components/hy-notice-bar/hy-notice-bar.vue +67 -144
- package/components/hy-notice-bar/props.ts +80 -19
- package/components/hy-notice-bar/typing.d.ts +62 -62
- package/components/hy-notify/hy-notify.vue +128 -177
- package/components/hy-notify/props.ts +49 -12
- package/components/hy-notify/typing.d.ts +45 -41
- package/components/hy-number-step/hy-number-step.vue +281 -394
- package/components/hy-number-step/props.ts +110 -27
- package/components/hy-number-step/typing.d.ts +120 -120
- package/components/hy-overlay/hy-overlay.vue +39 -66
- package/components/hy-overlay/props.ts +31 -8
- package/components/hy-pagination/hy-pagination.vue +100 -155
- package/components/hy-pagination/props.ts +53 -13
- package/components/hy-picker/hy-picker.vue +309 -430
- package/components/hy-picker/index.scss +8 -12
- package/components/hy-picker/props.ts +110 -26
- package/components/hy-popover/hy-popover.vue +190 -252
- package/components/hy-popover/props.ts +48 -10
- package/components/hy-popup/hy-popup.vue +162 -248
- package/components/hy-popup/props.ts +82 -18
- package/components/hy-price/hy-price.vue +45 -104
- package/components/hy-price/props.ts +52 -12
- package/components/hy-price/typing.d.ts +41 -36
- package/components/hy-qrcode/hy-qrcode.vue +115 -185
- package/components/hy-qrcode/props.ts +68 -18
- package/components/hy-qrcode/typing.d.ts +67 -66
- package/components/hy-radio/hy-radio.vue +161 -259
- package/components/hy-radio/props.ts +95 -25
- package/components/hy-radio/typing.d.ts +85 -84
- package/components/hy-rate/hy-rate.vue +185 -270
- package/components/hy-rate/props.ts +76 -18
- package/components/hy-rate/typing.d.ts +61 -60
- package/components/hy-read-more/hy-read-more.vue +93 -136
- package/components/hy-read-more/props.ts +43 -13
- package/components/hy-scroll-list/hy-scroll-list.vue +81 -102
- package/components/hy-scroll-list/props.ts +22 -11
- package/components/hy-search/hy-search.vue +155 -284
- package/components/hy-search/props.ts +130 -25
- package/components/hy-signature/hy-signature.vue +491 -635
- package/components/hy-signature/props.ts +115 -26
- package/components/hy-signature/typing.d.ts +138 -138
- package/components/hy-slider/hy-slider.vue +388 -477
- package/components/hy-slider/props.ts +75 -19
- package/components/hy-steps/hy-steps.vue +212 -279
- package/components/hy-steps/props.ts +47 -13
- package/components/hy-submit-bar/hy-submit-bar.vue +137 -222
- package/components/hy-submit-bar/props.ts +89 -20
- package/components/hy-submit-bar/typing.d.ts +86 -85
- package/components/hy-subsection/hy-subsection.vue +132 -185
- package/components/hy-subsection/props.ts +50 -17
- package/components/hy-subsection/typing.d.ts +52 -52
- package/components/hy-swipe-action/hy-swipe-action.vue +228 -283
- package/components/hy-swipe-action/props.ts +43 -18
- package/components/hy-swipe-action/typing.d.ts +46 -46
- package/components/hy-swiper/hy-swiper.vue +159 -286
- package/components/hy-swiper/props.ts +126 -28
- package/components/hy-swiper/typing.d.ts +115 -115
- package/components/hy-switch/hy-switch.vue +112 -176
- package/components/hy-switch/props.ts +60 -15
- package/components/hy-switch/typing.d.ts +63 -63
- package/components/hy-tabBar/hy-tabBar.vue +64 -60
- package/components/hy-tabs/hy-tabs.vue +277 -380
- package/components/hy-tabs/props.ts +75 -18
- package/components/hy-tag/hy-tag.vue +111 -204
- package/components/hy-tag/props.ts +81 -19
- package/components/hy-text/hy-text.vue +200 -322
- package/components/hy-text/props.ts +107 -28
- package/components/hy-textarea/hy-textarea.vue +147 -256
- package/components/hy-textarea/props.ts +112 -25
- package/components/hy-textarea/typing.d.ts +42 -42
- package/components/hy-toast/hy-toast.vue +135 -143
- package/components/hy-tooltip/hy-tooltip.vue +220 -306
- package/components/hy-tooltip/props.ts +79 -15
- package/components/hy-transition/hy-transition.vue +111 -138
- package/components/hy-transition/props.ts +30 -8
- package/components/hy-upload/hy-upload.vue +320 -469
- package/components/hy-upload/props.ts +130 -27
- package/components/hy-warn/hy-warn.vue +80 -129
- package/components/hy-warn/props.ts +47 -12
- package/components/hy-waterfall/hy-waterfall.vue +139 -163
- package/components/hy-waterfall/props.ts +19 -7
- package/components/hy-watermark/hy-watermark.vue +762 -870
- package/components/hy-watermark/props.ts +103 -22
- package/global.d.ts +2 -0
- package/libs/css/theme.scss +3 -3
- package/package.json +2 -2
- package/web-types.json +1 -1
- package/components/hy-folding-panel/index.scss +0 -9
|
@@ -1,325 +1,240 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
2
|
+
<view class="hy-rate" :id="elId" ref="hy-rate" :style="[customStyle]">
|
|
3
|
+
<view class="hy-rate__content" @touchmove.stop="touchMove" @touchend.stop="touchEnd">
|
|
4
|
+
<view
|
|
5
|
+
class="hy-rate__content--item cursor-pointer"
|
|
6
|
+
v-for="(item, index) in Number(count)"
|
|
7
|
+
:key="index"
|
|
8
|
+
:class="[elClass]"
|
|
9
|
+
>
|
|
10
|
+
<view
|
|
11
|
+
class="hy-rate__content--item__icon-wrap"
|
|
12
|
+
ref="hy-rate__content--item__icon-wrap"
|
|
13
|
+
@tap.stop="clickHandler($event)"
|
|
14
|
+
>
|
|
15
|
+
<hy-icon
|
|
16
|
+
:name="Math.floor(activeIndex) > index ? activeIcon : inactiveIcon"
|
|
17
|
+
:color="
|
|
18
|
+
disabled
|
|
19
|
+
? '#c8c9cc'
|
|
20
|
+
: Math.floor(activeIndex) > index
|
|
21
|
+
? activeColor
|
|
22
|
+
: inactiveColor
|
|
23
|
+
"
|
|
24
|
+
:custom-style="{
|
|
25
|
+
padding: `0 ${addUnit(gutter / 2)}`
|
|
26
|
+
}"
|
|
27
|
+
:size="size"
|
|
28
|
+
></hy-icon>
|
|
29
|
+
</view>
|
|
30
|
+
<view
|
|
31
|
+
v-if="allowHalf"
|
|
32
|
+
@tap.stop="clickHandler($event)"
|
|
33
|
+
class="hy-rate__content--item__icon-wrap hy-rate__content--item__icon-wrap--half"
|
|
34
|
+
:style="[
|
|
35
|
+
{
|
|
36
|
+
width: addUnit(rateWidth / 2)
|
|
37
|
+
}
|
|
38
|
+
]"
|
|
39
|
+
ref="hy-rate__content--item__icon-wrap"
|
|
40
|
+
>
|
|
41
|
+
<hy-icon
|
|
42
|
+
:name="Math.ceil(activeIndex) > index ? activeIcon : inactiveIcon"
|
|
43
|
+
:color="
|
|
44
|
+
disabled
|
|
45
|
+
? '#c8c9cc'
|
|
46
|
+
: Math.ceil(activeIndex) > index
|
|
47
|
+
? activeColor
|
|
48
|
+
: inactiveColor
|
|
49
|
+
"
|
|
50
|
+
:custom-style="{
|
|
51
|
+
padding: `0 ${addUnit(gutter / 2)}`
|
|
52
|
+
}"
|
|
53
|
+
:size="size"
|
|
54
|
+
></hy-icon>
|
|
55
|
+
</view>
|
|
56
|
+
</view>
|
|
33
57
|
</view>
|
|
34
|
-
<view
|
|
35
|
-
v-if="allowHalf"
|
|
36
|
-
@tap.stop="clickHandler($event)"
|
|
37
|
-
class="hy-rate__content--item__icon-wrap hy-rate__content--item__icon-wrap--half"
|
|
38
|
-
:style="[
|
|
39
|
-
{
|
|
40
|
-
width: addUnit(rateWidth / 2),
|
|
41
|
-
},
|
|
42
|
-
]"
|
|
43
|
-
ref="hy-rate__content--item__icon-wrap"
|
|
44
|
-
>
|
|
45
|
-
<HyIcon
|
|
46
|
-
:name="Math.ceil(activeIndex) > index ? activeIcon : inactiveIcon"
|
|
47
|
-
:color="
|
|
48
|
-
disabled
|
|
49
|
-
? '#c8c9cc'
|
|
50
|
-
: Math.ceil(activeIndex) > index
|
|
51
|
-
? activeColor
|
|
52
|
-
: inactiveColor
|
|
53
|
-
"
|
|
54
|
-
:custom-style="{
|
|
55
|
-
padding: `0 ${addUnit(gutter / 2)}`,
|
|
56
|
-
}"
|
|
57
|
-
:size="size"
|
|
58
|
-
></HyIcon>
|
|
59
|
-
</view>
|
|
60
|
-
</view>
|
|
61
58
|
</view>
|
|
62
|
-
</view>
|
|
63
59
|
</template>
|
|
64
60
|
|
|
65
61
|
<script lang="ts">
|
|
66
62
|
export default {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
63
|
+
name: 'hy-rate',
|
|
64
|
+
options: {
|
|
65
|
+
addGlobalClass: true,
|
|
66
|
+
virtualHost: true,
|
|
67
|
+
styleIsolation: 'shared'
|
|
68
|
+
}
|
|
69
|
+
}
|
|
74
70
|
</script>
|
|
75
71
|
|
|
76
72
|
<script setup lang="ts">
|
|
77
|
-
import { ref, watch, onMounted, getCurrentInstance } from
|
|
78
|
-
import type {
|
|
79
|
-
import
|
|
80
|
-
import
|
|
73
|
+
import { ref, watch, onMounted, getCurrentInstance } from 'vue'
|
|
74
|
+
import type { IRateEmits } from './typing'
|
|
75
|
+
import { addUnit, getRect, guid, range, sleep } from '../../libs'
|
|
76
|
+
import rateProps from './props'
|
|
81
77
|
// 组件
|
|
82
|
-
import HyIcon from
|
|
78
|
+
import HyIcon from '../hy-icon/hy-icon.vue'
|
|
83
79
|
|
|
84
80
|
/**
|
|
85
81
|
* 该组件一般用于满意度调查,星型评分的场景。
|
|
86
82
|
* @displayName hy-rate
|
|
87
83
|
*/
|
|
88
|
-
defineOptions({})
|
|
84
|
+
defineOptions({})
|
|
89
85
|
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
/** v-model绑定的值 */
|
|
93
|
-
modelValue: {
|
|
94
|
-
type: Number,
|
|
95
|
-
default: 1,
|
|
96
|
-
},
|
|
97
|
-
/** 星星的默认最多数 */
|
|
98
|
-
count: {
|
|
99
|
-
type: Number,
|
|
100
|
-
default: 5,
|
|
101
|
-
},
|
|
102
|
-
/** 是否禁用 */
|
|
103
|
-
disabled: {
|
|
104
|
-
type: Boolean,
|
|
105
|
-
default: false,
|
|
106
|
-
},
|
|
107
|
-
/** 是否只读 */
|
|
108
|
-
readonly: {
|
|
109
|
-
type: Boolean,
|
|
110
|
-
default: false,
|
|
111
|
-
},
|
|
112
|
-
/** 星星的大小 */
|
|
113
|
-
size: {
|
|
114
|
-
type: Number,
|
|
115
|
-
default: 18,
|
|
116
|
-
},
|
|
117
|
-
/** 未激活星星的颜色 */
|
|
118
|
-
inactiveColor: {
|
|
119
|
-
type: String,
|
|
120
|
-
default: "#b2b2b2",
|
|
121
|
-
},
|
|
122
|
-
/** 激活星星的颜色 */
|
|
123
|
-
activeColor: {
|
|
124
|
-
type: String,
|
|
125
|
-
default: "#FFF00D",
|
|
126
|
-
},
|
|
127
|
-
/** 星星之间的间距 */
|
|
128
|
-
gutter: {
|
|
129
|
-
type: Number,
|
|
130
|
-
default: 4,
|
|
131
|
-
},
|
|
132
|
-
/** 最小星星数量 */
|
|
133
|
-
minCount: {
|
|
134
|
-
type: Number,
|
|
135
|
-
default: 1,
|
|
136
|
-
},
|
|
137
|
-
/** 是否允许半星 */
|
|
138
|
-
allowHalf: {
|
|
139
|
-
type: Boolean,
|
|
140
|
-
default: false,
|
|
141
|
-
},
|
|
142
|
-
/** 激活状态的图标 */
|
|
143
|
-
activeIcon: {
|
|
144
|
-
type: String,
|
|
145
|
-
default: IconConfig.STAR_FILL,
|
|
146
|
-
},
|
|
147
|
-
/** 未激活状态的图标 */
|
|
148
|
-
inactiveIcon: {
|
|
149
|
-
type: String,
|
|
150
|
-
default: IconConfig.STAR,
|
|
151
|
-
},
|
|
152
|
-
/** 是否可触摸 */
|
|
153
|
-
touchable: {
|
|
154
|
-
type: Boolean,
|
|
155
|
-
default: true,
|
|
156
|
-
},
|
|
157
|
-
/** 定义需要用到的外部样式 */
|
|
158
|
-
customStyle: {
|
|
159
|
-
type: Object as PropType<CSSProperties>,
|
|
160
|
-
},
|
|
161
|
-
/** 自定义外部类名 */
|
|
162
|
-
customClass: String,
|
|
163
|
-
});
|
|
164
|
-
const emit = defineEmits<IRateEmits>();
|
|
86
|
+
const props = defineProps(rateProps)
|
|
87
|
+
const emit = defineEmits<IRateEmits>()
|
|
165
88
|
|
|
166
|
-
const elId = guid()
|
|
167
|
-
const elClass = guid()
|
|
168
|
-
const rateBoxLeft = ref<number>(0)
|
|
169
|
-
const activeIndex = ref(props.modelValue)
|
|
89
|
+
const elId = guid()
|
|
90
|
+
const elClass = guid()
|
|
91
|
+
const rateBoxLeft = ref<number>(0)
|
|
92
|
+
const activeIndex = ref(props.modelValue)
|
|
170
93
|
// 每个星星的宽度
|
|
171
|
-
const rateWidth = ref(0)
|
|
94
|
+
const rateWidth = ref(0)
|
|
172
95
|
// 标识是否正在滑动,由于iOS事件上touch比click先触发,导致快速滑动结束后,接着触发click,导致事件混乱而出错
|
|
173
|
-
const moving = ref(false)
|
|
96
|
+
const moving = ref(false)
|
|
174
97
|
|
|
175
98
|
watch(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
)
|
|
99
|
+
() => props.modelValue,
|
|
100
|
+
(newValue) => {
|
|
101
|
+
activeIndex.value = newValue
|
|
102
|
+
}
|
|
103
|
+
)
|
|
181
104
|
watch(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
)
|
|
187
|
-
const instance = getCurrentInstance()
|
|
105
|
+
() => activeIndex.value,
|
|
106
|
+
() => {
|
|
107
|
+
emitEvent()
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
const instance = getCurrentInstance()
|
|
188
111
|
|
|
189
112
|
onMounted(() => {
|
|
190
|
-
|
|
191
|
-
})
|
|
113
|
+
init()
|
|
114
|
+
})
|
|
192
115
|
|
|
193
116
|
const init = () => {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
117
|
+
sleep(300).then(async () => {
|
|
118
|
+
await getRateItemRect()
|
|
119
|
+
await getRateIconWrapRect()
|
|
120
|
+
})
|
|
121
|
+
}
|
|
199
122
|
|
|
200
123
|
/**
|
|
201
124
|
* @description 获取评分组件盒子的布局信息
|
|
202
125
|
* */
|
|
203
126
|
const getRateItemRect = async () => {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
)) as UniApp.NodeInfo;
|
|
211
|
-
rateBoxLeft.value = res.left || 0;
|
|
212
|
-
// #endif
|
|
213
|
-
};
|
|
127
|
+
await sleep()
|
|
128
|
+
// #ifndef APP-NVUE
|
|
129
|
+
const res: UniApp.NodeInfo = (await getRect(`#${elId}`, false, instance)) as UniApp.NodeInfo
|
|
130
|
+
rateBoxLeft.value = res.left || 0
|
|
131
|
+
// #endif
|
|
132
|
+
}
|
|
214
133
|
|
|
215
134
|
/**
|
|
216
135
|
* @description 获取单个星星的尺寸
|
|
217
136
|
* */
|
|
218
137
|
const getRateIconWrapRect = async () => {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
)) as UniApp.NodeInfo;
|
|
226
|
-
rateWidth.value = res.width || 0;
|
|
227
|
-
// #endif
|
|
228
|
-
};
|
|
138
|
+
// uView封装的获取节点的方法,详见文档
|
|
139
|
+
// #ifndef APP-NVUE
|
|
140
|
+
const res: UniApp.NodeInfo = (await getRect(`.${elClass}`, false, instance)) as UniApp.NodeInfo
|
|
141
|
+
rateWidth.value = res.width || 0
|
|
142
|
+
// #endif
|
|
143
|
+
}
|
|
229
144
|
// 手指滑动
|
|
230
145
|
const touchMove = (e: TouchEvent) => {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
146
|
+
// 如果禁止通过手动滑动选择,返回
|
|
147
|
+
if (!props.touchable) {
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
e.stopPropagation()
|
|
151
|
+
const x = e.changedTouches[0].pageX
|
|
152
|
+
getActiveIndex(x)
|
|
153
|
+
}
|
|
239
154
|
// 停止滑动
|
|
240
155
|
const touchEnd = (e: TouchEvent) => {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
156
|
+
// 如果禁止通过手动滑动选择,返回
|
|
157
|
+
if (!props.touchable) {
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
e.stopPropagation()
|
|
161
|
+
const x = e.changedTouches[0].pageX
|
|
162
|
+
getActiveIndex(x)
|
|
163
|
+
}
|
|
249
164
|
// 通过点击,直接选中
|
|
250
165
|
const clickHandler = (e: TouchEvent) => {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
166
|
+
// if (moving.value) {
|
|
167
|
+
// return;
|
|
168
|
+
// }
|
|
169
|
+
e.stopPropagation()
|
|
170
|
+
console.log(e, '微信')
|
|
171
|
+
let x = 0
|
|
172
|
+
// #ifndef APP-NVUE || MP-ALIPAY
|
|
173
|
+
x = e.detail.x
|
|
174
|
+
// #endif
|
|
175
|
+
// #ifdef MP-ALIPAY
|
|
176
|
+
x = e.detail.pageX
|
|
177
|
+
// #endif
|
|
178
|
+
getActiveIndex(x, true)
|
|
179
|
+
}
|
|
265
180
|
// 发出事件
|
|
266
181
|
const emitEvent = () => {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
182
|
+
// 发出change事件
|
|
183
|
+
emit('change', activeIndex.value)
|
|
184
|
+
// 同时修改双向绑定的值
|
|
185
|
+
emit('update:modelValue', activeIndex.value)
|
|
186
|
+
}
|
|
272
187
|
// 获取当前激活的评分图标
|
|
273
188
|
const getActiveIndex = (x: number, isClick = false) => {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
// 判断当前操作的点的x坐标值,是否在允许的边界范围内
|
|
278
|
-
const allRateWidth = rateWidth.value * props.count + rateBoxLeft.value;
|
|
279
|
-
// 如果小于第一个图标的左边界,设置为最小值,如果大于所有图标的宽度,则设置为最大值
|
|
280
|
-
x = range(rateBoxLeft.value, allRateWidth, x) - rateBoxLeft.value;
|
|
281
|
-
// 滑动点相对于评分盒子左边的距离
|
|
282
|
-
const distance = x;
|
|
283
|
-
// 滑动的距离,相当于多少颗星星
|
|
284
|
-
let index;
|
|
285
|
-
// 判断是否允许半星
|
|
286
|
-
if (props.allowHalf) {
|
|
287
|
-
index = Math.floor(distance / rateWidth.value);
|
|
288
|
-
// 取余,判断小数的区间范围
|
|
289
|
-
const decimal = distance % rateWidth.value;
|
|
290
|
-
if (decimal <= rateWidth.value / 2 && decimal > 0) {
|
|
291
|
-
index += 0.5;
|
|
292
|
-
} else if (decimal > rateWidth.value / 2) {
|
|
293
|
-
index++;
|
|
189
|
+
if (props.disabled || props.readonly) {
|
|
190
|
+
return
|
|
294
191
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
//
|
|
298
|
-
|
|
299
|
-
//
|
|
300
|
-
|
|
301
|
-
|
|
192
|
+
// 判断当前操作的点的x坐标值,是否在允许的边界范围内
|
|
193
|
+
const allRateWidth = rateWidth.value * props.count + rateBoxLeft.value
|
|
194
|
+
// 如果小于第一个图标的左边界,设置为最小值,如果大于所有图标的宽度,则设置为最大值
|
|
195
|
+
x = range(rateBoxLeft.value, allRateWidth, x) - rateBoxLeft.value
|
|
196
|
+
// 滑动点相对于评分盒子左边的距离
|
|
197
|
+
const distance = x
|
|
198
|
+
// 滑动的距离,相当于多少颗星星
|
|
199
|
+
let index
|
|
200
|
+
// 判断是否允许半星
|
|
201
|
+
if (props.allowHalf) {
|
|
202
|
+
index = Math.floor(distance / rateWidth.value)
|
|
203
|
+
// 取余,判断小数的区间范围
|
|
204
|
+
const decimal = distance % rateWidth.value
|
|
205
|
+
if (decimal <= rateWidth.value / 2 && decimal > 0) {
|
|
206
|
+
index += 0.5
|
|
207
|
+
} else if (decimal > rateWidth.value / 2) {
|
|
208
|
+
index++
|
|
209
|
+
}
|
|
302
210
|
} else {
|
|
303
|
-
|
|
211
|
+
index = Math.floor(distance / rateWidth.value)
|
|
212
|
+
// 取余,判断小数的区间范围
|
|
213
|
+
const decimal = distance % rateWidth.value
|
|
214
|
+
// 非半星时,只有超过了图标的一半距离,才认为是选择了这颗星
|
|
215
|
+
if (isClick) {
|
|
216
|
+
if (decimal > 0) index++
|
|
217
|
+
} else {
|
|
218
|
+
if (decimal > rateWidth.value / 2) index++
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
activeIndex.value = Math.min(index, props.count)
|
|
222
|
+
// 对最少颗星星的限制
|
|
223
|
+
if (activeIndex.value < props.minCount) {
|
|
224
|
+
activeIndex.value = props.minCount
|
|
304
225
|
}
|
|
305
|
-
}
|
|
306
|
-
activeIndex.value = Math.min(index, props.count);
|
|
307
|
-
// 对最少颗星星的限制
|
|
308
|
-
if (activeIndex.value < props.minCount) {
|
|
309
|
-
activeIndex.value = props.minCount;
|
|
310
|
-
}
|
|
311
226
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
227
|
+
// 设置延时为了让click事件在touchmove之前触发
|
|
228
|
+
setTimeout(() => {
|
|
229
|
+
moving.value = true
|
|
230
|
+
}, 10)
|
|
231
|
+
// 一定时间后,取消标识为移动中状态,是为了让click事件无效
|
|
232
|
+
setTimeout(() => {
|
|
233
|
+
moving.value = false
|
|
234
|
+
}, 10)
|
|
235
|
+
}
|
|
321
236
|
</script>
|
|
322
237
|
|
|
323
238
|
<style lang="scss" scoped>
|
|
324
|
-
@import
|
|
239
|
+
@import './index.scss';
|
|
325
240
|
</style>
|
|
@@ -1,19 +1,77 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type
|
|
1
|
+
import { IconConfig } from '../../libs/config'
|
|
2
|
+
import type { CSSProperties, PropType } from 'vue'
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
const rateProps = {
|
|
5
|
+
/** v-model绑定的值 */
|
|
6
|
+
modelValue: {
|
|
7
|
+
type: Number,
|
|
8
|
+
default: 1
|
|
9
|
+
},
|
|
10
|
+
/** 星星的默认最多数 */
|
|
11
|
+
count: {
|
|
12
|
+
type: Number,
|
|
13
|
+
default: 5
|
|
14
|
+
},
|
|
15
|
+
/** 是否禁用 */
|
|
16
|
+
disabled: {
|
|
17
|
+
type: Boolean,
|
|
18
|
+
default: false
|
|
19
|
+
},
|
|
20
|
+
/** 是否只读 */
|
|
21
|
+
readonly: {
|
|
22
|
+
type: Boolean,
|
|
23
|
+
default: false
|
|
24
|
+
},
|
|
25
|
+
/** 星星的大小 */
|
|
26
|
+
size: {
|
|
27
|
+
type: Number,
|
|
28
|
+
default: 18
|
|
29
|
+
},
|
|
30
|
+
/** 未激活星星的颜色 */
|
|
31
|
+
inactiveColor: {
|
|
32
|
+
type: String,
|
|
33
|
+
default: '#b2b2b2'
|
|
34
|
+
},
|
|
35
|
+
/** 激活星星的颜色 */
|
|
36
|
+
activeColor: {
|
|
37
|
+
type: String,
|
|
38
|
+
default: '#FFF00D'
|
|
39
|
+
},
|
|
40
|
+
/** 星星之间的间距 */
|
|
41
|
+
gutter: {
|
|
42
|
+
type: Number,
|
|
43
|
+
default: 4
|
|
44
|
+
},
|
|
45
|
+
/** 最小星星数量 */
|
|
46
|
+
minCount: {
|
|
47
|
+
type: Number,
|
|
48
|
+
default: 1
|
|
49
|
+
},
|
|
50
|
+
/** 是否允许半星 */
|
|
51
|
+
allowHalf: {
|
|
52
|
+
type: Boolean,
|
|
53
|
+
default: false
|
|
54
|
+
},
|
|
55
|
+
/** 激活状态的图标 */
|
|
56
|
+
activeIcon: {
|
|
57
|
+
type: String,
|
|
58
|
+
default: IconConfig.STAR_FILL
|
|
59
|
+
},
|
|
60
|
+
/** 未激活状态的图标 */
|
|
61
|
+
inactiveIcon: {
|
|
62
|
+
type: String,
|
|
63
|
+
default: IconConfig.STAR
|
|
64
|
+
},
|
|
65
|
+
/** 是否可触摸 */
|
|
66
|
+
touchable: {
|
|
67
|
+
type: Boolean,
|
|
68
|
+
default: true
|
|
69
|
+
},
|
|
70
|
+
/** 定义需要用到的外部样式 */
|
|
71
|
+
customStyle: {
|
|
72
|
+
type: Object as PropType<CSSProperties>
|
|
73
|
+
},
|
|
74
|
+
/** 自定义外部类名 */
|
|
75
|
+
customClass: String
|
|
76
|
+
}
|
|
77
|
+
export default rateProps
|