-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(milliseconds): 支持毫秒倒计时 #6
Conversation
Deploy preview for femessage-count-down ready! Built with commit b6a97bd |
1.为何会有 breaking change |
timeFormatter 没有对天数进行格式化,之前一位的天数会自动在前面添加0,而现在表现为不自动加0
|
docs/timestamp.md
Outdated
@@ -0,0 +1,5 @@ | |||
```vue | |||
<template> | |||
<count-down :timestamp="(()=>new Date().getTime() + 3600000)()" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
假设服务器传的是截止时间戳,那么传:seconds="(timestamp - Date.now()) / 1000"
即可
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea !
src/count-down.vue
Outdated
default: 0, | ||
validator(e) { | ||
const len = e.toString().length | ||
if (len === 13 || len === 10) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0到13位都有可能呀
hours: 60 * 60, | ||
minutes: 60, | ||
seconds: 1 | ||
days: 60 * 60 * 24 * 1000, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果都乘以1000,那么名字就该叫millisecondsIn
了……
/** | ||
* remain milliseconds | ||
*/ | ||
milliseconds: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个可以有
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
之前没有加毫秒的考虑是:已经有:seconds="time / 1000"
这种写法了;再加个:milliseconds="time"
似乎没有节省字符数……
src/util.js
Outdated
* @param {number} timestamp - 时间戳 | ||
* @returns {number} 时间对象到毫秒转化结果 | ||
*/ | ||
export function toMilliseconds( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个函数现在藏了两套完全不同的逻辑。
src/util.js
Outdated
*/ | ||
function timeFormatter(key, value) { | ||
// 天数不格式化,时分秒两位,毫秒三位 | ||
if (key === 'hours' || key === 'minutes' || key === 'seconds') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
days没有处理。似乎是你有意的,为啥哩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我觉得天数没必要补0处理
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议保留milliseconds这个prop,其他像timestamp这样的改动就没必要了
src/util.js
Outdated
entries(secondsIn).forEach(([k, v]) => { | ||
timeData[k] = Math.floor(time / v) | ||
time -= timeData[k] * v | ||
timeData[k] = timeFormatter(k, Math.floor(time / v)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slot的用途是方便用户自定义处理倒计时数据的,所以会传原始数据。补了0变成字符串,定制就麻烦了些
这两个commit需要讨论一下
案例: <count-down :seconds="59" :days="1" format="dd天 hh:mm:ss.ms" /> 修改前输出 <count-down :seconds="59" :days="1">
<template v-slot="{days,hours,minutes,seconds,milliseconds}">
{{`${days}天 ${hours}:${minutes}:${seconds}.${milliseconds}`}}
</template>
</count-down> 修改前输出: |
|
天数、时、分、秒补全两位,毫秒补全三位
@all-contributors add @shoyuf code |
I've put up a pull request to add @shoyuf! 🎉 |
Why
使用过程中发现的几个问题
How
Detail in commits 🤙
Test
dev...shoyuf:dev#diff-d5a5c858fb7261c905d152bd5ed0c9d2
Docs
Already changed in api documents