uview-pro 0.0.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.
- package/changelog.md +6 -0
- package/components/u-action-sheet/u-action-sheet.vue +205 -0
- package/components/u-alert-tips/u-alert-tips.vue +241 -0
- package/components/u-avatar/u-avatar.vue +220 -0
- package/components/u-avatar-cropper/u-avatar-cropper.vue +329 -0
- package/components/u-avatar-cropper/weCropper.d.ts +54 -0
- package/components/u-avatar-cropper/weCropper.js +1267 -0
- package/components/u-avatar-cropper/weCropper.ts +1254 -0
- package/components/u-back-top/u-back-top.vue +156 -0
- package/components/u-badge/u-badge.vue +189 -0
- package/components/u-button/u-button.vue +562 -0
- package/components/u-calendar/u-calendar.vue +725 -0
- package/components/u-car-keyboard/u-car-keyboard.vue +236 -0
- package/components/u-card/u-card.vue +240 -0
- package/components/u-cell-group/u-cell-group.vue +56 -0
- package/components/u-cell-item/u-cell-item.vue +245 -0
- package/components/u-checkbox/u-checkbox.vue +310 -0
- package/components/u-checkbox-group/u-checkbox-group.vue +134 -0
- package/components/u-circle-progress/u-circle-progress.vue +210 -0
- package/components/u-col/u-col.vue +135 -0
- package/components/u-collapse/u-collapse.vue +82 -0
- package/components/u-collapse-item/u-collapse-item.vue +190 -0
- package/components/u-column-notice/u-column-notice.vue +264 -0
- package/components/u-count-down/u-count-down.vue +333 -0
- package/components/u-count-to/u-count-to.vue +297 -0
- package/components/u-divider/u-divider.vue +141 -0
- package/components/u-dropdown/u-dropdown.vue +311 -0
- package/components/u-dropdown-item/u-dropdown-item.vue +135 -0
- package/components/u-empty/u-empty.vue +111 -0
- package/components/u-field/u-field.vue +469 -0
- package/components/u-form/u-form.vue +162 -0
- package/components/u-form-item/u-form-item.vue +476 -0
- package/components/u-full-screen/u-full-screen.vue +80 -0
- package/components/u-gap/u-gap.vue +48 -0
- package/components/u-grid/u-grid.vue +101 -0
- package/components/u-grid-item/u-grid-item.vue +136 -0
- package/components/u-icon/u-icon.vue +389 -0
- package/components/u-image/types.ts +48 -0
- package/components/u-image/u-image.vue +218 -0
- package/components/u-index-anchor/u-index-anchor.vue +101 -0
- package/components/u-index-list/u-index-list.vue +376 -0
- package/components/u-input/u-input.vue +462 -0
- package/components/u-keyboard/u-keyboard.vue +188 -0
- package/components/u-lazy-load/u-lazy-load.vue +288 -0
- package/components/u-line/u-line.vue +71 -0
- package/components/u-line-progress/u-line-progress.vue +128 -0
- package/components/u-link/u-link.vue +87 -0
- package/components/u-loading/u-loading.vue +111 -0
- package/components/u-loadmore/u-loadmore.vue +205 -0
- package/components/u-mask/u-mask.vue +137 -0
- package/components/u-message-input/u-message-input.vue +315 -0
- package/components/u-modal/u-modal.vue +284 -0
- package/components/u-navbar/u-navbar.vue +314 -0
- package/components/u-no-network/image.ts +2 -0
- package/components/u-no-network/u-no-network.vue +311 -0
- package/components/u-notice-bar/u-notice-bar.vue +274 -0
- package/components/u-number-box/u-number-box.vue +344 -0
- package/components/u-number-keyboard/u-number-keyboard.vue +170 -0
- package/components/u-parse/libs/CssHandler.js +100 -0
- package/components/u-parse/libs/MpHtmlParser.js +580 -0
- package/components/u-parse/libs/config.js +80 -0
- package/components/u-parse/libs/handler.wxs +22 -0
- package/components/u-parse/libs/trees.vue +505 -0
- package/components/u-parse/u-parse.vue +645 -0
- package/components/u-picker/u-picker.vue +808 -0
- package/components/u-popup/u-popup.vue +404 -0
- package/components/u-radio/u-radio.vue +272 -0
- package/components/u-radio-group/u-radio-group.vue +116 -0
- package/components/u-rate/u-rate.vue +349 -0
- package/components/u-read-more/u-read-more.vue +199 -0
- package/components/u-row/u-row.vue +95 -0
- package/components/u-row-notice/u-row-notice.vue +273 -0
- package/components/u-search/u-search.vue +298 -0
- package/components/u-section/u-section.vue +175 -0
- package/components/u-select/u-select.vue +387 -0
- package/components/u-skeleton/u-skeleton.vue +230 -0
- package/components/u-slider/u-slider.vue +293 -0
- package/components/u-steps/u-steps.vue +200 -0
- package/components/u-sticky/u-sticky.vue +189 -0
- package/components/u-subsection/u-subsection.vue +388 -0
- package/components/u-swipe-action/u-swipe-action.vue +289 -0
- package/components/u-swiper/u-swiper.vue +305 -0
- package/components/u-switch/u-switch.vue +146 -0
- package/components/u-tabbar/u-tabbar.vue +347 -0
- package/components/u-table/u-table.vue +104 -0
- package/components/u-tabs/u-tabs.vue +322 -0
- package/components/u-tabs-swiper/u-tabs-swiper.vue +426 -0
- package/components/u-tag/u-tag.vue +270 -0
- package/components/u-td/u-td.vue +76 -0
- package/components/u-th/u-th.vue +70 -0
- package/components/u-time-line/u-time-line.vue +39 -0
- package/components/u-time-line-item/u-time-line-item.vue +88 -0
- package/components/u-toast/types.ts +4 -0
- package/components/u-toast/u-toast.vue +238 -0
- package/components/u-top-tips/u-top-tips.vue +118 -0
- package/components/u-tr/u-tr.vue +24 -0
- package/components/u-upload/u-upload.vue +600 -0
- package/components/u-verification-code/u-verification-code.vue +194 -0
- package/components/u-waterfall/u-waterfall.vue +186 -0
- package/iconfont.css +910 -0
- package/index.scss +23 -0
- package/index.ts +166 -0
- package/libs/config/config.ts +26 -0
- package/libs/config/zIndex.ts +37 -0
- package/libs/css/color.scss +155 -0
- package/libs/css/common.scss +176 -0
- package/libs/css/style.components.scss +7 -0
- package/libs/css/style.h5.scss +8 -0
- package/libs/css/style.mp.scss +72 -0
- package/libs/css/style.nvue.scss +3 -0
- package/libs/css/style.vue.scss +175 -0
- package/libs/function/$parent.ts +22 -0
- package/libs/function/addUnit.ts +13 -0
- package/libs/function/color.ts +37 -0
- package/libs/function/colorGradient.ts +123 -0
- package/libs/function/debounce.ts +28 -0
- package/libs/function/deepClone.ts +39 -0
- package/libs/function/deepMerge.ts +34 -0
- package/libs/function/getParent.ts +59 -0
- package/libs/function/getRect.ts +26 -0
- package/libs/function/guid.ts +42 -0
- package/libs/function/md5.ts +397 -0
- package/libs/function/parent.ts +21 -0
- package/libs/function/queryParams.ts +60 -0
- package/libs/function/random.ts +16 -0
- package/libs/function/randomArray.ts +11 -0
- package/libs/function/route.ts +118 -0
- package/libs/function/sys.ts +15 -0
- package/libs/function/test.ts +229 -0
- package/libs/function/throttle.ts +31 -0
- package/libs/function/timeFormat.ts +54 -0
- package/libs/function/timeFrom.ts +48 -0
- package/libs/function/toast.ts +14 -0
- package/libs/function/trim.ts +21 -0
- package/libs/function/type2icon.ts +36 -0
- package/libs/hooks/useEmitter.ts +77 -0
- package/libs/hooks/useParent.ts +29 -0
- package/libs/request/index.ts +237 -0
- package/libs/store/index.ts +88 -0
- package/libs/util/area.ts +1 -0
- package/libs/util/async-validator.js +1356 -0
- package/libs/util/city.ts +1 -0
- package/libs/util/emitter.ts +112 -0
- package/libs/util/mitt.ts +118 -0
- package/libs/util/parent.ts +20 -0
- package/libs/util/province.ts +1 -0
- package/package.json +98 -0
- package/readme.md +165 -0
- package/theme.scss +38 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="u-notice-bar" :style="{ background: computeBgColor, padding: props.padding }" :class="[props.type ? `u-type-${props.type}-light-bg` : '']">
|
|
3
|
+
<view class="u-icon-wrap">
|
|
4
|
+
<u-icon class="u-left-icon" v-if="props.volumeIcon" name="volume-fill" :size="props.volumeSize" :color="computeColor"></u-icon>
|
|
5
|
+
</view>
|
|
6
|
+
<swiper
|
|
7
|
+
:disable-touch="props.disableTouch"
|
|
8
|
+
@change="change"
|
|
9
|
+
:autoplay="props.autoplay && props.playState === 'play'"
|
|
10
|
+
:vertical="vertical"
|
|
11
|
+
circular
|
|
12
|
+
:interval="props.duration"
|
|
13
|
+
class="u-swiper"
|
|
14
|
+
>
|
|
15
|
+
<swiper-item v-for="(item, index) in props.list" :key="index" class="u-swiper-item">
|
|
16
|
+
<view class="u-news-item u-line-1" :style="textStyle" @tap="click(index)" :class="['u-type-' + props.type]">
|
|
17
|
+
{{ item }}
|
|
18
|
+
</view>
|
|
19
|
+
</swiper-item>
|
|
20
|
+
</swiper>
|
|
21
|
+
<view class="u-icon-wrap">
|
|
22
|
+
<u-icon @click="getMore" class="u-right-icon" v-if="props.moreIcon" name="arrow-right" :size="26" :color="computeColor"></u-icon>
|
|
23
|
+
<u-icon @click="close" class="u-right-icon" v-if="props.closeIcon" name="close" :size="24" :color="computeColor"></u-icon>
|
|
24
|
+
</view>
|
|
25
|
+
</view>
|
|
26
|
+
</template>
|
|
27
|
+
|
|
28
|
+
<script setup lang="ts">
|
|
29
|
+
import { computed } from 'vue';
|
|
30
|
+
|
|
31
|
+
defineOptions({ name: 'u-column-notice' });
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* u-column-notice 通告栏
|
|
35
|
+
* @property {Array} list 显示的内容,数组
|
|
36
|
+
* @property {String} type 显示的主题,success|error|primary|info|warning
|
|
37
|
+
* @property {Boolean} volumeIcon 是否显示左侧的音量图标
|
|
38
|
+
* @property {Boolean} moreIcon 是否显示右侧的右箭头图标
|
|
39
|
+
* @property {Boolean} closeIcon 是否显示右侧的关闭图标
|
|
40
|
+
* @property {Boolean} autoplay 是否自动播放
|
|
41
|
+
* @property {String} color 文字颜色,各图标也会使用文字颜色
|
|
42
|
+
* @property {String} bgColor 背景颜色
|
|
43
|
+
* @property {String} direction 滚动方向,row-水平滚动,column-垂直滚动
|
|
44
|
+
* @property {Boolean} show 是否显示
|
|
45
|
+
* @property {String|Number} fontSize 字体大小,单位rpx
|
|
46
|
+
* @property {String|Number} duration 滚动一个周期的时间长,单位ms
|
|
47
|
+
* @property {String|Number} volumeSize 音量喇叭的大小
|
|
48
|
+
* @property {Number} speed 水平滚动时的滚动速度,即每秒滚动多少rpx
|
|
49
|
+
* @property {Boolean} isCircular 水平滚动时,是否采用衔接形式滚动
|
|
50
|
+
* @property {String} mode 滚动方向,horizontal-水平滚动,vertical-垂直滚动
|
|
51
|
+
* @property {String} playState 播放状态,play-播放,paused-暂停
|
|
52
|
+
* @property {Boolean} disableTouch 是否禁止用手滑动切换
|
|
53
|
+
* @property {String|Number} padding 通知的边距
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
const props = defineProps({
|
|
57
|
+
/** 显示的内容,数组 */
|
|
58
|
+
list: {
|
|
59
|
+
type: Array as () => string[],
|
|
60
|
+
default: () => []
|
|
61
|
+
},
|
|
62
|
+
/** 显示的主题,success|error|primary|info|warning */
|
|
63
|
+
type: {
|
|
64
|
+
type: String,
|
|
65
|
+
default: 'warning'
|
|
66
|
+
},
|
|
67
|
+
/** 是否显示左侧的音量图标 */
|
|
68
|
+
volumeIcon: {
|
|
69
|
+
type: Boolean,
|
|
70
|
+
default: true
|
|
71
|
+
},
|
|
72
|
+
/** 是否显示右侧的右箭头图标 */
|
|
73
|
+
moreIcon: {
|
|
74
|
+
type: Boolean,
|
|
75
|
+
default: false
|
|
76
|
+
},
|
|
77
|
+
/** 是否显示右侧的关闭图标 */
|
|
78
|
+
closeIcon: {
|
|
79
|
+
type: Boolean,
|
|
80
|
+
default: false
|
|
81
|
+
},
|
|
82
|
+
/** 是否自动播放 */
|
|
83
|
+
autoplay: {
|
|
84
|
+
type: Boolean,
|
|
85
|
+
default: true
|
|
86
|
+
},
|
|
87
|
+
/** 文字颜色,各图标也会使用文字颜色 */
|
|
88
|
+
color: {
|
|
89
|
+
type: String,
|
|
90
|
+
default: ''
|
|
91
|
+
},
|
|
92
|
+
/** 背景颜色 */
|
|
93
|
+
bgColor: {
|
|
94
|
+
type: String,
|
|
95
|
+
default: ''
|
|
96
|
+
},
|
|
97
|
+
/** 滚动方向,row-水平滚动,column-垂直滚动 */
|
|
98
|
+
direction: {
|
|
99
|
+
type: String,
|
|
100
|
+
default: 'row'
|
|
101
|
+
},
|
|
102
|
+
/** 是否显示 */
|
|
103
|
+
show: {
|
|
104
|
+
type: Boolean,
|
|
105
|
+
default: true
|
|
106
|
+
},
|
|
107
|
+
/** 字体大小,单位rpx */
|
|
108
|
+
fontSize: {
|
|
109
|
+
type: [Number, String],
|
|
110
|
+
default: 26
|
|
111
|
+
},
|
|
112
|
+
/** 滚动一个周期的时间长,单位ms */
|
|
113
|
+
duration: {
|
|
114
|
+
type: [Number, String],
|
|
115
|
+
default: 2000
|
|
116
|
+
},
|
|
117
|
+
/** 音量喇叭的大小 */
|
|
118
|
+
volumeSize: {
|
|
119
|
+
type: [Number, String],
|
|
120
|
+
default: 34
|
|
121
|
+
},
|
|
122
|
+
/** 水平滚动时的滚动速度,即每秒滚动多少rpx,这有利于控制文字无论多少时,都能有一个恒定的速度 */
|
|
123
|
+
speed: {
|
|
124
|
+
type: Number,
|
|
125
|
+
default: 160
|
|
126
|
+
},
|
|
127
|
+
/** 水平滚动时,是否采用衔接形式滚动 */
|
|
128
|
+
isCircular: {
|
|
129
|
+
type: Boolean,
|
|
130
|
+
default: true
|
|
131
|
+
},
|
|
132
|
+
/** 滚动方向,horizontal-水平滚动,vertical-垂直滚动 */
|
|
133
|
+
mode: {
|
|
134
|
+
type: String,
|
|
135
|
+
default: 'horizontal'
|
|
136
|
+
},
|
|
137
|
+
/** 播放状态,play-播放,paused-暂停 */
|
|
138
|
+
playState: {
|
|
139
|
+
type: String,
|
|
140
|
+
default: 'play'
|
|
141
|
+
},
|
|
142
|
+
/** 是否禁止用手滑动切换 */
|
|
143
|
+
disableTouch: {
|
|
144
|
+
type: Boolean,
|
|
145
|
+
default: true
|
|
146
|
+
},
|
|
147
|
+
/** 通知的边距 */
|
|
148
|
+
padding: {
|
|
149
|
+
type: [Number, String],
|
|
150
|
+
default: '18rpx 24rpx'
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const emit = defineEmits<{ (e: 'click', index: number): void; (e: 'close'): void; (e: 'getMore'): void; (e: 'end'): void }>();
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* 计算字体颜色,如果没有自定义的,就用uview主题颜色
|
|
158
|
+
*/
|
|
159
|
+
const computeColor = computed(() => {
|
|
160
|
+
if (props.color) return props.color;
|
|
161
|
+
// 如果是无主题,就默认使用content-color
|
|
162
|
+
else if (props.type === 'none') return '#606266';
|
|
163
|
+
else return props.type;
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 文字内容的样式
|
|
168
|
+
*/
|
|
169
|
+
const textStyle = computed(() => {
|
|
170
|
+
const style: Record<string, any> = {};
|
|
171
|
+
if (props.color) style.color = props.color;
|
|
172
|
+
else if (props.type === 'none') style.color = '#606266';
|
|
173
|
+
style.fontSize = props.fontSize + 'rpx';
|
|
174
|
+
return style;
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* 垂直或者水平滚动
|
|
179
|
+
*/
|
|
180
|
+
const vertical = computed(() => {
|
|
181
|
+
return props.mode !== 'horizontal';
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 计算背景颜色
|
|
186
|
+
*/
|
|
187
|
+
const computeBgColor = computed(() => {
|
|
188
|
+
if (props.bgColor) return props.bgColor;
|
|
189
|
+
else if (props.type === 'none') return 'transparent';
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* 点击通告栏
|
|
194
|
+
*/
|
|
195
|
+
function click(index: number) {
|
|
196
|
+
emit('click', index);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* 点击关闭按钮
|
|
201
|
+
*/
|
|
202
|
+
function close() {
|
|
203
|
+
emit('close');
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 点击更多箭头按钮
|
|
208
|
+
*/
|
|
209
|
+
function getMore() {
|
|
210
|
+
emit('getMore');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* swiper 切换事件
|
|
215
|
+
*/
|
|
216
|
+
function change(e: { detail: { current: number } }) {
|
|
217
|
+
const index = e.detail.current;
|
|
218
|
+
if (index === props.list.length - 1) {
|
|
219
|
+
emit('end');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
</script>
|
|
223
|
+
|
|
224
|
+
<style lang="scss" scoped>
|
|
225
|
+
@import '../../libs/css/style.components.scss';
|
|
226
|
+
.u-notice-bar {
|
|
227
|
+
width: 100%;
|
|
228
|
+
@include vue-flex;
|
|
229
|
+
align-items: center;
|
|
230
|
+
justify-content: center;
|
|
231
|
+
flex-wrap: nowrap;
|
|
232
|
+
padding: 18rpx 24rpx;
|
|
233
|
+
overflow: hidden;
|
|
234
|
+
}
|
|
235
|
+
.u-swiper {
|
|
236
|
+
font-size: 26rpx;
|
|
237
|
+
height: 32rpx;
|
|
238
|
+
@include vue-flex;
|
|
239
|
+
align-items: center;
|
|
240
|
+
flex: 1;
|
|
241
|
+
margin-left: 12rpx;
|
|
242
|
+
}
|
|
243
|
+
.u-swiper-item {
|
|
244
|
+
@include vue-flex;
|
|
245
|
+
align-items: center;
|
|
246
|
+
overflow: hidden;
|
|
247
|
+
}
|
|
248
|
+
.u-news-item {
|
|
249
|
+
overflow: hidden;
|
|
250
|
+
}
|
|
251
|
+
.u-right-icon {
|
|
252
|
+
margin-left: 12rpx;
|
|
253
|
+
/* #ifndef APP-NVUE */
|
|
254
|
+
display: inline-flex;
|
|
255
|
+
/* #endif */
|
|
256
|
+
align-items: center;
|
|
257
|
+
}
|
|
258
|
+
.u-left-icon {
|
|
259
|
+
/* #ifndef APP-NVUE */
|
|
260
|
+
display: inline-flex;
|
|
261
|
+
/* #endif */
|
|
262
|
+
align-items: center;
|
|
263
|
+
}
|
|
264
|
+
</style>
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="u-countdown">
|
|
3
|
+
<view class="u-countdown-item" :style="[itemStyle]" v-if="props.showDays && (props.hideZeroDay || (!props.hideZeroDay && d != '00'))">
|
|
4
|
+
<view class="u-countdown-time" :style="[letterStyle]">
|
|
5
|
+
{{ d }}
|
|
6
|
+
</view>
|
|
7
|
+
</view>
|
|
8
|
+
<view
|
|
9
|
+
class="u-countdown-colon"
|
|
10
|
+
:style="{ fontSize: props.separatorSize + 'rpx', color: props.separatorColor, paddingBottom: props.separator == 'colon' ? '4rpx' : 0 }"
|
|
11
|
+
v-if="props.showDays && (props.hideZeroDay || (!props.hideZeroDay && d != '00'))"
|
|
12
|
+
>
|
|
13
|
+
{{ props.separator == 'colon' ? ':' : '天' }}
|
|
14
|
+
</view>
|
|
15
|
+
<view class="u-countdown-item" :style="[itemStyle]" v-if="props.showHours">
|
|
16
|
+
<view class="u-countdown-time" :style="{ fontSize: props.fontSize + 'rpx', color: props.color }">
|
|
17
|
+
{{ h }}
|
|
18
|
+
</view>
|
|
19
|
+
</view>
|
|
20
|
+
<view
|
|
21
|
+
class="u-countdown-colon"
|
|
22
|
+
:style="{ fontSize: props.separatorSize + 'rpx', color: props.separatorColor, paddingBottom: props.separator == 'colon' ? '4rpx' : 0 }"
|
|
23
|
+
v-if="props.showHours"
|
|
24
|
+
>
|
|
25
|
+
{{ props.separator == 'colon' ? ':' : '时' }}
|
|
26
|
+
</view>
|
|
27
|
+
<view class="u-countdown-item" :style="[itemStyle]" v-if="props.showMinutes">
|
|
28
|
+
<view class="u-countdown-time" :style="{ fontSize: props.fontSize + 'rpx', color: props.color }">
|
|
29
|
+
{{ i }}
|
|
30
|
+
</view>
|
|
31
|
+
</view>
|
|
32
|
+
<view
|
|
33
|
+
class="u-countdown-colon"
|
|
34
|
+
:style="{ fontSize: props.separatorSize + 'rpx', color: props.separatorColor, paddingBottom: props.separator == 'colon' ? '4rpx' : 0 }"
|
|
35
|
+
v-if="props.showMinutes"
|
|
36
|
+
>
|
|
37
|
+
{{ props.separator == 'colon' ? ':' : '分' }}
|
|
38
|
+
</view>
|
|
39
|
+
<view class="u-countdown-item" :style="[itemStyle]" v-if="props.showSeconds">
|
|
40
|
+
<view class="u-countdown-time" :style="{ fontSize: props.fontSize + 'rpx', color: props.color }">
|
|
41
|
+
{{ s }}
|
|
42
|
+
</view>
|
|
43
|
+
</view>
|
|
44
|
+
<view
|
|
45
|
+
class="u-countdown-colon"
|
|
46
|
+
:style="{ fontSize: props.separatorSize + 'rpx', color: props.separatorColor, paddingBottom: 0 }"
|
|
47
|
+
v-if="props.showSeconds && props.separator == 'zh'"
|
|
48
|
+
>
|
|
49
|
+
秒
|
|
50
|
+
</view>
|
|
51
|
+
</view>
|
|
52
|
+
</template>
|
|
53
|
+
|
|
54
|
+
<script setup lang="ts">
|
|
55
|
+
import { ref, computed, watch, onMounted } from 'vue';
|
|
56
|
+
|
|
57
|
+
defineOptions({ name: 'u-count-down' });
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* countDown 倒计时
|
|
61
|
+
* @description 该组件一般使用于某个活动的截止时间上,通过数字的变化,给用户明确的时间感受,提示用户进行某一个行为操作。
|
|
62
|
+
* @tutorial https://www.uviewui.com/components/countDown.html
|
|
63
|
+
* @property {String | Number} timestamp 倒计时,单位为秒
|
|
64
|
+
* @property {Boolean} autoplay 是否自动开始倒计时,如果为false,需手动调用开始方法。见官网说明(默认true)
|
|
65
|
+
* @property {String} separator 分隔符,colon为英文冒号,zh为中文(默认colon)
|
|
66
|
+
* @property {String | Number} separator-size 分隔符的字体大小,单位rpx(默认30)
|
|
67
|
+
* @property {String} separator-color 分隔符的颜色(默认#303133)
|
|
68
|
+
* @property {String | Number} font-size 倒计时字体大小,单位rpx(默认30)
|
|
69
|
+
* @property {Boolean} show-border 是否显示倒计时数字的边框(默认false)
|
|
70
|
+
* @property {Boolean} hide-zero-day 当"天"的部分为0时,隐藏该字段 (默认true)
|
|
71
|
+
* @property {String} border-color 数字边框的颜色(默认#303133)
|
|
72
|
+
* @property {String} bg-color 倒计时数字的背景颜色(默认#ffffff)
|
|
73
|
+
* @property {String} color 倒计时数字的颜色(默认#303133)
|
|
74
|
+
* @property {String | Number} height 数字高度值(宽度等同此值),设置边框时看情况是否需要设置此值,单位rpx(默认auto)
|
|
75
|
+
* @property {Boolean} show-days 是否显示倒计时的"天"部分(默认true)
|
|
76
|
+
* @property {Boolean} show-hours 是否显示倒计时的"时"部分(默认true)
|
|
77
|
+
* @property {Boolean} show-minutes 是否显示倒计时的"分"部分(默认true)
|
|
78
|
+
* @property {Boolean} show-seconds 是否显示倒计时的"秒"部分(默认true)
|
|
79
|
+
* @event {Function} end 倒计时结束
|
|
80
|
+
* @event {Function} change 每秒触发一次,回调为当前剩余的倒计秒数
|
|
81
|
+
* @example <u-count-down ref="uCountDown" :timestamp="86400" :autoplay="false"></u-count-down>
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
const emit = defineEmits(['end', 'change']);
|
|
85
|
+
|
|
86
|
+
const props = defineProps({
|
|
87
|
+
/** 倒计时的时间,秒为单位 */
|
|
88
|
+
timestamp: {
|
|
89
|
+
type: [Number, String],
|
|
90
|
+
default: 0
|
|
91
|
+
},
|
|
92
|
+
/** 是否自动开始倒计时 */
|
|
93
|
+
autoplay: {
|
|
94
|
+
type: Boolean,
|
|
95
|
+
default: true
|
|
96
|
+
},
|
|
97
|
+
/** 分隔符 */
|
|
98
|
+
separator: {
|
|
99
|
+
type: String,
|
|
100
|
+
default: 'colon'
|
|
101
|
+
},
|
|
102
|
+
/** 分隔符的大小,单位rpx */
|
|
103
|
+
separatorSize: {
|
|
104
|
+
type: [Number, String],
|
|
105
|
+
default: 30
|
|
106
|
+
},
|
|
107
|
+
/** 分隔符颜色 */
|
|
108
|
+
separatorColor: {
|
|
109
|
+
type: String,
|
|
110
|
+
default: '#303133'
|
|
111
|
+
},
|
|
112
|
+
/** 字体颜色 */
|
|
113
|
+
color: {
|
|
114
|
+
type: String,
|
|
115
|
+
default: '#303133'
|
|
116
|
+
},
|
|
117
|
+
/** 字体大小,单位rpx */
|
|
118
|
+
fontSize: {
|
|
119
|
+
type: [Number, String],
|
|
120
|
+
default: 30
|
|
121
|
+
},
|
|
122
|
+
/** 背景颜色 */
|
|
123
|
+
bgColor: {
|
|
124
|
+
type: String,
|
|
125
|
+
default: '#fff'
|
|
126
|
+
},
|
|
127
|
+
/** 数字框高度,单位rpx */
|
|
128
|
+
height: {
|
|
129
|
+
type: [Number, String],
|
|
130
|
+
default: 'auto'
|
|
131
|
+
},
|
|
132
|
+
/** 是否显示数字框 */
|
|
133
|
+
showBorder: {
|
|
134
|
+
type: Boolean,
|
|
135
|
+
default: false
|
|
136
|
+
},
|
|
137
|
+
/** 边框颜色 */
|
|
138
|
+
borderColor: {
|
|
139
|
+
type: String,
|
|
140
|
+
default: '#303133'
|
|
141
|
+
},
|
|
142
|
+
/** 是否显示秒 */
|
|
143
|
+
showSeconds: {
|
|
144
|
+
type: Boolean,
|
|
145
|
+
default: true
|
|
146
|
+
},
|
|
147
|
+
/** 是否显示分钟 */
|
|
148
|
+
showMinutes: {
|
|
149
|
+
type: Boolean,
|
|
150
|
+
default: true
|
|
151
|
+
},
|
|
152
|
+
/** 是否显示小时 */
|
|
153
|
+
showHours: {
|
|
154
|
+
type: Boolean,
|
|
155
|
+
default: true
|
|
156
|
+
},
|
|
157
|
+
/** 是否显示“天” */
|
|
158
|
+
showDays: {
|
|
159
|
+
type: Boolean,
|
|
160
|
+
default: true
|
|
161
|
+
},
|
|
162
|
+
/** 当"天"的部分为0时,不显示 */
|
|
163
|
+
hideZeroDay: {
|
|
164
|
+
type: Boolean,
|
|
165
|
+
default: false
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const d = ref('00'); // 天
|
|
170
|
+
const h = ref('00'); // 小时
|
|
171
|
+
const i = ref('00'); // 分钟
|
|
172
|
+
const s = ref('00'); // 秒
|
|
173
|
+
const timer = ref<number | null>(null); // 定时器类型修正
|
|
174
|
+
const seconds = ref(0);
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* 倒计时item的样式,item为分别的时分秒部分的数字
|
|
178
|
+
*/
|
|
179
|
+
const itemStyle = computed(() => {
|
|
180
|
+
const style: Record<string, string> = {};
|
|
181
|
+
if (props.height) {
|
|
182
|
+
style.height = props.height + 'rpx';
|
|
183
|
+
style.width = props.height + 'rpx';
|
|
184
|
+
}
|
|
185
|
+
if (props.showBorder) {
|
|
186
|
+
style.borderStyle = 'solid';
|
|
187
|
+
style.borderColor = props.borderColor;
|
|
188
|
+
style.borderWidth = '1px';
|
|
189
|
+
}
|
|
190
|
+
if (props.bgColor) {
|
|
191
|
+
style.backgroundColor = props.bgColor;
|
|
192
|
+
}
|
|
193
|
+
return style;
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 倒计时数字的样式
|
|
198
|
+
*/
|
|
199
|
+
const letterStyle = computed(() => {
|
|
200
|
+
const style: Record<string, string> = {};
|
|
201
|
+
if (props.fontSize) style.fontSize = props.fontSize + 'rpx';
|
|
202
|
+
if (props.color) style.color = props.color;
|
|
203
|
+
return style;
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// 监听时间戳的变化
|
|
207
|
+
watch(
|
|
208
|
+
() => props.timestamp,
|
|
209
|
+
(newVal, oldVal) => {
|
|
210
|
+
// 如果倒计时间发生变化,清除定时器,重新开始倒计时
|
|
211
|
+
clearTimer();
|
|
212
|
+
start();
|
|
213
|
+
}
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
onMounted(() => {
|
|
217
|
+
// 如果自动倒计时
|
|
218
|
+
if (props.autoplay && props.timestamp) {
|
|
219
|
+
start();
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* 倒计时
|
|
225
|
+
*/
|
|
226
|
+
function start() {
|
|
227
|
+
// 避免可能出现的倒计时重叠情况
|
|
228
|
+
clearTimer();
|
|
229
|
+
if (Number(props.timestamp) <= 0) return;
|
|
230
|
+
seconds.value = Number(props.timestamp);
|
|
231
|
+
formatTime(seconds.value);
|
|
232
|
+
timer.value = setInterval(() => {
|
|
233
|
+
seconds.value--;
|
|
234
|
+
// 发出change事件
|
|
235
|
+
emit('change', seconds.value);
|
|
236
|
+
if (seconds.value < 0) {
|
|
237
|
+
end();
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
formatTime(seconds.value);
|
|
241
|
+
}, 1000);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* 格式化时间
|
|
246
|
+
*/
|
|
247
|
+
function formatTime(sec: number) {
|
|
248
|
+
// 小于等于0的话,结束倒计时
|
|
249
|
+
if (sec <= 0) end();
|
|
250
|
+
let dayNum = Math.floor(sec / (60 * 60 * 24));
|
|
251
|
+
let hourNum = Math.floor(sec / (60 * 60)) - dayNum * 24;
|
|
252
|
+
// showHour为需要显示的小时
|
|
253
|
+
let showHour: string;
|
|
254
|
+
// 判断是否显示“天”参数,如果不显示,将天部分的值,加入到小时中
|
|
255
|
+
// hour为给后面计算秒和分等用的(基于显示天的前提下计算)
|
|
256
|
+
if (props.showDays) {
|
|
257
|
+
showHour = hourNum < 10 ? '0' + hourNum : String(hourNum);
|
|
258
|
+
} else {
|
|
259
|
+
// 如果不显示天数,将“天”部分的时间折算到小时中去
|
|
260
|
+
// 如果小于10,在前面补上一个"0"
|
|
261
|
+
const hourTotal = Math.floor(sec / (60 * 60));
|
|
262
|
+
showHour = hourTotal < 10 ? '0' + hourTotal : String(hourTotal);
|
|
263
|
+
}
|
|
264
|
+
let minuteNum = Math.floor(sec / 60) - hourNum * 60 - dayNum * 24 * 60;
|
|
265
|
+
let secondNum = Math.floor(sec) - dayNum * 24 * 60 * 60 - hourNum * 60 * 60 - minuteNum * 60;
|
|
266
|
+
const minute = minuteNum < 10 ? '0' + minuteNum : String(minuteNum);
|
|
267
|
+
const second = secondNum < 10 ? '0' + secondNum : String(secondNum);
|
|
268
|
+
const day = dayNum < 10 ? '0' + dayNum : String(dayNum);
|
|
269
|
+
d.value = day;
|
|
270
|
+
h.value = showHour;
|
|
271
|
+
i.value = minute;
|
|
272
|
+
s.value = second;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* 停止倒计时
|
|
277
|
+
*/
|
|
278
|
+
function end() {
|
|
279
|
+
clearTimer();
|
|
280
|
+
emit('end', {});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* 清除定时器
|
|
285
|
+
*/
|
|
286
|
+
function clearTimer() {
|
|
287
|
+
if (timer.value) {
|
|
288
|
+
clearInterval(timer.value);
|
|
289
|
+
timer.value = null;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
</script>
|
|
293
|
+
|
|
294
|
+
<style scoped lang="scss">
|
|
295
|
+
@import '../../libs/css/style.components.scss';
|
|
296
|
+
|
|
297
|
+
.u-countdown {
|
|
298
|
+
/* #ifndef APP-NVUE */
|
|
299
|
+
display: inline-flex;
|
|
300
|
+
/* #endif */
|
|
301
|
+
align-items: center;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
.u-countdown-item {
|
|
305
|
+
@include vue-flex;
|
|
306
|
+
align-items: center;
|
|
307
|
+
justify-content: center;
|
|
308
|
+
padding: 2rpx;
|
|
309
|
+
border-radius: 6rpx;
|
|
310
|
+
white-space: nowrap;
|
|
311
|
+
transform: translateZ(0);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
.u-countdown-time {
|
|
315
|
+
margin: 0;
|
|
316
|
+
padding: 0;
|
|
317
|
+
line-height: 1;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
.u-countdown-colon {
|
|
321
|
+
@include vue-flex;
|
|
322
|
+
justify-content: center;
|
|
323
|
+
padding: 0 5rpx;
|
|
324
|
+
line-height: 1;
|
|
325
|
+
align-items: center;
|
|
326
|
+
padding-bottom: 4rpx;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
.u-countdown-scale {
|
|
330
|
+
transform: scale(0.9);
|
|
331
|
+
transform-origin: center center;
|
|
332
|
+
}
|
|
333
|
+
</style>
|