Skip to content
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

Merged
merged 2 commits into from
Nov 6, 2019
Merged

Conversation

shoyuf
Copy link
Member

@shoyuf shoyuf commented Nov 1, 2019

Why

使用过程中发现的几个问题

  1. feat: format 支持 ms 处理,补齐天时分秒毫秒输出的格式
  2. props 没有支持到 millisecond

How

Detail in commits 🤙

Test

dev...shoyuf:dev#diff-d5a5c858fb7261c905d152bd5ed0c9d2

Docs

Already changed in api documents

@auto-add-label auto-add-label bot added the enhancement New feature or request label Nov 1, 2019
@netlify
Copy link

netlify bot commented Nov 1, 2019

Deploy preview for femessage-count-down ready!

Built with commit b6a97bd

https://deploy-preview-6--femessage-count-down.netlify.com

@levy9527
Copy link
Collaborator

levy9527 commented Nov 4, 2019

1.为何会有 breaking change
2.时间戳同时支持10位与13位是出于什么考虑。

@shoyuf
Copy link
Member Author

shoyuf commented Nov 4, 2019

1.为何会有 breaking change
2.时间戳同时支持10位与13位是出于什么考虑。

  1. https://github.com/FEMessage/count-down/pull/6/files#diff-34a6d62af0cf0b784f8444529f3130efR56

timeFormatter 没有对天数进行格式化,之前一位的天数会自动在前面添加0,而现在表现为不自动加0

  1. 时间戳支持10和13位出于对服务端返回的秒和毫秒两种类型时间戳进行兼容

@@ -0,0 +1,5 @@
```vue
<template>
<count-down :timestamp="(()=>new Date().getTime() + 3600000)()" />
Copy link
Contributor

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"即可

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea !

default: 0,
validator(e) {
const len = e.toString().length
if (len === 13 || len === 10) {
Copy link
Contributor

@donaldshen donaldshen Nov 5, 2019

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,
Copy link
Contributor

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: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个可以有

Copy link
Contributor

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(
Copy link
Contributor

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') {
Copy link
Contributor

@donaldshen donaldshen Nov 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

days没有处理。似乎是你有意的,为啥哩

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得天数没必要补0处理

Copy link
Contributor

@donaldshen donaldshen left a 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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slot的用途是方便用户自定义处理倒计时数据的,所以会传原始数据。补了0变成字符串,定制就麻烦了些

@shoyuf
Copy link
Member Author

shoyuf commented Nov 6, 2019

  1. format 和 slot 表现的结果不一致(slot 内的时间数据没有补齐)
  2. slot 内的 hours, minutes, seconds, milliseconds 补齐(同时避免毫秒在有背景色的情况下显示宽度一直在抖动)

这两个commit需要讨论一下

  1. 第一个问题包含两个问题
    1. format prop 不支持ms
    2. 之前使用format prop和slot,在相同传入参数情况下,表现结果不一致

案例:

<count-down :seconds="59" :days="1" format="dd天 hh:mm:ss.ms" />

修改前输出 01天 00:00:59
修改后输出 1天 00:00:59.000

<count-down :seconds="59" :days="1">
<template v-slot="{days,hours,minutes,seconds,milliseconds}">
{{`${days}天 ${hours}:${minutes}:${seconds}.${milliseconds}`}}
</template>
</count-down>

修改前输出:1天 0: 0:59.0
修改后输出:1天 00: 00:59.000

  1. 第二个问题如图,时分秒在降到个位数时宽度不易控制,但主要问题还是第一个问题的不一致情况

@lianghx-319
Copy link
Member

  1. format 和 slot 表现的结果不一致(slot 内的时间数据没有补齐)
  2. slot 内的 hours, minutes, seconds, milliseconds 补齐(同时避免毫秒在有背景色的情况下显示宽度一直在抖动)

这两个commit需要讨论一下

  1. 第一个问题包含两个问题

    1. format prop 不支持ms
    2. 之前使用format prop和slot,在相同传入参数情况下,表现结果不一致

案例:

<count-down :seconds="59" :days="1" format="dd天 hh:mm:ss.ms" />

修改前输出 01天 00:00:59
修改后输出 1天 00:00:59.000

<count-down :seconds="59" :days="1">
<template v-slot="{days,hours,minutes,seconds,milliseconds}">
{{`${days}天 ${hours}:${minutes}:${seconds}.${milliseconds}`}}
</template>
</count-down>

修改前输出:1天 0: 0:59.0
修改后输出:1天 00: 00:59.000

  1. 第二个问题如图,时分秒在降到个位数时宽度不易控制,但主要问题还是第一个问题的不一致情况
  1. ms 的 props 可以确认增加的
  2. slot 原则上还是传源数据,需要处理补零的话,其实可以在外部用 filter。

@levy9527 levy9527 changed the title feat: 一些小改进 feat(milliseconds): 支持毫秒倒计时 Nov 6, 2019
@levy9527
Copy link
Collaborator

levy9527 commented Nov 6, 2019

@all-contributors add @shoyuf code

@allcontributors
Copy link
Contributor

@levy9527

I've put up a pull request to add @shoyuf! 🎉

@levy9527 levy9527 merged commit cd712c6 into FEMessage:dev Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants