From e437bf9b312c468f87e0855689bb9a4790d6bf9e Mon Sep 17 00:00:00 2001 From: shoyuf Date: Thu, 31 Oct 2019 15:11:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=84=E4=BB=B6=E4=BC=A0=E5=85=A5=20?= =?UTF-8?q?prop=20=E6=94=AF=E6=8C=81=20=20milliseconds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/count-down.vue | 7 +++++++ src/util.js | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/count-down.vue b/src/count-down.vue index fa34376..9181692 100644 --- a/src/count-down.vue +++ b/src/count-down.vue @@ -38,6 +38,13 @@ export default { type: Number, default: 0 }, + /** + * remain milliseconds + */ + milliseconds: { + type: Number, + default: 0 + }, /** * whether autoplay or not */ diff --git a/src/util.js b/src/util.js index c70880d..37a035f 100644 --- a/src/util.js +++ b/src/util.js @@ -6,7 +6,7 @@ const formatSpecifiers = { seconds: 'ss', milliseconds: 'ms' } -const secondsIn = { +const millisecondsIn = { days: 60 * 60 * 24 * 1000, hours: 60 * 60 * 1000, minutes: 60 * 1000, @@ -77,8 +77,8 @@ export function formatTime(time, format) { // 注意顺序很重要。要先从大的时间单位开始构造字符串 entries(formatSpecifiers).forEach(([k, specifier]) => { if (includes(result, specifier)) { - const v = Math.floor(time / secondsIn[k]) - time -= v * secondsIn[k] + const v = Math.floor(time / millisecondsIn[k]) + time -= v * millisecondsIn[k] result = result.replace(specifier, timeFormatter(k, v)) } }) @@ -92,7 +92,7 @@ export function formatTime(time, format) { */ export function toTimeData(time) { const timeData = {} - entries(secondsIn).forEach(([k, v]) => { + entries(millisecondsIn).forEach(([k, v]) => { timeData[k] = Math.floor(time / v) time -= timeData[k] * v })