增加新模块
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
const CountDown = {
|
||||
// u-count-down 计时器组件
|
||||
countDown: {
|
||||
time: 0,
|
||||
format: "HH:mm:ss",
|
||||
autoStart: true,
|
||||
millisecond: false
|
||||
}
|
||||
};
|
||||
exports.CountDown = CountDown;
|
||||
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/uview-plus/components/u-count-down/countDown.js.map
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
const uni_modules_uviewPlus_libs_vue = require("../../libs/vue.js");
|
||||
const uni_modules_uviewPlus_libs_config_props = require("../../libs/config/props.js");
|
||||
const props = uni_modules_uviewPlus_libs_vue.defineMixin({
|
||||
props: {
|
||||
// 倒计时时长,单位ms
|
||||
time: {
|
||||
type: [String, Number],
|
||||
default: () => uni_modules_uviewPlus_libs_config_props.defProps.countDown.time
|
||||
},
|
||||
// 时间格式,DD-日,HH-时,mm-分,ss-秒,SSS-毫秒
|
||||
format: {
|
||||
type: String,
|
||||
default: () => uni_modules_uviewPlus_libs_config_props.defProps.countDown.format
|
||||
},
|
||||
// 是否自动开始倒计时
|
||||
autoStart: {
|
||||
type: Boolean,
|
||||
default: () => uni_modules_uviewPlus_libs_config_props.defProps.countDown.autoStart
|
||||
},
|
||||
// 是否展示毫秒倒计时
|
||||
millisecond: {
|
||||
type: Boolean,
|
||||
default: () => uni_modules_uviewPlus_libs_config_props.defProps.countDown.millisecond
|
||||
}
|
||||
}
|
||||
});
|
||||
exports.props = props;
|
||||
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/uview-plus/components/u-count-down/props.js.map
|
||||
Vendored
+121
@@ -0,0 +1,121 @@
|
||||
"use strict";
|
||||
const uni_modules_uviewPlus_components_uCountDown_props = require("./props.js");
|
||||
const uni_modules_uviewPlus_libs_mixin_mpMixin = require("../../libs/mixin/mpMixin.js");
|
||||
const uni_modules_uviewPlus_libs_mixin_mixin = require("../../libs/mixin/mixin.js");
|
||||
const uni_modules_uviewPlus_components_uCountDown_utils = require("./utils.js");
|
||||
const common_vendor = require("../../../../common/vendor.js");
|
||||
const _sfc_main = {
|
||||
name: "u-count-down",
|
||||
mixins: [uni_modules_uviewPlus_libs_mixin_mpMixin.mpMixin, uni_modules_uviewPlus_libs_mixin_mixin.mixin, uni_modules_uviewPlus_components_uCountDown_props.props],
|
||||
data() {
|
||||
return {
|
||||
timer: null,
|
||||
// 各单位(天,时,分等)剩余时间
|
||||
timeData: uni_modules_uviewPlus_components_uCountDown_utils.parseTimeData(0),
|
||||
// 格式化后的时间,如"03:23:21"
|
||||
formattedTime: "0",
|
||||
// 倒计时是否正在进行中
|
||||
runing: false,
|
||||
endTime: 0,
|
||||
// 结束的毫秒时间戳
|
||||
remainTime: 0
|
||||
// 剩余的毫秒时间
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
time(n) {
|
||||
this.reset();
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.init();
|
||||
},
|
||||
emits: ["change", "finish"],
|
||||
methods: {
|
||||
init() {
|
||||
this.reset();
|
||||
},
|
||||
// 开始倒计时
|
||||
start() {
|
||||
if (this.runing)
|
||||
return;
|
||||
this.runing = true;
|
||||
this.endTime = Date.now() + this.remainTime;
|
||||
this.toTick();
|
||||
},
|
||||
// 根据是否展示毫秒,执行不同操作函数
|
||||
toTick() {
|
||||
if (this.millisecond) {
|
||||
this.microTick();
|
||||
} else {
|
||||
this.macroTick();
|
||||
}
|
||||
},
|
||||
macroTick() {
|
||||
this.clearTimeout();
|
||||
this.timer = setTimeout(() => {
|
||||
const remain = this.getRemainTime();
|
||||
if (!uni_modules_uviewPlus_components_uCountDown_utils.isSameSecond(remain, this.remainTime) || remain === 0) {
|
||||
this.setRemainTime(remain);
|
||||
}
|
||||
if (this.remainTime !== 0) {
|
||||
this.macroTick();
|
||||
}
|
||||
}, 30);
|
||||
},
|
||||
microTick() {
|
||||
this.clearTimeout();
|
||||
this.timer = setTimeout(() => {
|
||||
this.setRemainTime(this.getRemainTime());
|
||||
if (this.remainTime !== 0) {
|
||||
this.microTick();
|
||||
}
|
||||
}, 50);
|
||||
},
|
||||
// 获取剩余的时间
|
||||
getRemainTime() {
|
||||
return Math.max(this.endTime - Date.now(), 0);
|
||||
},
|
||||
// 设置剩余的时间
|
||||
setRemainTime(remain) {
|
||||
this.remainTime = remain;
|
||||
const timeData = uni_modules_uviewPlus_components_uCountDown_utils.parseTimeData(remain);
|
||||
this.$emit("change", timeData);
|
||||
this.formattedTime = uni_modules_uviewPlus_components_uCountDown_utils.parseFormat(this.format, timeData);
|
||||
if (remain <= 0) {
|
||||
this.pause();
|
||||
this.$emit("finish");
|
||||
}
|
||||
},
|
||||
// 重置倒计时
|
||||
reset() {
|
||||
this.pause();
|
||||
this.remainTime = this.time;
|
||||
this.setRemainTime(this.remainTime);
|
||||
if (this.autoStart) {
|
||||
this.start();
|
||||
}
|
||||
},
|
||||
// 暂停倒计时
|
||||
pause() {
|
||||
this.runing = false;
|
||||
this.clearTimeout();
|
||||
},
|
||||
// 清空定时器
|
||||
clearTimeout() {
|
||||
clearTimeout(this.timer);
|
||||
this.timer = null;
|
||||
}
|
||||
},
|
||||
beforeUnmount() {
|
||||
this.clearTimeout();
|
||||
}
|
||||
};
|
||||
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||
return {
|
||||
a: common_vendor.t($data.formattedTime)
|
||||
};
|
||||
}
|
||||
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2f829c0f"]]);
|
||||
wx.createComponent(Component);
|
||||
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/uview-plus/components/u-count-down/u-count-down.js.map
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {}
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
<view class="u-count-down data-v-2f829c0f"><block wx:if="{{$slots.d}}"><slot></slot></block><block wx:else><text class="u-count-down__text data-v-2f829c0f">{{a}}</text></block></view>
|
||||
Vendored
+53
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* 这里是uni-app内置的常用样式变量
|
||||
*
|
||||
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
|
||||
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
|
||||
*
|
||||
*/
|
||||
/* uni.scss */
|
||||
/**
|
||||
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
|
||||
*
|
||||
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
|
||||
*/
|
||||
/* 颜色变量 */
|
||||
/* 行为相关颜色 */
|
||||
/* 文字基本颜色 */
|
||||
/* 背景颜色 */
|
||||
/* 边框颜色 */
|
||||
/* 尺寸变量 */
|
||||
/* 文字尺寸 */
|
||||
/* 图片尺寸 */
|
||||
/* Border Radius */
|
||||
/* 水平间距 */
|
||||
/* 垂直间距 */
|
||||
.u-empty.data-v-2f829c0f,
|
||||
.u-empty__wrap.data-v-2f829c0f,
|
||||
.u-tabs.data-v-2f829c0f,
|
||||
.u-tabs__wrapper.data-v-2f829c0f,
|
||||
.u-tabs__wrapper__scroll-view-wrapper.data-v-2f829c0f,
|
||||
.u-tabs__wrapper__scroll-view.data-v-2f829c0f,
|
||||
.u-tabs__wrapper__nav.data-v-2f829c0f,
|
||||
.u-tabs__wrapper__nav__line.data-v-2f829c0f,
|
||||
.up-empty.data-v-2f829c0f,
|
||||
.up-empty__wrap.data-v-2f829c0f,
|
||||
.up-tabs.data-v-2f829c0f,
|
||||
.up-tabs__wrapper.data-v-2f829c0f,
|
||||
.up-tabs__wrapper__scroll-view-wrapper.data-v-2f829c0f,
|
||||
.up-tabs__wrapper__scroll-view.data-v-2f829c0f,
|
||||
.up-tabs__wrapper__nav.data-v-2f829c0f,
|
||||
.up-tabs__wrapper__nav__line.data-v-2f829c0f {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-shrink: 0;
|
||||
flex-grow: 0;
|
||||
flex-basis: auto;
|
||||
align-items: stretch;
|
||||
align-content: flex-start;
|
||||
}
|
||||
.u-count-down__text.data-v-2f829c0f {
|
||||
color: #606266;
|
||||
font-size: 15px;
|
||||
line-height: 22px;
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
"use strict";
|
||||
function padZero(num, targetLength = 2) {
|
||||
let str = `${num}`;
|
||||
while (str.length < targetLength) {
|
||||
str = `0${str}`;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
const SECOND = 1e3;
|
||||
const MINUTE = 60 * SECOND;
|
||||
const HOUR = 60 * MINUTE;
|
||||
const DAY = 24 * HOUR;
|
||||
function parseTimeData(time) {
|
||||
const days = Math.floor(time / DAY);
|
||||
const hours = Math.floor(time % DAY / HOUR);
|
||||
const minutes = Math.floor(time % HOUR / MINUTE);
|
||||
const seconds = Math.floor(time % MINUTE / SECOND);
|
||||
const milliseconds = Math.floor(time % SECOND);
|
||||
return {
|
||||
days,
|
||||
hours,
|
||||
minutes,
|
||||
seconds,
|
||||
milliseconds
|
||||
};
|
||||
}
|
||||
function parseFormat(format, timeData) {
|
||||
let {
|
||||
days,
|
||||
hours,
|
||||
minutes,
|
||||
seconds,
|
||||
milliseconds
|
||||
} = timeData;
|
||||
if (format.indexOf("DD") === -1) {
|
||||
hours += days * 24;
|
||||
} else {
|
||||
format = format.replace("DD", padZero(days));
|
||||
}
|
||||
if (format.indexOf("HH") === -1) {
|
||||
minutes += hours * 60;
|
||||
} else {
|
||||
format = format.replace("HH", padZero(hours));
|
||||
}
|
||||
if (format.indexOf("mm") === -1) {
|
||||
seconds += minutes * 60;
|
||||
} else {
|
||||
format = format.replace("mm", padZero(minutes));
|
||||
}
|
||||
if (format.indexOf("ss") === -1) {
|
||||
milliseconds += seconds * 1e3;
|
||||
} else {
|
||||
format = format.replace("ss", padZero(seconds));
|
||||
}
|
||||
return format.replace("SSS", padZero(milliseconds, 3));
|
||||
}
|
||||
function isSameSecond(time1, time2) {
|
||||
return Math.floor(time1 / 1e3) === Math.floor(time2 / 1e3);
|
||||
}
|
||||
exports.isSameSecond = isSameSecond;
|
||||
exports.parseFormat = parseFormat;
|
||||
exports.parseTimeData = parseTimeData;
|
||||
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/uview-plus/components/u-count-down/utils.js.map
|
||||
Reference in New Issue
Block a user