提交初始版本,使用vant ui库

This commit is contained in:
2024-02-01 14:38:56 +08:00
commit 787a1f26b6
480 changed files with 12239 additions and 0 deletions

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,104 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var component_1 = require("../common/component");
var utils_1 = require("./utils");
function simpleTick(fn) {
return setTimeout(fn, 30);
}
(0, component_1.VantComponent)({
props: {
useSlot: Boolean,
millisecond: Boolean,
time: {
type: Number,
observer: 'reset',
},
format: {
type: String,
value: 'HH:mm:ss',
},
autoStart: {
type: Boolean,
value: true,
},
},
data: {
timeData: (0, utils_1.parseTimeData)(0),
formattedTime: '0',
},
destroyed: function () {
clearTimeout(this.tid);
this.tid = null;
},
methods: {
// 开始
start: function () {
if (this.counting) {
return;
}
this.counting = true;
this.endTime = Date.now() + this.remain;
this.tick();
},
// 暂停
pause: function () {
this.counting = false;
clearTimeout(this.tid);
},
// 重置
reset: function () {
this.pause();
this.remain = this.data.time;
this.setRemain(this.remain);
if (this.data.autoStart) {
this.start();
}
},
tick: function () {
if (this.data.millisecond) {
this.microTick();
}
else {
this.macroTick();
}
},
microTick: function () {
var _this = this;
this.tid = simpleTick(function () {
_this.setRemain(_this.getRemain());
if (_this.remain !== 0) {
_this.microTick();
}
});
},
macroTick: function () {
var _this = this;
this.tid = simpleTick(function () {
var remain = _this.getRemain();
if (!(0, utils_1.isSameSecond)(remain, _this.remain) || remain === 0) {
_this.setRemain(remain);
}
if (_this.remain !== 0) {
_this.macroTick();
}
});
},
getRemain: function () {
return Math.max(this.endTime - Date.now(), 0);
},
setRemain: function (remain) {
this.remain = remain;
var timeData = (0, utils_1.parseTimeData)(remain);
if (this.data.useSlot) {
this.$emit('change', timeData);
}
this.setData({
formattedTime: (0, utils_1.parseFormat)(this.data.format, timeData),
});
if (remain === 0) {
this.pause();
this.$emit('finish');
}
},
},
});

View File

@@ -0,0 +1,3 @@
{
"component": true
}

View File

@@ -0,0 +1,4 @@
<view class="van-count-down">
<slot wx:if="{{ useSlot }}"/>
<block wx:else>{{ formattedTime }}</block>
</view>

View File

@@ -0,0 +1 @@
@import '../common/index.wxss';.van-count-down{color:var(--count-down-text-color,#323233);font-size:var(--count-down-font-size,14px);line-height:var(--count-down-line-height,20px)}

View File

@@ -0,0 +1,10 @@
export type TimeData = {
days: number;
hours: number;
minutes: number;
seconds: number;
milliseconds: number;
};
export declare function parseTimeData(time: number): TimeData;
export declare function parseFormat(format: string, timeData: TimeData): string;
export declare function isSameSecond(time1: number, time2: number): boolean;

View File

@@ -0,0 +1,64 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isSameSecond = exports.parseFormat = exports.parseTimeData = void 0;
function padZero(num, targetLength) {
if (targetLength === void 0) { targetLength = 2; }
var str = num + '';
while (str.length < targetLength) {
str = '0' + str;
}
return str;
}
var SECOND = 1000;
var MINUTE = 60 * SECOND;
var HOUR = 60 * MINUTE;
var DAY = 24 * HOUR;
function parseTimeData(time) {
var days = Math.floor(time / DAY);
var hours = Math.floor((time % DAY) / HOUR);
var minutes = Math.floor((time % HOUR) / MINUTE);
var seconds = Math.floor((time % MINUTE) / SECOND);
var milliseconds = Math.floor(time % SECOND);
return {
days: days,
hours: hours,
minutes: minutes,
seconds: seconds,
milliseconds: milliseconds,
};
}
exports.parseTimeData = parseTimeData;
function parseFormat(format, timeData) {
var days = timeData.days;
var hours = timeData.hours, minutes = timeData.minutes, seconds = timeData.seconds, milliseconds = timeData.milliseconds;
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 * 1000;
}
else {
format = format.replace('ss', padZero(seconds));
}
return format.replace('SSS', padZero(milliseconds, 3));
}
exports.parseFormat = parseFormat;
function isSameSecond(time1, time2) {
return Math.floor(time1 / 1000) === Math.floor(time2 / 1000);
}
exports.isSameSecond = isSameSecond;