first
This commit is contained in:
1
node_modules/vant/lib/count-down/index.css
generated
vendored
Normal file
1
node_modules/vant/lib/count-down/index.css
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
.van-count-down{color:#323233;font-size:14px;line-height:20px}
|
164
node_modules/vant/lib/count-down/index.js
generated
vendored
Normal file
164
node_modules/vant/lib/count-down/index.js
generated
vendored
Normal file
@ -0,0 +1,164 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = void 0;
|
||||
|
||||
var _utils = require("../utils");
|
||||
|
||||
var _raf = require("../utils/dom/raf");
|
||||
|
||||
var _utils2 = require("./utils");
|
||||
|
||||
var _createNamespace = (0, _utils.createNamespace)('count-down'),
|
||||
createComponent = _createNamespace[0],
|
||||
bem = _createNamespace[1];
|
||||
|
||||
var _default = createComponent({
|
||||
props: {
|
||||
millisecond: Boolean,
|
||||
time: {
|
||||
type: [Number, String],
|
||||
default: 0
|
||||
},
|
||||
format: {
|
||||
type: String,
|
||||
default: 'HH:mm:ss'
|
||||
},
|
||||
autoStart: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
},
|
||||
data: function data() {
|
||||
return {
|
||||
remain: 0
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
timeData: function timeData() {
|
||||
return (0, _utils2.parseTimeData)(this.remain);
|
||||
},
|
||||
formattedTime: function formattedTime() {
|
||||
return (0, _utils2.parseFormat)(this.format, this.timeData);
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
time: {
|
||||
immediate: true,
|
||||
handler: 'reset'
|
||||
}
|
||||
},
|
||||
activated: function activated() {
|
||||
if (this.keepAlivePaused) {
|
||||
this.counting = true;
|
||||
this.keepAlivePaused = false;
|
||||
this.tick();
|
||||
}
|
||||
},
|
||||
deactivated: function deactivated() {
|
||||
if (this.counting) {
|
||||
this.pause();
|
||||
this.keepAlivePaused = true;
|
||||
}
|
||||
},
|
||||
beforeDestroy: function beforeDestroy() {
|
||||
this.pause();
|
||||
},
|
||||
methods: {
|
||||
// @exposed-api
|
||||
start: function start() {
|
||||
if (this.counting) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.counting = true;
|
||||
this.endTime = Date.now() + this.remain;
|
||||
this.tick();
|
||||
},
|
||||
// @exposed-api
|
||||
pause: function pause() {
|
||||
this.counting = false;
|
||||
(0, _raf.cancelRaf)(this.rafId);
|
||||
},
|
||||
// @exposed-api
|
||||
reset: function reset() {
|
||||
this.pause();
|
||||
this.remain = +this.time;
|
||||
|
||||
if (this.autoStart) {
|
||||
this.start();
|
||||
}
|
||||
},
|
||||
tick: function tick() {
|
||||
// should not start counting in server
|
||||
// see: https://github.com/vant-ui/vant/issues/7807
|
||||
if (!_utils.inBrowser) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.millisecond) {
|
||||
this.microTick();
|
||||
} else {
|
||||
this.macroTick();
|
||||
}
|
||||
},
|
||||
microTick: function microTick() {
|
||||
var _this = this;
|
||||
|
||||
this.rafId = (0, _raf.raf)(function () {
|
||||
/* istanbul ignore if */
|
||||
// in case of call reset immediately after finish
|
||||
if (!_this.counting) {
|
||||
return;
|
||||
}
|
||||
|
||||
_this.setRemain(_this.getRemain());
|
||||
|
||||
if (_this.remain > 0) {
|
||||
_this.microTick();
|
||||
}
|
||||
});
|
||||
},
|
||||
macroTick: function macroTick() {
|
||||
var _this2 = this;
|
||||
|
||||
this.rafId = (0, _raf.raf)(function () {
|
||||
/* istanbul ignore if */
|
||||
// in case of call reset immediately after finish
|
||||
if (!_this2.counting) {
|
||||
return;
|
||||
}
|
||||
|
||||
var remain = _this2.getRemain();
|
||||
|
||||
if (!(0, _utils2.isSameSecond)(remain, _this2.remain) || remain === 0) {
|
||||
_this2.setRemain(remain);
|
||||
}
|
||||
|
||||
if (_this2.remain > 0) {
|
||||
_this2.macroTick();
|
||||
}
|
||||
});
|
||||
},
|
||||
getRemain: function getRemain() {
|
||||
return Math.max(this.endTime - Date.now(), 0);
|
||||
},
|
||||
setRemain: function setRemain(remain) {
|
||||
this.remain = remain;
|
||||
this.$emit('change', this.timeData);
|
||||
|
||||
if (remain === 0) {
|
||||
this.pause();
|
||||
this.$emit('finish');
|
||||
}
|
||||
}
|
||||
},
|
||||
render: function render() {
|
||||
var h = arguments[0];
|
||||
return h("div", {
|
||||
"class": bem()
|
||||
}, [this.slots('default', this.timeData) || this.formattedTime]);
|
||||
}
|
||||
});
|
||||
|
||||
exports.default = _default;
|
7
node_modules/vant/lib/count-down/index.less
generated
vendored
Normal file
7
node_modules/vant/lib/count-down/index.less
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
@import '../style/var';
|
||||
|
||||
.van-count-down {
|
||||
color: @count-down-text-color;
|
||||
font-size: @count-down-font-size;
|
||||
line-height: @count-down-line-height;
|
||||
}
|
2
node_modules/vant/lib/count-down/style/index.js
generated
vendored
Normal file
2
node_modules/vant/lib/count-down/style/index.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
require('../../style/base.css');
|
||||
require('../index.css');
|
2
node_modules/vant/lib/count-down/style/less.js
generated
vendored
Normal file
2
node_modules/vant/lib/count-down/style/less.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
require('../../style/base.less');
|
||||
require('../index.less');
|
78
node_modules/vant/lib/count-down/utils.js
generated
vendored
Normal file
78
node_modules/vant/lib/count-down/utils.js
generated
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.parseTimeData = parseTimeData;
|
||||
exports.parseFormat = parseFormat;
|
||||
exports.isSameSecond = isSameSecond;
|
||||
|
||||
var _string = require("../utils/format/string");
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
|
||||
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', (0, _string.padZero)(days));
|
||||
}
|
||||
|
||||
if (format.indexOf('HH') === -1) {
|
||||
minutes += hours * 60;
|
||||
} else {
|
||||
format = format.replace('HH', (0, _string.padZero)(hours));
|
||||
}
|
||||
|
||||
if (format.indexOf('mm') === -1) {
|
||||
seconds += minutes * 60;
|
||||
} else {
|
||||
format = format.replace('mm', (0, _string.padZero)(minutes));
|
||||
}
|
||||
|
||||
if (format.indexOf('ss') === -1) {
|
||||
milliseconds += seconds * 1000;
|
||||
} else {
|
||||
format = format.replace('ss', (0, _string.padZero)(seconds));
|
||||
}
|
||||
|
||||
if (format.indexOf('S') !== -1) {
|
||||
var ms = (0, _string.padZero)(milliseconds, 3);
|
||||
|
||||
if (format.indexOf('SSS') !== -1) {
|
||||
format = format.replace('SSS', ms);
|
||||
} else if (format.indexOf('SS') !== -1) {
|
||||
format = format.replace('SS', ms.slice(0, 2));
|
||||
} else {
|
||||
format = format.replace('S', ms.charAt(0));
|
||||
}
|
||||
}
|
||||
|
||||
return format;
|
||||
}
|
||||
|
||||
function isSameSecond(time1, time2) {
|
||||
return Math.floor(time1 / 1000) === Math.floor(time2 / 1000);
|
||||
}
|
Reference in New Issue
Block a user