hy-app 0.4.15 → 0.5.1

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.
Files changed (206) hide show
  1. package/components/hy-action-sheet/hy-action-sheet.vue +155 -238
  2. package/components/hy-action-sheet/props.ts +68 -15
  3. package/components/hy-action-sheet/typing.d.ts +115 -115
  4. package/components/hy-address-picker/hy-address-picker.vue +185 -289
  5. package/components/hy-address-picker/props.ts +97 -21
  6. package/components/hy-address-picker/typing.d.ts +90 -89
  7. package/components/hy-avatar/hy-avatar.vue +121 -204
  8. package/components/hy-avatar/props.ts +76 -18
  9. package/components/hy-avatar/typing.d.ts +63 -62
  10. package/components/hy-back-top/hy-back-top.vue +65 -120
  11. package/components/hy-back-top/props.ts +57 -16
  12. package/components/hy-back-top/typing.d.ts +43 -42
  13. package/components/hy-badge/hy-badge.vue +66 -138
  14. package/components/hy-badge/props.ts +73 -17
  15. package/components/hy-badge/typing.d.ts +59 -58
  16. package/components/hy-button/hy-button.vue +226 -375
  17. package/components/hy-button/props.ts +129 -158
  18. package/components/hy-calendar/header.vue +48 -64
  19. package/components/hy-calendar/hy-calendar.vue +274 -438
  20. package/components/hy-calendar/month.vue +508 -516
  21. package/components/hy-calendar/props.ts +157 -35
  22. package/components/hy-calendar/typing.d.ts +129 -128
  23. package/components/hy-card/hy-card.vue +118 -240
  24. package/components/hy-card/index.scss +1 -2
  25. package/components/hy-card/props.ts +122 -27
  26. package/components/hy-card/typing.d.ts +119 -118
  27. package/components/hy-cell/hy-cell.vue +176 -258
  28. package/components/hy-cell/props.ts +71 -17
  29. package/components/hy-cell/typing.d.ts +87 -86
  30. package/components/hy-check-button/hy-check-button.vue +69 -139
  31. package/components/hy-check-button/props.ts +72 -18
  32. package/components/hy-check-button/typing.d.ts +74 -73
  33. package/components/hy-checkbox/hy-checkbox.vue +170 -263
  34. package/components/hy-checkbox/props.ts +94 -24
  35. package/components/hy-checkbox/typing.d.ts +72 -72
  36. package/components/hy-checkbox-group/hy-checkbox-group.vue +25 -100
  37. package/components/hy-checkbox-group/props.ts +80 -0
  38. package/components/hy-checkbox-group/typing.d.ts +65 -65
  39. package/components/hy-checkbox-item/hy-checkbox-item.vue +140 -177
  40. package/components/hy-checkbox-item/props.ts +24 -0
  41. package/components/hy-checkbox-item/typing.d.ts +4 -3
  42. package/components/hy-code-input/hy-code-input.vue +179 -262
  43. package/components/hy-code-input/props.ts +84 -18
  44. package/components/hy-code-input/typing.d.ts +71 -71
  45. package/components/hy-config-provider/hy-config-provider.vue +28 -50
  46. package/components/hy-config-provider/props.ts +26 -11
  47. package/components/hy-config-provider/typing.d.ts +20 -20
  48. package/components/hy-count-down/hy-count-down.vue +103 -131
  49. package/components/hy-count-down/props.ts +30 -8
  50. package/components/hy-count-down/typing.d.ts +25 -25
  51. package/components/hy-count-to/hy-count-to.vue +148 -213
  52. package/components/hy-count-to/props.ts +60 -15
  53. package/components/hy-count-to/typing.d.ts +46 -46
  54. package/components/hy-coupon/hy-coupon.vue +10 -5
  55. package/components/hy-coupon/index.scss +148 -64
  56. package/components/hy-coupon/props.ts +35 -50
  57. package/components/hy-coupon/typing.d.ts +10 -0
  58. package/components/hy-datetime-picker/hy-datetime-picker.vue +415 -580
  59. package/components/hy-datetime-picker/props.ts +142 -32
  60. package/components/hy-datetime-picker/typing.d.ts +132 -132
  61. package/components/hy-divider/hy-divider.vue +90 -169
  62. package/components/hy-divider/props.ts +78 -19
  63. package/components/hy-divider/typing.d.ts +60 -60
  64. package/components/hy-dropdown/hy-dropdown.vue +37 -71
  65. package/components/hy-dropdown/props.ts +38 -15
  66. package/components/hy-dropdown/typing.d.ts +44 -44
  67. package/components/hy-dropdown-item/hy-dropdown-item.vue +141 -173
  68. package/components/hy-dropdown-item/props.ts +19 -8
  69. package/components/hy-empty/hy-empty.vue +75 -129
  70. package/components/hy-empty/props.ts +57 -15
  71. package/components/hy-empty/typing.d.ts +84 -84
  72. package/components/hy-flex/hy-flex.vue +33 -88
  73. package/components/hy-flex/props.ts +58 -0
  74. package/components/hy-flex/typing.d.ts +14 -16
  75. package/components/hy-float-button/hy-float-button.vue +289 -406
  76. package/components/hy-float-button/props.ts +109 -25
  77. package/components/hy-folding-panel/hy-folding-panel.vue +74 -114
  78. package/components/hy-folding-panel/props.ts +42 -0
  79. package/components/hy-folding-panel/typing.d.ts +57 -57
  80. package/components/hy-folding-panel-item/hy-folding-panel-item.vue +139 -231
  81. package/components/hy-folding-panel-item/props.ts +81 -0
  82. package/components/hy-folding-panel-item/typing.d.ts +23 -23
  83. package/components/hy-form/hy-form.vue +172 -212
  84. package/components/hy-form/props.ts +37 -0
  85. package/components/hy-form/typing.d.ts +68 -61
  86. package/components/hy-form-group/typing.d.ts +74 -74
  87. package/components/hy-form-item/hy-form-item.vue +100 -129
  88. package/components/hy-form-item/props.ts +25 -0
  89. package/components/hy-form-item/typing.d.ts +40 -37
  90. package/components/hy-grid/hy-grid.vue +76 -132
  91. package/components/hy-grid/props.ts +58 -16
  92. package/components/hy-grid/typing.d.ts +66 -66
  93. package/components/hy-icon/hy-icon.vue +84 -161
  94. package/components/hy-icon/props.ts +76 -22
  95. package/components/hy-icon/typing.d.ts +83 -82
  96. package/components/hy-image/hy-image.vue +142 -272
  97. package/components/hy-image/props.ts +105 -23
  98. package/components/hy-image/typing.d.ts +84 -87
  99. package/components/hy-input/hy-input.vue +230 -421
  100. package/components/hy-input/props.ts +183 -35
  101. package/components/hy-input/typing.d.ts +169 -169
  102. package/components/hy-line/hy-line.vue +34 -72
  103. package/components/hy-line/props.ts +41 -10
  104. package/components/hy-line/typing.d.ts +29 -29
  105. package/components/hy-line-progress/hy-line-progress.vue +66 -101
  106. package/components/hy-line-progress/props.ts +31 -10
  107. package/components/hy-line-progress/typing.d.ts +29 -29
  108. package/components/hy-list/hy-list.vue +151 -220
  109. package/components/hy-list/props.ts +67 -16
  110. package/components/hy-list/typing.d.ts +52 -52
  111. package/components/hy-loading/hy-loading.vue +63 -119
  112. package/components/hy-loading/props.ts +63 -15
  113. package/components/hy-loading/typing.d.ts +49 -49
  114. package/components/hy-menu/hy-menu.vue +124 -166
  115. package/components/hy-menu/props.ts +42 -10
  116. package/components/hy-menu/typing.d.ts +60 -60
  117. package/components/hy-modal/hy-modal.vue +127 -218
  118. package/components/hy-modal/props.ts +89 -24
  119. package/components/hy-navbar/hy-navbar.vue +104 -177
  120. package/components/hy-navbar/props.ts +76 -22
  121. package/components/hy-navbar/typing.d.ts +81 -81
  122. package/components/hy-notice-bar/hy-notice-bar.vue +67 -144
  123. package/components/hy-notice-bar/props.ts +80 -19
  124. package/components/hy-notice-bar/typing.d.ts +62 -62
  125. package/components/hy-notify/hy-notify.vue +128 -177
  126. package/components/hy-notify/props.ts +49 -12
  127. package/components/hy-notify/typing.d.ts +45 -41
  128. package/components/hy-number-step/hy-number-step.vue +281 -394
  129. package/components/hy-number-step/props.ts +110 -27
  130. package/components/hy-number-step/typing.d.ts +120 -120
  131. package/components/hy-overlay/hy-overlay.vue +39 -66
  132. package/components/hy-overlay/props.ts +31 -8
  133. package/components/hy-pagination/hy-pagination.vue +100 -155
  134. package/components/hy-pagination/props.ts +53 -13
  135. package/components/hy-picker/hy-picker.vue +309 -430
  136. package/components/hy-picker/index.scss +8 -12
  137. package/components/hy-picker/props.ts +110 -26
  138. package/components/hy-popover/hy-popover.vue +190 -252
  139. package/components/hy-popover/props.ts +48 -10
  140. package/components/hy-popup/hy-popup.vue +162 -248
  141. package/components/hy-popup/props.ts +82 -18
  142. package/components/hy-price/hy-price.vue +45 -104
  143. package/components/hy-price/props.ts +52 -12
  144. package/components/hy-price/typing.d.ts +41 -36
  145. package/components/hy-qrcode/hy-qrcode.vue +115 -185
  146. package/components/hy-qrcode/props.ts +68 -18
  147. package/components/hy-qrcode/typing.d.ts +67 -66
  148. package/components/hy-radio/hy-radio.vue +161 -259
  149. package/components/hy-radio/props.ts +95 -25
  150. package/components/hy-radio/typing.d.ts +85 -84
  151. package/components/hy-rate/hy-rate.vue +185 -270
  152. package/components/hy-rate/props.ts +76 -18
  153. package/components/hy-rate/typing.d.ts +61 -60
  154. package/components/hy-read-more/hy-read-more.vue +93 -136
  155. package/components/hy-read-more/props.ts +43 -13
  156. package/components/hy-scroll-list/hy-scroll-list.vue +81 -102
  157. package/components/hy-scroll-list/props.ts +22 -11
  158. package/components/hy-search/hy-search.vue +155 -284
  159. package/components/hy-search/props.ts +130 -25
  160. package/components/hy-signature/hy-signature.vue +491 -635
  161. package/components/hy-signature/props.ts +115 -26
  162. package/components/hy-signature/typing.d.ts +138 -138
  163. package/components/hy-slider/hy-slider.vue +388 -477
  164. package/components/hy-slider/props.ts +75 -19
  165. package/components/hy-steps/hy-steps.vue +212 -279
  166. package/components/hy-steps/props.ts +47 -13
  167. package/components/hy-submit-bar/hy-submit-bar.vue +136 -221
  168. package/components/hy-submit-bar/props.ts +89 -20
  169. package/components/hy-submit-bar/typing.d.ts +87 -87
  170. package/components/hy-subsection/hy-subsection.vue +132 -185
  171. package/components/hy-subsection/props.ts +50 -17
  172. package/components/hy-subsection/typing.d.ts +52 -52
  173. package/components/hy-swipe-action/hy-swipe-action.vue +228 -283
  174. package/components/hy-swipe-action/props.ts +43 -18
  175. package/components/hy-swipe-action/typing.d.ts +46 -46
  176. package/components/hy-swiper/hy-swiper.vue +159 -286
  177. package/components/hy-swiper/props.ts +126 -28
  178. package/components/hy-swiper/typing.d.ts +115 -115
  179. package/components/hy-switch/hy-switch.vue +112 -176
  180. package/components/hy-switch/props.ts +60 -15
  181. package/components/hy-switch/typing.d.ts +63 -63
  182. package/components/hy-tabBar/hy-tabBar.vue +64 -60
  183. package/components/hy-tabs/hy-tabs.vue +277 -380
  184. package/components/hy-tabs/props.ts +75 -18
  185. package/components/hy-tag/hy-tag.vue +111 -204
  186. package/components/hy-tag/props.ts +81 -19
  187. package/components/hy-text/hy-text.vue +200 -322
  188. package/components/hy-text/props.ts +107 -28
  189. package/components/hy-textarea/hy-textarea.vue +147 -256
  190. package/components/hy-textarea/props.ts +112 -25
  191. package/components/hy-textarea/typing.d.ts +42 -42
  192. package/components/hy-toast/hy-toast.vue +135 -143
  193. package/components/hy-tooltip/hy-tooltip.vue +220 -306
  194. package/components/hy-tooltip/props.ts +79 -15
  195. package/components/hy-transition/hy-transition.vue +111 -138
  196. package/components/hy-transition/props.ts +30 -8
  197. package/components/hy-upload/hy-upload.vue +320 -469
  198. package/components/hy-upload/props.ts +130 -27
  199. package/components/hy-warn/hy-warn.vue +80 -129
  200. package/components/hy-warn/props.ts +47 -12
  201. package/components/hy-waterfall/hy-waterfall.vue +139 -163
  202. package/components/hy-waterfall/props.ts +19 -7
  203. package/components/hy-watermark/hy-watermark.vue +762 -870
  204. package/components/hy-watermark/props.ts +103 -22
  205. package/package.json +2 -2
  206. package/web-types.json +1 -1
@@ -1,325 +1,240 @@
1
1
  <template>
2
- <view class="hy-rate" :id="elId" ref="hy-rate" :style="[customStyle]">
3
- <view
4
- class="hy-rate__content"
5
- @touchmove.stop="touchMove"
6
- @touchend.stop="touchEnd"
7
- >
8
- <view
9
- class="hy-rate__content--item cursor-pointer"
10
- v-for="(item, index) in Number(count)"
11
- :key="index"
12
- :class="[elClass]"
13
- >
14
- <view
15
- class="hy-rate__content--item__icon-wrap"
16
- ref="hy-rate__content--item__icon-wrap"
17
- @tap.stop="clickHandler($event)"
18
- >
19
- <HyIcon
20
- :name="Math.floor(activeIndex) > index ? activeIcon : inactiveIcon"
21
- :color="
22
- disabled
23
- ? '#c8c9cc'
24
- : Math.floor(activeIndex) > index
25
- ? activeColor
26
- : inactiveColor
27
- "
28
- :custom-style="{
29
- padding: `0 ${addUnit(gutter / 2)}`,
30
- }"
31
- :size="size"
32
- ></HyIcon>
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
- name: "hy-rate",
68
- options: {
69
- addGlobalClass: true,
70
- virtualHost: true,
71
- styleIsolation: "shared",
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 "vue";
78
- import type { CSSProperties, PropType } from "vue";
79
- import type { IRateEmits } from "./typing";
80
- import { addUnit, getRect, guid, range, sleep, IconConfig } from "../../libs";
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 "../hy-icon/hy-icon.vue";
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
- // const props = withDefaults(defineProps<IProps>(), defaultProps)
91
- const props = defineProps({
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
- () => props.modelValue,
177
- (newValue) => {
178
- activeIndex.value = newValue;
179
- },
180
- );
99
+ () => props.modelValue,
100
+ (newValue) => {
101
+ activeIndex.value = newValue
102
+ }
103
+ )
181
104
  watch(
182
- () => activeIndex.value,
183
- () => {
184
- emitEvent();
185
- },
186
- );
187
- const instance = getCurrentInstance();
105
+ () => activeIndex.value,
106
+ () => {
107
+ emitEvent()
108
+ }
109
+ )
110
+ const instance = getCurrentInstance()
188
111
 
189
112
  onMounted(() => {
190
- init();
191
- });
113
+ init()
114
+ })
192
115
 
193
116
  const init = () => {
194
- sleep(300).then(async () => {
195
- await getRateItemRect();
196
- await getRateIconWrapRect();
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
- await sleep();
205
- // #ifndef APP-NVUE
206
- const res: UniApp.NodeInfo = (await getRect(
207
- `#${elId}`,
208
- false,
209
- instance,
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
- // uView封装的获取节点的方法,详见文档
220
- // #ifndef APP-NVUE
221
- const res: UniApp.NodeInfo = (await getRect(
222
- `.${elClass}`,
223
- false,
224
- instance,
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
- if (!props.touchable) {
233
- return;
234
- }
235
- e.stopPropagation();
236
- const x = e.changedTouches[0].pageX;
237
- getActiveIndex(x);
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
- if (!props.touchable) {
243
- return;
244
- }
245
- e.stopPropagation();
246
- const x = e.changedTouches[0].pageX;
247
- getActiveIndex(x);
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
- // if (moving.value) {
252
- // return;
253
- // }
254
- e.stopPropagation();
255
- console.log(e, "微信");
256
- let x = 0;
257
- // #ifndef APP-NVUE || MP-ALIPAY
258
- x = e.detail.x;
259
- // #endif
260
- // #ifdef MP-ALIPAY
261
- x = e.detail.pageX;
262
- // #endif
263
- getActiveIndex(x, true);
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
- // 发出change事件
268
- emit("change", activeIndex.value);
269
- // 同时修改双向绑定的值
270
- emit("update:modelValue", activeIndex.value);
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
- if (props.disabled || props.readonly) {
275
- return;
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
- } else {
296
- index = Math.floor(distance / rateWidth.value);
297
- // 取余,判断小数的区间范围
298
- const decimal = distance % rateWidth.value;
299
- // 非半星时,只有超过了图标的一半距离,才认为是选择了这颗星
300
- if (isClick) {
301
- if (decimal > 0) index++;
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
- if (decimal > rateWidth.value / 2) index++;
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
- // 设置延时为了让click事件在touchmove之前触发
313
- setTimeout(() => {
314
- moving.value = true;
315
- }, 10);
316
- // 一定时间后,取消标识为移动中状态,是为了让click事件无效
317
- setTimeout(() => {
318
- moving.value = false;
319
- }, 10);
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 "./index.scss";
239
+ @import './index.scss';
325
240
  </style>
@@ -1,19 +1,77 @@
1
- import { ColorConfig, IconConfig } from "../../libs/config";
2
- import type IProps from "./typing";
1
+ import { IconConfig } from '../../libs/config'
2
+ import type { CSSProperties, PropType } from 'vue'
3
3
 
4
- const defaultProps: IProps = {
5
- modelValue: 1,
6
- count: 5,
7
- disabled: false,
8
- readonly: false,
9
- size: 18,
10
- inactiveColor: "#b2b2b2",
11
- activeColor: "#FFF00D",
12
- gutter: 4,
13
- minCount: 1,
14
- allowHalf: false,
15
- activeIcon: IconConfig.STAR_FILL,
16
- inactiveIcon: IconConfig.STAR,
17
- touchable: true,
18
- };
19
- export default defaultProps;
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