hy-app 0.1.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/README.md +42 -0
  2. package/api/http.ts +138 -0
  3. package/api/index.ts +1 -0
  4. package/common/index.ts +1 -0
  5. package/common/versionControl.ts +102 -0
  6. package/components/dialog/TheDialog.vue +128 -0
  7. package/components/dialog/index.ts +38 -0
  8. package/components/hy-address-picker/hy-address-picker.vue +262 -0
  9. package/components/hy-address-picker/props.ts +27 -0
  10. package/components/hy-address-picker/typing.d.ts +98 -0
  11. package/components/hy-avatar/hy-avatar.vue +217 -0
  12. package/components/hy-avatar/props.ts +20 -0
  13. package/components/hy-avatar/typing.d.ts +64 -0
  14. package/components/hy-back-top/hy-back-top.vue +71 -0
  15. package/components/hy-back-top/props.ts +23 -0
  16. package/components/hy-back-top/typing.d.ts +49 -0
  17. package/components/hy-badge/hy-badge.vue +155 -0
  18. package/components/hy-badge/props.ts +19 -0
  19. package/components/hy-badge/typing.d.ts +60 -0
  20. package/components/hy-button/hy-button.vue +394 -0
  21. package/components/hy-button/props.ts +36 -0
  22. package/components/hy-button/typing.d.ts +125 -0
  23. package/components/hy-card/hy-card.vue +198 -0
  24. package/components/hy-card/props.ts +29 -0
  25. package/components/hy-card/typing.d.ts +112 -0
  26. package/components/hy-cell/hy-cell.vue +268 -0
  27. package/components/hy-cell/props.ts +20 -0
  28. package/components/hy-cell/typing.d.ts +98 -0
  29. package/components/hy-check-button/hy-check-button.vue +71 -0
  30. package/components/hy-check-button/props.ts +20 -0
  31. package/components/hy-check-button/typing.d.ts +79 -0
  32. package/components/hy-checkbox/hy-checkbox.vue +299 -0
  33. package/components/hy-checkbox/props.ts +28 -0
  34. package/components/hy-checkbox/typing.d.ts +77 -0
  35. package/components/hy-datetime-picker/hy-datetime-picker.vue +584 -0
  36. package/components/hy-datetime-picker/props.ts +36 -0
  37. package/components/hy-datetime-picker/typing.d.ts +135 -0
  38. package/components/hy-divider/hy-divider.vue +164 -0
  39. package/components/hy-divider/props.ts +21 -0
  40. package/components/hy-divider/typing.d.ts +64 -0
  41. package/components/hy-empty/hy-empty.vue +122 -0
  42. package/components/hy-empty/props.ts +21 -0
  43. package/components/hy-empty/typing.d.ts +68 -0
  44. package/components/hy-folding-panel/hy-folding-panel.vue +94 -0
  45. package/components/hy-folding-panel/props.ts +17 -0
  46. package/components/hy-folding-panel/typing.d.ts +59 -0
  47. package/components/hy-form/hy-form.vue +372 -0
  48. package/components/hy-form/props.ts +15 -0
  49. package/components/hy-form/typing.d.ts +51 -0
  50. package/components/hy-grid/hy-grid.vue +126 -0
  51. package/components/hy-grid/props.ts +16 -0
  52. package/components/hy-grid/typing.d.ts +62 -0
  53. package/components/hy-icon/hy-icon.vue +207 -0
  54. package/components/hy-icon/props.ts +24 -0
  55. package/components/hy-icon/typing.d.ts +80 -0
  56. package/components/hy-input/hy-input.vue +402 -0
  57. package/components/hy-input/props.ts +41 -0
  58. package/components/hy-input/typing.d.ts +148 -0
  59. package/components/hy-line/hy-line.vue +44 -0
  60. package/components/hy-line/props.ts +12 -0
  61. package/components/hy-line/typing.d.ts +32 -0
  62. package/components/hy-line-progress/hy-line-progress.vue +118 -0
  63. package/components/hy-line-progress/props.ts +12 -0
  64. package/components/hy-line-progress/typing.d.ts +28 -0
  65. package/components/hy-list/hy-list.vue +250 -0
  66. package/components/hy-list/props.ts +18 -0
  67. package/components/hy-list/typing.d.ts +50 -0
  68. package/components/hy-login/ThePhoneLogin.vue +106 -0
  69. package/components/hy-login/TheUserLogin.vue +391 -0
  70. package/components/hy-login/hy-login.vue +283 -0
  71. package/components/hy-login/props.ts +32 -0
  72. package/components/hy-login/typing.d.ts +60 -0
  73. package/components/hy-modal/hy-modal.vue +240 -0
  74. package/components/hy-modal/props.ts +24 -0
  75. package/components/hy-modal/typing.d.ts +70 -0
  76. package/components/hy-navbar/hy-navbar.vue +194 -0
  77. package/components/hy-navbar/props.ts +24 -0
  78. package/components/hy-navbar/typing.d.ts +81 -0
  79. package/components/hy-notice-bar/hy-column-notice.vue +130 -0
  80. package/components/hy-notice-bar/hy-notice-bar.vue +82 -0
  81. package/components/hy-notice-bar/hy-row-notice.vue +182 -0
  82. package/components/hy-notice-bar/props.ts +19 -0
  83. package/components/hy-notice-bar/typing.d.ts +56 -0
  84. package/components/hy-number-step/hy-number-step.vue +428 -0
  85. package/components/hy-number-step/props.ts +29 -0
  86. package/components/hy-number-step/typing.d.ts +104 -0
  87. package/components/hy-overlay/hy-overlay.vue +54 -0
  88. package/components/hy-overlay/props.ts +10 -0
  89. package/components/hy-overlay/typing.d.ts +24 -0
  90. package/components/hy-picker/hy-picker.vue +499 -0
  91. package/components/hy-picker/props.ts +30 -0
  92. package/components/hy-picker/typing.d.ts +115 -0
  93. package/components/hy-popup/hy-popup.vue +269 -0
  94. package/components/hy-popup/props.ts +21 -0
  95. package/components/hy-popup/typing.d.ts +68 -0
  96. package/components/hy-price/hy-price.vue +86 -0
  97. package/components/hy-price/props.ts +13 -0
  98. package/components/hy-price/typing.d.ts +36 -0
  99. package/components/hy-qrcode/hy-qrcode.vue +153 -0
  100. package/components/hy-qrcode/props.ts +20 -0
  101. package/components/hy-qrcode/qrcode.js +1364 -0
  102. package/components/hy-qrcode/typing.d.ts +64 -0
  103. package/components/hy-radio/hy-radio.vue +319 -0
  104. package/components/hy-radio/props.ts +28 -0
  105. package/components/hy-radio/typing.d.ts +85 -0
  106. package/components/hy-rate/hy-rate.vue +261 -0
  107. package/components/hy-rate/props.ts +18 -0
  108. package/components/hy-rate/typing.d.ts +60 -0
  109. package/components/hy-read-more/hy-read-more.vue +134 -0
  110. package/components/hy-read-more/props.ts +20 -0
  111. package/components/hy-read-more/typing.d.ts +44 -0
  112. package/components/hy-safe-bottom/hy-safe-bottom.vue +64 -0
  113. package/components/hy-scroll-list/hy-scroll-list.vue +146 -0
  114. package/components/hy-scroll-list/props.ts +12 -0
  115. package/components/hy-scroll-list/typing.d.ts +28 -0
  116. package/components/hy-search/hy-search.vue +294 -0
  117. package/components/hy-search/props.ts +29 -0
  118. package/components/hy-search/typing.d.ts +109 -0
  119. package/components/hy-slider/hy-slider.vue +511 -0
  120. package/components/hy-slider/props.ts +21 -0
  121. package/components/hy-slider/typing.d.ts +68 -0
  122. package/components/hy-steps/hy-steps.vue +352 -0
  123. package/components/hy-steps/props.ts +15 -0
  124. package/components/hy-steps/typing.d.ts +58 -0
  125. package/components/hy-subsection/hy-subsection.vue +272 -0
  126. package/components/hy-subsection/props.ts +16 -0
  127. package/components/hy-subsection/typing.d.ts +44 -0
  128. package/components/hy-swiper/hy-swiper-indicator.vue +105 -0
  129. package/components/hy-swiper/hy-swiper.vue +242 -0
  130. package/components/hy-swiper/props.ts +30 -0
  131. package/components/hy-swiper/typing.d.ts +107 -0
  132. package/components/hy-switch/hy-switch.vue +168 -0
  133. package/components/hy-switch/props.ts +16 -0
  134. package/components/hy-switch/typing.d.ts +48 -0
  135. package/components/hy-tabs/hy-tabs.vue +416 -0
  136. package/components/hy-tabs/props.ts +26 -0
  137. package/components/hy-tabs/typing.d.ts +86 -0
  138. package/components/hy-tag/hy-tag.vue +374 -0
  139. package/components/hy-tag/props.ts +22 -0
  140. package/components/hy-tag/typing.d.ts +76 -0
  141. package/components/hy-textarea/hy-textarea.vue +229 -0
  142. package/components/hy-textarea/props.ts +26 -0
  143. package/components/hy-textarea/typing.d.ts +27 -0
  144. package/components/hy-tooltip/hy-tooltip.vue +332 -0
  145. package/components/hy-tooltip/props.ts +17 -0
  146. package/components/hy-tooltip/typing.d.ts +52 -0
  147. package/components/hy-transition/hy-transition.vue +150 -0
  148. package/components/hy-transition/index.scss +113 -0
  149. package/components/hy-transition/props.ts +10 -0
  150. package/components/hy-transition/typing.d.ts +36 -0
  151. package/components/hy-upload/hy-upload.vue +557 -0
  152. package/components/hy-upload/props.ts +29 -0
  153. package/components/hy-upload/typing.d.ts +147 -0
  154. package/components/hy-warn/hy-warn.vue +228 -0
  155. package/components/hy-warn/props.ts +14 -0
  156. package/components/hy-warn/typing.d.ts +40 -0
  157. package/components/hy-waterfall/hy-waterfall.vue +51 -0
  158. package/components/hy-waterfall/props.ts +10 -0
  159. package/components/hy-waterfall/typing.d.ts +20 -0
  160. package/components/index.ts +162 -0
  161. package/components/message/TheMessage.vue +169 -0
  162. package/components/message/index.ts +54 -0
  163. package/components/u-form/form.js +22 -0
  164. package/components/u-form/hy-form.vue +324 -0
  165. package/components/u-form/props.js +49 -0
  166. package/components/u-form/schema.js +1451 -0
  167. package/components/u-form/u-form.vue +267 -0
  168. package/components/u-form/utils.js +65 -0
  169. package/components/u-form-item/formItem.js +24 -0
  170. package/components/u-form-item/hy-form-item.vue +360 -0
  171. package/components/u-form-item/props.js +57 -0
  172. package/components/u-form-item/u-form-item.vue +294 -0
  173. package/components/yk-dialog/yk-dialog.vue +129 -0
  174. package/components/yk-tabbar/props.ts +49 -0
  175. package/components/yk-tabbar/yk-tabbar.vue +224 -0
  176. package/config/color.ts +6 -0
  177. package/config/icon.ts +366 -0
  178. package/config/index.ts +2 -0
  179. package/global/index.ts +6 -0
  180. package/global/register-properties.ts +37 -0
  181. package/index.ts +8 -0
  182. package/libs/css/common.scss +0 -0
  183. package/libs/css/iconfont.css +379 -0
  184. package/libs/css/iconfont.ttf +0 -0
  185. package/libs/css/mixin.scss +15 -0
  186. package/package.json +42 -0
  187. package/public/icons/error.png +0 -0
  188. package/public/icons/success.png +0 -0
  189. package/public/icons/warning.png +0 -0
  190. package/store/index.ts +1 -0
  191. package/store/userInfo.ts +25 -0
  192. package/theme.scss +94 -0
  193. package/typing/index.ts +7 -0
  194. package/typing/modules/common.d.ts +50 -0
  195. package/typing/modules/dialog.ts +17 -0
  196. package/typing/modules/enum.ts +67 -0
  197. package/typing/modules/form.ts +161 -0
  198. package/typing/modules/http.ts +68 -0
  199. package/typing/modules/icon.d.ts +366 -0
  200. package/typing/modules/img.ts +15 -0
  201. package/typing/modules/rect.ts +10 -0
  202. package/utils/address.json +5890 -0
  203. package/utils/base64.ts +119 -0
  204. package/utils/index.ts +3 -0
  205. package/utils/inside.ts +310 -0
  206. package/utils/utils.ts +446 -0
@@ -0,0 +1,352 @@
1
+ <template>
2
+ <view :class="[`hy-steps--${direction}`, 'hy-steps']">
3
+ <template v-for="(item, i) in list" :key="i">
4
+ <view
5
+ ref="hy-steps-item"
6
+ :class="[`hy-steps-item--${direction}`, 'hy-steps-item']"
7
+ >
8
+ <!-- 线条 -->
9
+ <view
10
+ v-if="i + 1 < list.length"
11
+ :class="[`hy-steps-item__line--${direction}`, 'hy-steps-item__line']"
12
+ :style="lineStyle(item, i)"
13
+ ></view>
14
+ <view
15
+ :class="[
16
+ `hy-steps-item__wrapper--${direction}`,
17
+ dot && `hy-steps-item__wrapper--${direction}--dot`,
18
+ 'hy-steps-item__wrapper'
19
+ ]"
20
+ :style="itemStyleInner"
21
+ >
22
+ <slot name="icon" :error="item.error" :index="i">
23
+ <view
24
+ class="hy-steps-item__wrapper__dot"
25
+ v-if="dot"
26
+ :style="{
27
+ backgroundColor: statusColor(i, item.error)
28
+ }"
29
+ >
30
+ </view>
31
+ <view
32
+ class="hy-steps-item__wrapper__icon"
33
+ v-else-if="activeIcon || inactiveIcon"
34
+ >
35
+ <HyIcon
36
+ :name="i <= current ? activeIcon : inactiveIcon"
37
+ :size="iconSize"
38
+ :color="i <= current ? activeColor : inactiveColor"
39
+ >
40
+ </HyIcon>
41
+ </view>
42
+ <view
43
+ v-else
44
+ :style="{
45
+ backgroundColor:
46
+ statusClass(i, item.error) === 'process'
47
+ ? activeColor
48
+ : 'transparent',
49
+ borderColor: statusColor(i, item?.error)
50
+ }"
51
+ class="hy-steps-item__wrapper__circle"
52
+ >
53
+ <text
54
+ v-if="
55
+ statusClass(i, item.error) === 'process' ||
56
+ statusClass(i, item.error) === 'wait'
57
+ "
58
+ class="hy-steps-item__wrapper__circle__text"
59
+ :style="{
60
+ color: i == current ? '#ffffff' : inactiveColor
61
+ }"
62
+ >{{ i + 1 }}</text
63
+ >
64
+ <HyIcon
65
+ v-else
66
+ :color="
67
+ statusClass(i, item.error) === 'error' ? 'error' : activeColor
68
+ "
69
+ :size="iconSize"
70
+ :name="
71
+ statusClass(i, item.error) === 'error'
72
+ ? IconConfig.CLOSE
73
+ : IconConfig.CHECK_MASK
74
+ "
75
+ ></HyIcon>
76
+ </view>
77
+ </slot>
78
+ </view>
79
+
80
+ <!-- 内容 -->
81
+ <view
82
+ class="hy-steps-item__content"
83
+ :class="[`hy-steps-item__content--${direction}`]"
84
+ :style="[contentStyle]"
85
+ >
86
+ <slot name="content" :record="item" :index="i">
87
+ <template>
88
+ <slot name="title" :title="item.title" :index="i">
89
+ <text
90
+ :style="{
91
+ lineHeight: '20px',
92
+ fontSize: current == i ? '14px' : '13px',
93
+ color: i == current ? '#2c405a' : '#555555'
94
+ }"
95
+ >{{ item.title }}</text
96
+ >
97
+ </slot>
98
+ <slot name="desc" :desc="item.desc" :index="i">
99
+ <text :style="{ fontSize: '12px', color: '#999' }">{{
100
+ item.desc
101
+ }}</text>
102
+ </slot>
103
+ </template>
104
+ </slot>
105
+ </view>
106
+ </view>
107
+ </template>
108
+ </view>
109
+ </template>
110
+
111
+ <script setup lang="ts">
112
+ import { computed, CSSProperties, toRefs, ref, onMounted } from "vue";
113
+ import defaultProps from "./props";
114
+ import IProps, { StepListVo } from "./typing";
115
+ import { addUnit, getRect } from "../../utils";
116
+ import { ColorConfig, IconConfig } from "../../config";
117
+
118
+ // 组件
119
+ import HyIcon from "../hy-icon/hy-icon.vue";
120
+
121
+ const props = withDefaults(defineProps<IProps>(), defaultProps);
122
+ const { current, direction, dot, inactiveColor, activeColor } = toRefs(props);
123
+ const emit = defineEmits(["click", "update:current"]);
124
+
125
+ const showLine = ref(false);
126
+ const size = ref<UniApp.NodeInfo>({
127
+ height: 0,
128
+ width: 0
129
+ });
130
+
131
+ const lineStyle = computed(() => {
132
+ return (temp: StepListVo, index: number): CSSProperties => {
133
+ const style: CSSProperties = {};
134
+ if (direction.value === "row") {
135
+ style.width = addUnit(size.value.width);
136
+ style.left = addUnit(size.value.width! / 2);
137
+ } else {
138
+ style.height = addUnit(size.value.height);
139
+ // style.top = addUnit(size.width / 2)
140
+ }
141
+ style.backgroundColor = temp.error
142
+ ? ColorConfig.error
143
+ : index < current.value
144
+ ? activeColor.value
145
+ : inactiveColor.value;
146
+ return style;
147
+ };
148
+ });
149
+ // const itemStyleInner = () => {
150
+ // return {
151
+ // ...itemStyle.value
152
+ // }
153
+ // }
154
+ const itemStyleInner = computed(() => {
155
+ return {};
156
+ });
157
+ /**
158
+ * @description 状态类名
159
+ * */
160
+ const statusClass = computed(() => {
161
+ return (index: number, error: boolean = false) => {
162
+ if (current.value == index) {
163
+ return error ? "error" : "process";
164
+ } else if (error) {
165
+ return "error";
166
+ } else if (current.value > index) {
167
+ return "finish";
168
+ } else {
169
+ return "wait";
170
+ }
171
+ };
172
+ });
173
+ const statusColor = computed(() => {
174
+ return (index: number, error: boolean) => {
175
+ let colorTmp = "";
176
+ switch (statusClass.value(index, error)) {
177
+ case "finish":
178
+ colorTmp = activeColor.value;
179
+ break;
180
+ case "error":
181
+ colorTmp = ColorConfig.error;
182
+ break;
183
+ case "process":
184
+ colorTmp = dot.value ? activeColor.value : "transparent";
185
+ break;
186
+ default:
187
+ colorTmp = inactiveColor.value;
188
+ break;
189
+ }
190
+ return colorTmp;
191
+ };
192
+ });
193
+
194
+ const contentStyle = computed<CSSProperties>(() => {
195
+ const style: CSSProperties = {};
196
+ if (direction.value === "column") {
197
+ style.marginLeft = dot.value ? "2px" : "6px";
198
+ style.marginTop = dot.value ? "0px" : "6px";
199
+ } else {
200
+ style.marginTop = dot.value ? "2px" : "6px";
201
+ style.marginLeft = dot.value ? "2px" : "6px";
202
+ }
203
+
204
+ return style;
205
+ });
206
+
207
+ onMounted(() => {
208
+ getStepsItemRect();
209
+ });
210
+
211
+ // 获取组件的尺寸,用于设置横线的位置
212
+ const getStepsItemRect = () => {
213
+ getRect(".hy-steps-item").then((rect) => {
214
+ size.value = rect as UniApp.NodeInfo;
215
+ });
216
+ };
217
+ </script>
218
+
219
+ <style lang="scss" scoped>
220
+ @import "../../libs/css/mixin.scss";
221
+ @import "../../theme.scss";
222
+
223
+ .hy-steps {
224
+ @include flex;
225
+
226
+ &--column {
227
+ flex-direction: column;
228
+ }
229
+
230
+ &--row {
231
+ flex-direction: row;
232
+ flex: 1;
233
+ /* #ifdef MP */
234
+ display: grid;
235
+ grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
236
+ /* #endif */
237
+ }
238
+
239
+ &-item {
240
+ flex: 1;
241
+ @include flex;
242
+
243
+ &--row {
244
+ flex-direction: column;
245
+ align-items: center;
246
+ position: relative;
247
+ }
248
+
249
+ &--column {
250
+ position: relative;
251
+ flex-direction: row;
252
+ justify-content: flex-start;
253
+ padding-bottom: 5px;
254
+ }
255
+
256
+ &__wrapper {
257
+ @include flex;
258
+ justify-content: center;
259
+ align-items: center;
260
+ position: relative;
261
+ background-color: #fff;
262
+ border-radius: 50px;
263
+
264
+ &--column {
265
+ width: 20px;
266
+ height: 20px;
267
+
268
+ &--dot {
269
+ height: 20px;
270
+ width: 20px;
271
+ }
272
+ }
273
+
274
+ &--row {
275
+ width: 20px;
276
+ height: 20px;
277
+
278
+ &--dot {
279
+ width: 20px;
280
+ height: 20px;
281
+ }
282
+ }
283
+
284
+ &__circle {
285
+ width: 20px;
286
+ height: 20px;
287
+ /* #ifndef APP-NVUE */
288
+ box-sizing: border-box;
289
+ flex-shrink: 0;
290
+ /* #endif */
291
+ border-radius: 100px;
292
+ border-width: 1px;
293
+ border-color: $hy-tips-color;
294
+ border-style: solid;
295
+ @include flex(row);
296
+ align-items: center;
297
+ justify-content: center;
298
+ transition: background-color 0.3s;
299
+
300
+ &__text {
301
+ color: $hy-tips-color;
302
+ font-size: 11px;
303
+ @include flex(row);
304
+ align-items: center;
305
+ justify-content: center;
306
+ text-align: center;
307
+ line-height: 11px;
308
+ }
309
+ }
310
+
311
+ &__dot {
312
+ width: 10px;
313
+ height: 10px;
314
+ border-radius: 100px;
315
+ background-color: $hy-color-subtitle;
316
+ }
317
+ }
318
+
319
+ &__content {
320
+ @include flex;
321
+ flex: 1;
322
+
323
+ &--row {
324
+ flex-direction: column;
325
+ align-items: center;
326
+ }
327
+
328
+ &--column {
329
+ flex-direction: column;
330
+ justify-content: flex-start;
331
+ margin-left: 6px;
332
+ min-height: 60px;
333
+ }
334
+ }
335
+
336
+ &__line {
337
+ position: absolute;
338
+ background: $hy-tips-color;
339
+
340
+ &--row {
341
+ top: 10px;
342
+ height: 1px;
343
+ }
344
+
345
+ &--column {
346
+ width: 1px;
347
+ left: 10px;
348
+ }
349
+ }
350
+ }
351
+ }
352
+ </style>
@@ -0,0 +1,15 @@
1
+ import IProps from "./typing";
2
+
3
+ const defaultProps: IProps = {
4
+ list: [],
5
+ direction: "row",
6
+ current: 0,
7
+ activeColor: "#3c9cff",
8
+ inactiveColor: "#969799",
9
+ activeIcon: "",
10
+ inactiveIcon: "",
11
+ dot: false,
12
+ iconSize: 17
13
+ };
14
+
15
+ export default defaultProps;
@@ -0,0 +1,58 @@
1
+ import { CSSProperties } from "vue";
2
+
3
+ export interface StepListVo {
4
+ /**
5
+ * @description 标题
6
+ * */
7
+ title?: string;
8
+ /**
9
+ * @description 描述
10
+ * */
11
+ desc?: string;
12
+ /**
13
+ * @description 是否错误
14
+ * */
15
+ error?: boolean;
16
+ }
17
+ export default interface IProps {
18
+ /**
19
+ * @description 设置当前处于第几步 (默认 0 )
20
+ * */
21
+ current: number;
22
+ /**
23
+ * @description 步骤条的数据集
24
+ * */
25
+ list: StepListVo[];
26
+ /**
27
+ * @description row-横向,column-竖向 (默认 'row' )
28
+ * */
29
+ direction?: HyApp.PermutationType;
30
+ /**
31
+ * @description 激活状态颜色 (默认 '#3c9cff' )
32
+ * */
33
+ activeColor?: string;
34
+ /**
35
+ * @description 未激活状态颜色 (默认 '#969799' )
36
+ * */
37
+ inactiveColor?: string;
38
+ /**
39
+ * @description 激活状态的图标
40
+ * */
41
+ activeIcon?: string;
42
+ /**
43
+ * @description 未激活状态图标
44
+ * */
45
+ inactiveIcon?: string;
46
+ /**
47
+ * @description 是否显示点类型 (默认 false )
48
+ * */
49
+ dot?: boolean;
50
+ /**
51
+ * @description 图标大小 (默认 17 )
52
+ * */
53
+ iconSize?: string | number;
54
+ /**
55
+ * @description 定义需要用到的外部样式
56
+ * */
57
+ customStyle?: CSSProperties;
58
+ }
@@ -0,0 +1,272 @@
1
+ <template>
2
+ <view
3
+ ref="hy-subsection"
4
+ :class="[`hy-subsection--${mode}`, 'hy-subsection']"
5
+ :style="[customStyle, wrapperStyle]"
6
+ >
7
+ <view ref="hy-subsection__bar" :style="barStyle" :class="barClass"></view>
8
+ <view
9
+ :class="wrapperClass"
10
+ :ref="`hy-subsection__item--${index}`"
11
+ :style="itemStyle"
12
+ @tap="clickHandler(index)"
13
+ v-for="(item, index) in list"
14
+ :key="index"
15
+ >
16
+ <text class="hy-subsection__item__text" :style="[textStyle(index)]">{{
17
+ getText(item)
18
+ }}</text>
19
+ </view>
20
+ </view>
21
+ </template>
22
+
23
+ <script setup lang="ts">
24
+ import { computed, CSSProperties, toRefs, ref, onMounted } from "vue";
25
+ import defaultProps from "./props";
26
+ import IProps from "./typing";
27
+ import { addUnit, getRect } from "../../utils";
28
+
29
+ const props = withDefaults(defineProps<IProps>(), defaultProps);
30
+ const {
31
+ current,
32
+ list,
33
+ mode,
34
+ activeColor,
35
+ fontSize,
36
+ bold,
37
+ bgColor,
38
+ inactiveColor,
39
+ keyName
40
+ } = toRefs(props);
41
+ const emit = defineEmits(["change"]);
42
+
43
+ // 组件尺寸
44
+ const itemRect = ref<UniApp.NodeInfo>({
45
+ width: 0,
46
+ height: 0
47
+ });
48
+ const innerCurrent = ref<number>(0);
49
+
50
+ /**
51
+ * @description 容器样式
52
+ * */
53
+ const wrapperStyle = computed<CSSProperties>(() => {
54
+ const style: CSSProperties = {};
55
+ // button模式时,设置背景色
56
+ if (mode.value === "button") {
57
+ style.backgroundColor = bgColor.value;
58
+ }
59
+ return style;
60
+ });
61
+ /**
62
+ * @description 容器类名
63
+ * */
64
+ const wrapperClass = computed(() => {
65
+ return [
66
+ "hy-subsection__item",
67
+ "cursor-pointer",
68
+ `hy-subsection__item--${innerCurrent.value}`,
69
+ innerCurrent.value < list.value.length - 1 &&
70
+ "hy-subsection__item--no-border-right",
71
+ innerCurrent.value === 0 && "hy-subsection__item--first",
72
+ innerCurrent.value === list.value.length - 1 && "hy-subsection__item--last"
73
+ ];
74
+ });
75
+ /**
76
+ * @description 滑块的样式
77
+ * */
78
+ const barStyle = computed<CSSProperties>(() => {
79
+ const style: CSSProperties = {};
80
+ style.width = `${itemRect.value.width}px`;
81
+ style.height = `${itemRect.value.height}px`;
82
+ // 通过translateX移动滑块,其移动的距离为索引*item的宽度
83
+ style.transform = `translateX(${
84
+ innerCurrent.value * itemRect.value.width!
85
+ }px)`;
86
+ if (mode.value === "subsection") {
87
+ // 在subsection模式下,需要动态设置滑块的圆角,因为移动滑块使用的是translateX,无法通过父元素设置overflow: hidden隐藏滑块的直角
88
+ style.backgroundColor = activeColor.value;
89
+ }
90
+ return style;
91
+ });
92
+ /**
93
+ * @description 滑块的类目
94
+ * */
95
+ const barClass = computed(() => {
96
+ let className: string[] = ["hy-subsection__bar", "cursor-pointer"];
97
+ const className_2 = [
98
+ mode.value === "button" && "hy-subsection--button__bar",
99
+ innerCurrent.value === 0 &&
100
+ mode.value === "subsection" &&
101
+ "hy-subsection__bar--first",
102
+ innerCurrent.value > 0 &&
103
+ innerCurrent.value < list.value.length - 1 &&
104
+ mode.value === "subsection" &&
105
+ "hy-subsection__bar--center",
106
+ innerCurrent.value === list.value.length - 1 &&
107
+ mode.value === "subsection" &&
108
+ "hy-subsection__bar--last"
109
+ ].filter(Boolean) as string[];
110
+ className = className.concat(className_2);
111
+
112
+ return className;
113
+ });
114
+ /**
115
+ * @description 分段器item的样式
116
+ * */
117
+ const itemStyle = computed(() => {
118
+ return (): CSSProperties => {
119
+ const style: CSSProperties = {};
120
+ if (mode.value === "subsection") {
121
+ // 设置border的样式
122
+ style.borderColor = activeColor.value;
123
+ style.borderWidth = "1px";
124
+ style.borderStyle = "solid";
125
+ }
126
+ return style;
127
+ };
128
+ });
129
+ /**
130
+ * @description 分段器文字颜色
131
+ * */
132
+ const textStyle = computed(() => {
133
+ return (index: number): CSSProperties => {
134
+ const style: CSSProperties = {};
135
+ style.fontWeight =
136
+ bold.value && innerCurrent.value === index ? "bold" : "normal";
137
+ style.fontSize = addUnit(fontSize.value);
138
+ // subsection模式下,激活时默认为白色的文字
139
+ if (mode.value === "subsection") {
140
+ style.color = innerCurrent.value === index ? "#fff" : inactiveColor.value;
141
+ } else {
142
+ // button模式下,激活时文字颜色默认为activeColor
143
+ style.color =
144
+ innerCurrent.value === index ? activeColor.value : inactiveColor.value;
145
+ }
146
+ return style;
147
+ };
148
+ });
149
+
150
+ onMounted(() => {
151
+ init();
152
+ });
153
+
154
+ /**
155
+ * @description 初始化
156
+ * */
157
+ const init = () => {
158
+ innerCurrent.value = current.value;
159
+ getRect(".hy-subsection__item--0").then((size) => {
160
+ itemRect.value = size as UniApp.NodeInfo;
161
+ });
162
+ };
163
+ /**
164
+ * @description 判断展示文本
165
+ * */
166
+ const getText = (item: string | Record<string, string>) => {
167
+ return typeof item === "object" ? item[keyName.value] : item;
168
+ };
169
+ /**
170
+ * @description 点击事件
171
+ * */
172
+ const clickHandler = (index: number) => {
173
+ // 值改变才触发
174
+ if (innerCurrent.value !== index) {
175
+ emit("change", index);
176
+ }
177
+ innerCurrent.value = index;
178
+ };
179
+ </script>
180
+
181
+ <style lang="scss" scoped>
182
+ @import "../../libs/css/mixin.scss";
183
+
184
+ .hy-subsection {
185
+ @include flex;
186
+ position: relative;
187
+ overflow: hidden;
188
+ /* #ifndef APP-NVUE */
189
+ width: 100%;
190
+ box-sizing: border-box;
191
+ /* #endif */
192
+
193
+ &--button {
194
+ height: 35px;
195
+ background-color: rgb(238, 238, 239);
196
+ padding: 3px;
197
+ border-radius: 4px;
198
+ align-items: stretch;
199
+
200
+ &__bar {
201
+ background-color: #ffffff;
202
+ border-radius: 4px !important;
203
+ }
204
+ }
205
+
206
+ &--subsection {
207
+ height: 32px;
208
+ }
209
+
210
+ &__bar {
211
+ position: absolute;
212
+ /* #ifndef APP-NVUE */
213
+ transition-property: transform, color;
214
+ transition-duration: 0.3s;
215
+ transition-timing-function: ease-in-out;
216
+ /* #endif */
217
+
218
+ &--first {
219
+ border-top-left-radius: 4px;
220
+ border-bottom-left-radius: 4px;
221
+ border-top-right-radius: 0px;
222
+ border-bottom-right-radius: 0px;
223
+ }
224
+
225
+ &--center {
226
+ border-top-left-radius: 0px;
227
+ border-bottom-left-radius: 0px;
228
+ border-top-right-radius: 0px;
229
+ border-bottom-right-radius: 0px;
230
+ }
231
+
232
+ &--last {
233
+ border-top-left-radius: 0px;
234
+ border-bottom-left-radius: 0px;
235
+ border-top-right-radius: 4px;
236
+ border-bottom-right-radius: 4px;
237
+ }
238
+ }
239
+
240
+ &__item {
241
+ @include flex;
242
+ flex: 1;
243
+ justify-content: center;
244
+ align-items: center;
245
+ // vue环境下,需要设置相对定位,因为滑块为绝对定位,item需要在滑块的上面
246
+ position: relative;
247
+
248
+ &--no-border-right {
249
+ border-right-width: 0 !important;
250
+ }
251
+
252
+ &--first {
253
+ border-top-left-radius: 4px;
254
+ border-bottom-left-radius: 4px;
255
+ }
256
+
257
+ &--last {
258
+ border-top-right-radius: 4px;
259
+ border-bottom-right-radius: 4px;
260
+ }
261
+
262
+ &__text {
263
+ font-size: 12px;
264
+ line-height: 14px;
265
+ @include flex;
266
+ align-items: center;
267
+ transition-property: color;
268
+ transition-duration: 0.3s;
269
+ }
270
+ }
271
+ }
272
+ </style>
@@ -0,0 +1,16 @@
1
+ import IProps from "./typing";
2
+ import { ColorConfig } from "../../config";
3
+
4
+ const defaultProps: IProps = {
5
+ list: [],
6
+ current: 0,
7
+ activeColor: ColorConfig.success,
8
+ inactiveColor: "#303133",
9
+ mode: "button",
10
+ fontSize: 12,
11
+ bold: true,
12
+ bgColor: "#eeeeef",
13
+ keyName: "name"
14
+ };
15
+
16
+ export default defaultProps;