muzhiyu-ui 1.0.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.
Files changed (96) hide show
  1. package/README.md +202 -0
  2. package/components/muzhiyu/mu-action-sheet/mu-action-sheet.vue +335 -0
  3. package/components/muzhiyu/mu-alert/mu-alert.vue +220 -0
  4. package/components/muzhiyu/mu-back-top/mu-back-top.vue +161 -0
  5. package/components/muzhiyu/mu-badge/mu-badge.vue +150 -0
  6. package/components/muzhiyu/mu-barcode/mu-barcode.vue +100 -0
  7. package/components/muzhiyu/mu-blank/mu-blank.vue +30 -0
  8. package/components/muzhiyu/mu-bottom-nav/mu-bottom-nav.vue +331 -0
  9. package/components/muzhiyu/mu-bubble/mu-bubble.vue +316 -0
  10. package/components/muzhiyu/mu-button/mu-button.vue +431 -0
  11. package/components/muzhiyu/mu-calendar/mu-calendar.vue +429 -0
  12. package/components/muzhiyu/mu-car-input/mu-car-input.vue +209 -0
  13. package/components/muzhiyu/mu-card/mu-card.vue +317 -0
  14. package/components/muzhiyu/mu-cascader/mu-cascader.vue +336 -0
  15. package/components/muzhiyu/mu-cell/mu-cell.vue +368 -0
  16. package/components/muzhiyu/mu-checkbox/mu-checkbox.vue +116 -0
  17. package/components/muzhiyu/mu-checkbox-group/mu-checkbox-group.vue +40 -0
  18. package/components/muzhiyu/mu-code-input/mu-code-input.vue +264 -0
  19. package/components/muzhiyu/mu-collapse/mu-collapse.vue +316 -0
  20. package/components/muzhiyu/mu-color-picker/mu-color-picker.vue +466 -0
  21. package/components/muzhiyu/mu-config/index.js +34 -0
  22. package/components/muzhiyu/mu-config/mu-config.vue +54 -0
  23. package/components/muzhiyu/mu-countdown/mu-countdown.vue +338 -0
  24. package/components/muzhiyu/mu-cropper/mu-cropper.vue +415 -0
  25. package/components/muzhiyu/mu-date-picker/mu-date-picker.vue +290 -0
  26. package/components/muzhiyu/mu-datetime/mu-datetime.vue +262 -0
  27. package/components/muzhiyu/mu-divider/mu-divider.vue +229 -0
  28. package/components/muzhiyu/mu-drawer/mu-drawer.vue +172 -0
  29. package/components/muzhiyu/mu-dropdown/mu-dropdown.vue +215 -0
  30. package/components/muzhiyu/mu-dropdown-top/mu-dropdown-top.vue +243 -0
  31. package/components/muzhiyu/mu-empty/mu-empty.vue +217 -0
  32. package/components/muzhiyu/mu-fab/mu-fab.vue +324 -0
  33. package/components/muzhiyu/mu-footer/mu-footer.vue +21 -0
  34. package/components/muzhiyu/mu-form/mu-form.vue +170 -0
  35. package/components/muzhiyu/mu-grid/mu-grid.vue +95 -0
  36. package/components/muzhiyu/mu-grid-item/mu-grid-item.vue +247 -0
  37. package/components/muzhiyu/mu-html/mu-html.vue +145 -0
  38. package/components/muzhiyu/mu-icon/mu-icon.vue +822 -0
  39. package/components/muzhiyu/mu-image-grid/mu-image-grid.vue +225 -0
  40. package/components/muzhiyu/mu-image-preview/mu-image-preview.vue +286 -0
  41. package/components/muzhiyu/mu-index-list/mu-index-list.vue +381 -0
  42. package/components/muzhiyu/mu-input/mu-input.vue +570 -0
  43. package/components/muzhiyu/mu-input-number/mu-input-number.vue +193 -0
  44. package/components/muzhiyu/mu-keyboard/mu-keyboard.vue +415 -0
  45. package/components/muzhiyu/mu-list/mu-list.vue +89 -0
  46. package/components/muzhiyu/mu-loading/mu-loading.vue +124 -0
  47. package/components/muzhiyu/mu-loading-page/mu-loading-page.vue +529 -0
  48. package/components/muzhiyu/mu-loadmore/mu-loadmore.vue +26 -0
  49. package/components/muzhiyu/mu-modal/mu-modal.vue +298 -0
  50. package/components/muzhiyu/mu-navbar/mu-navbar.vue +223 -0
  51. package/components/muzhiyu/mu-nomore/mu-nomore.vue +107 -0
  52. package/components/muzhiyu/mu-notice-bar/mu-notice-bar.vue +284 -0
  53. package/components/muzhiyu/mu-notify/mu-notify.vue +202 -0
  54. package/components/muzhiyu/mu-overlay/mu-overlay.vue +94 -0
  55. package/components/muzhiyu/mu-pagination/mu-pagination.vue +330 -0
  56. package/components/muzhiyu/mu-password-input/mu-password-input.vue +119 -0
  57. package/components/muzhiyu/mu-picker/mu-picker.vue +297 -0
  58. package/components/muzhiyu/mu-popup/mu-popup.vue +297 -0
  59. package/components/muzhiyu/mu-progress/mu-progress.vue +156 -0
  60. package/components/muzhiyu/mu-pull-refresh/mu-pull-refresh.vue +54 -0
  61. package/components/muzhiyu/mu-qrcode/mu-qrcode.vue +340 -0
  62. package/components/muzhiyu/mu-qrcode/qrcode.js +2237 -0
  63. package/components/muzhiyu/mu-radio/mu-radio.vue +125 -0
  64. package/components/muzhiyu/mu-radio-group/mu-radio-group.vue +37 -0
  65. package/components/muzhiyu/mu-rate/mu-rate.vue +103 -0
  66. package/components/muzhiyu/mu-search/mu-search.vue +320 -0
  67. package/components/muzhiyu/mu-section/mu-section.vue +206 -0
  68. package/components/muzhiyu/mu-select/mu-select.vue +440 -0
  69. package/components/muzhiyu/mu-share-sheet/mu-share-sheet.vue +269 -0
  70. package/components/muzhiyu/mu-sidebar/mu-sidebar.vue +304 -0
  71. package/components/muzhiyu/mu-signature/mu-signature.vue +449 -0
  72. package/components/muzhiyu/mu-skeleton/mu-skeleton.vue +225 -0
  73. package/components/muzhiyu/mu-slider/mu-slider.vue +228 -0
  74. package/components/muzhiyu/mu-space/mu-space.vue +84 -0
  75. package/components/muzhiyu/mu-steps/mu-steps.vue +311 -0
  76. package/components/muzhiyu/mu-sticky/mu-sticky.vue +57 -0
  77. package/components/muzhiyu/mu-swipe-cell/mu-swipe-cell.vue +281 -0
  78. package/components/muzhiyu/mu-swiper/mu-swiper.vue +107 -0
  79. package/components/muzhiyu/mu-switch/mu-switch.vue +99 -0
  80. package/components/muzhiyu/mu-tabbar/mu-tabbar.vue +382 -0
  81. package/components/muzhiyu/mu-table/mu-table.vue +420 -0
  82. package/components/muzhiyu/mu-tabs/mu-tabs.vue +339 -0
  83. package/components/muzhiyu/mu-tag/mu-tag.vue +65 -0
  84. package/components/muzhiyu/mu-text-ellipsis/mu-text-ellipsis.vue +54 -0
  85. package/components/muzhiyu/mu-timeline/mu-timeline.vue +166 -0
  86. package/components/muzhiyu/mu-tips/mu-tips.vue +36 -0
  87. package/components/muzhiyu/mu-toast/mu-toast.vue +151 -0
  88. package/components/muzhiyu/mu-transfer/mu-transfer.vue +114 -0
  89. package/components/muzhiyu/mu-tree/mu-tree.vue +263 -0
  90. package/components/muzhiyu/mu-upload/mu-upload.vue +415 -0
  91. package/components/muzhiyu/mu-waterfall/mu-waterfall.vue +321 -0
  92. package/components/muzhiyu/mu-watermark/mu-watermark.vue +60 -0
  93. package/index.js +83 -0
  94. package/package.json +38 -0
  95. package/utils/index.js +600 -0
  96. package/utils/request.js +265 -0
@@ -0,0 +1,338 @@
1
+ <template>
2
+ <view class="mu-countdown" :class="[`mu-countdown--${variant}`]">
3
+ <!-- 自定义插槽支持 -->
4
+ <slot :time="timeData">
5
+ <!-- 天数 -->
6
+ <view v-if="showDay && timeData.days > 0" class="mu-countdown__item">
7
+ <view class="mu-countdown__block" :style="blockCustomStyle">
8
+ <text class="mu-countdown__num" :style="numCustomStyle">{{ pad(timeData.days) }}</text>
9
+ </view>
10
+ <text class="mu-countdown__unit" :style="unitCustomStyle">{{ isTextUnit ? '天' : ':' }}</text>
11
+ </view>
12
+
13
+ <!-- 小时 -->
14
+ <view v-if="showHour" class="mu-countdown__item">
15
+ <view class="mu-countdown__block" :style="blockCustomStyle">
16
+ <text class="mu-countdown__num" :style="numCustomStyle">{{ pad(timeData.hours) }}</text>
17
+ </view>
18
+ <text class="mu-countdown__unit" :style="unitCustomStyle">{{ isTextUnit ? '时' : ':' }}</text>
19
+ </view>
20
+
21
+ <!-- 分钟 -->
22
+ <view v-if="showMinute" class="mu-countdown__item">
23
+ <view class="mu-countdown__block" :style="blockCustomStyle">
24
+ <text class="mu-countdown__num" :style="numCustomStyle">{{ pad(timeData.minutes) }}</text>
25
+ </view>
26
+ <text class="mu-countdown__unit" :style="unitCustomStyle">{{ isTextUnit ? '分' : ':' }}</text>
27
+ </view>
28
+
29
+ <!-- 秒数 -->
30
+ <view v-if="showSecond" class="mu-countdown__item">
31
+ <view class="mu-countdown__block" :style="blockCustomStyle">
32
+ <text class="mu-countdown__num" :style="numCustomStyle">{{ pad(timeData.seconds) }}</text>
33
+ </view>
34
+ <text v-if="isTextUnit" class="mu-countdown__unit" :style="unitCustomStyle">秒</text>
35
+ </view>
36
+
37
+ <!-- 毫秒数 (百/十毫秒高频平滑跑动) -->
38
+ <view v-if="millisecond" class="mu-countdown__item">
39
+ <text class="mu-countdown__unit" :style="unitCustomStyle">.</text>
40
+ <view class="mu-countdown__block mu-countdown__block--ms" :style="blockCustomStyle">
41
+ <text class="mu-countdown__num" :style="numCustomStyle">{{ padMs(timeData.milliseconds) }}</text>
42
+ </view>
43
+ </view>
44
+ </slot>
45
+ </view>
46
+ </template>
47
+
48
+ <script setup>
49
+ import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
50
+
51
+ const props = defineProps({
52
+ time: { type: [Number, String], default: 0 }, // 剩余毫秒数或秒数
53
+ endTime: { type: [Number, String], default: '' }, // 目标结束时间搓戳或时间串
54
+ variant: { type: String, default: 'badge' }, // badge (大促高彩方块) | simple (纯文字冒号) | round (圆角胶囊) | card (Bento 冰晶卡片)
55
+ autoStart: { type: Boolean, default: true },
56
+ showDay: { type: Boolean, default: true },
57
+ showHour: { type: Boolean, default: true },
58
+ showMinute: { type: Boolean, default: true },
59
+ showSecond: { type: Boolean, default: true },
60
+ unitType: { type: String, default: 'colon' }, // colon (冒号 :) | text (时分秒)
61
+ millisecond: { type: Boolean, default: false }, // 是否显示毫秒
62
+ color: { type: String, default: '' }, // 数字颜色
63
+ bgColor: { type: String, default: '' } // 数字块背景色
64
+ })
65
+
66
+ const emit = defineEmits(['finish', 'change'])
67
+
68
+ const remaining = ref(0)
69
+ let endTimeStamp = 0
70
+ let timer = null
71
+
72
+ const isTextUnit = computed(() => props.unitType === 'text')
73
+
74
+ const timeData = computed(() => {
75
+ const ms = remaining.value
76
+ const seconds = Math.floor(ms / 1000) % 60
77
+ const minutes = Math.floor(ms / 60000) % 60
78
+ const hours = Math.floor(ms / 3600000) % 24
79
+ const days = Math.floor(ms / 86400000)
80
+ const milliseconds = Math.floor((ms % 1000) / 10)
81
+ return { days, hours, minutes, seconds, milliseconds }
82
+ })
83
+
84
+ function pad(n) {
85
+ return String(n).padStart(2, '0')
86
+ }
87
+
88
+ function padMs(n) {
89
+ return String(n).padStart(2, '0')
90
+ }
91
+
92
+ function initRemaining() {
93
+ if (props.endTime) {
94
+ const end = new Date(props.endTime).getTime()
95
+ endTimeStamp = end
96
+ remaining.value = Math.max(0, end - Date.now())
97
+ } else {
98
+ const val = Number(props.time) || 0
99
+ const ms = val > 100000 ? val : val * 1000
100
+ endTimeStamp = Date.now() + ms
101
+ remaining.value = Math.max(0, ms)
102
+ }
103
+ }
104
+
105
+ function start() {
106
+ if (timer) return
107
+ const interval = props.millisecond ? 30 : 1000
108
+ timer = setInterval(() => {
109
+ // 动态校准真实剩余时间,防止页面离屏/后台休眠导致计时偏差
110
+ if (endTimeStamp > 0) {
111
+ remaining.value = Math.max(0, endTimeStamp - Date.now())
112
+ } else {
113
+ remaining.value = Math.max(0, remaining.value - interval)
114
+ }
115
+
116
+ emit('change', timeData.value)
117
+ if (remaining.value <= 0) {
118
+ pause()
119
+ emit('finish')
120
+ }
121
+ }, interval)
122
+ }
123
+
124
+ function pause() {
125
+ if (timer) {
126
+ clearInterval(timer)
127
+ timer = null
128
+ }
129
+ }
130
+
131
+ function reset() {
132
+ pause()
133
+ initRemaining()
134
+ if (props.autoStart) start()
135
+ }
136
+
137
+ const blockCustomStyle = computed(() => {
138
+ const s = {}
139
+ if (props.bgColor) {
140
+ s.background = props.bgColor
141
+ if (props.bgColor === 'transparent' || props.bgColor === 'none') {
142
+ s.boxShadow = 'none'
143
+ s.border = 'none'
144
+ }
145
+ }
146
+ return s
147
+ })
148
+
149
+ const numCustomStyle = computed(() => {
150
+ const s = {}
151
+ if (props.color) s.color = props.color
152
+ return s
153
+ })
154
+
155
+ const unitCustomStyle = computed(() => {
156
+ const s = {}
157
+ if (props.variant === 'simple' && props.color) s.color = props.color
158
+ return s
159
+ })
160
+
161
+ onMounted(() => {
162
+ initRemaining()
163
+ if (props.autoStart) start()
164
+ })
165
+
166
+ onUnmounted(() => pause())
167
+
168
+ watch(() => [props.time, props.endTime], () => reset())
169
+
170
+ defineExpose({ start, pause, reset })
171
+ </script>
172
+
173
+ <style lang="scss" scoped>
174
+ @import "@/uni.scss";
175
+
176
+ .mu-countdown {
177
+ display: inline-flex;
178
+ align-items: center;
179
+ box-sizing: border-box;
180
+
181
+ &__item {
182
+ display: inline-flex;
183
+ align-items: center;
184
+ }
185
+
186
+ &__num {
187
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
188
+ font-variant-numeric: tabular-nums;
189
+ line-height: 1;
190
+ }
191
+
192
+ /* 1. 数字高彩方块形态 (badge) */
193
+ &--badge {
194
+ .mu-countdown__block {
195
+ min-width: 48rpx;
196
+ height: 48rpx;
197
+ padding: 0 8rpx;
198
+ background: #F43F5E;
199
+ border-radius: 12rpx;
200
+ display: inline-flex;
201
+ align-items: center;
202
+ justify-content: center;
203
+ box-shadow: 0 4rpx 12rpx rgba(244, 63, 94, 0.25);
204
+ box-sizing: border-box;
205
+ }
206
+
207
+ .mu-countdown__num {
208
+ font-size: 26rpx;
209
+ font-weight: 800;
210
+ color: #ffffff;
211
+ }
212
+
213
+ .mu-countdown__unit {
214
+ font-size: 24rpx;
215
+ font-weight: 800;
216
+ color: #F43F5E;
217
+ margin: 0 8rpx;
218
+ line-height: 1;
219
+ }
220
+ }
221
+
222
+ /* 2. 纯文字冒号分隔形态 (simple) */
223
+ &--simple {
224
+ .mu-countdown__block {
225
+ background: transparent;
226
+ padding: 0;
227
+ }
228
+
229
+ .mu-countdown__num {
230
+ font-size: 32rpx;
231
+ font-weight: 800;
232
+ color: #0F172A;
233
+ }
234
+
235
+ .mu-countdown__unit {
236
+ font-size: 28rpx;
237
+ font-weight: 800;
238
+ color: #0F172A;
239
+ margin: 0 6rpx;
240
+ line-height: 1;
241
+ }
242
+ }
243
+
244
+ /* 3. 胶囊圆角形态 (round) */
245
+ &--round {
246
+ .mu-countdown__block {
247
+ min-width: 48rpx;
248
+ height: 48rpx;
249
+ padding: 0 10rpx;
250
+ background: #0F172A;
251
+ border-radius: 999rpx;
252
+ display: inline-flex;
253
+ align-items: center;
254
+ justify-content: center;
255
+ }
256
+
257
+ .mu-countdown__num {
258
+ font-size: 24rpx;
259
+ font-weight: 700;
260
+ color: #ffffff;
261
+ }
262
+
263
+ .mu-countdown__unit {
264
+ font-size: 24rpx;
265
+ font-weight: 700;
266
+ color: #0F172A;
267
+ margin: 0 8rpx;
268
+ line-height: 1;
269
+ }
270
+ }
271
+
272
+ /* 4. Bento 冰晶卡片形态 (card) */
273
+ &--card {
274
+ .mu-countdown__block {
275
+ min-width: 52rpx;
276
+ height: 52rpx;
277
+ padding: 0 10rpx;
278
+ background: #ffffff;
279
+ border-radius: 14rpx;
280
+ border: 1rpx solid rgba(226, 232, 240, 0.9);
281
+ box-shadow: 0 4rpx 16rpx rgba(15, 23, 42, 0.05);
282
+ display: inline-flex;
283
+ align-items: center;
284
+ justify-content: center;
285
+ }
286
+
287
+ .mu-countdown__num {
288
+ font-size: 28rpx;
289
+ font-weight: 800;
290
+ color: #171717;
291
+ }
292
+
293
+ .mu-countdown__unit {
294
+ font-size: 24rpx;
295
+ font-weight: 800;
296
+ color: #64748B;
297
+ margin: 0 8rpx;
298
+ line-height: 1;
299
+ }
300
+ }
301
+ }
302
+
303
+ .mu-dark, page.mu-dark {
304
+
305
+ .mu-countdown {
306
+ &--simple {
307
+ .mu-countdown__num, .mu-countdown__unit { color: $mu-dark-text-primary; }
308
+ }
309
+ &--round {
310
+ .mu-countdown__block { background: rgba(255, 255, 255, 0.15); }
311
+ .mu-countdown__unit { color: $mu-dark-text-primary; }
312
+ }
313
+ &--card {
314
+ .mu-countdown__block { background: $mu-dark-bg-base; border-color: rgba(255, 255, 255, 0.08); }
315
+ .mu-countdown__num { color: #FFFFFF; }
316
+ .mu-countdown__unit { color: $mu-dark-text-secondary; }
317
+ }
318
+ }
319
+ }
320
+
321
+ @media (prefers-color-scheme: dark) {
322
+
323
+ .mu-countdown {
324
+ &--simple {
325
+ .mu-countdown__num, .mu-countdown__unit { color: $mu-dark-text-primary; }
326
+ }
327
+ &--round {
328
+ .mu-countdown__block { background: rgba(255, 255, 255, 0.15); }
329
+ .mu-countdown__unit { color: $mu-dark-text-primary; }
330
+ }
331
+ &--card {
332
+ .mu-countdown__block { background: $mu-dark-bg-base; border-color: rgba(255, 255, 255, 0.08); }
333
+ .mu-countdown__num { color: #FFFFFF; }
334
+ .mu-countdown__unit { color: $mu-dark-text-secondary; }
335
+ }
336
+ }
337
+ }
338
+ </style>