Skip to content

Commit

Permalink
fix 提供时间戳单位选择 #baiy#167
Browse files Browse the repository at this point in the history
  • Loading branch information
xyeluo committed Nov 1, 2022
1 parent b615d74 commit 0a38511
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/i18n/locales/en/timestamp.i18n.json5
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
"error_format": "Input Format Error",
"error":"error:{0}",
"format": "Format",
"value":"Value"
"value":"Value",
"unit_seconds":"Seconds",
"unit_milliseconds":"Millisecond",
}
4 changes: 3 additions & 1 deletion src/i18n/locales/zh_CN/timestamp.i18n.json5
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
"error_format": "输入时间格式异常",
"error":"错误:{0}",
"format": "格式",
"value":"值"
"value":"值",
"unit_seconds":"秒(s)",
"unit_milliseconds":"毫秒(ms)",
}
23 changes: 20 additions & 3 deletions src/views/tool/timestamp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
<span slot="prepend">{{ $t('timestamp_input') }}</span>
</Input>
<template slot="extra">
<Dropdown @on-click="currentTimeUnit" transfer style="margin-right: 10px">
<Button size="small" type="primary">
{{ $t(`timestamp_unit_${current.timeUnit}`) }}
<Icon type="ios-arrow-down"></Icon>
</Button>
<DropdownMenu slot="list">
<DropdownItem name="seconds">{{ $t('timestamp_unit_seconds') }}</DropdownItem>
<DropdownItem name="milliseconds">{{ $t('timestamp_unit_milliseconds') }}</DropdownItem>
</DropdownMenu>
</Dropdown>
<Dropdown @on-click="currentTime" transfer>
<Button size="small" type="primary">
{{ $t('timestamp_get') }}
Expand Down Expand Up @@ -99,17 +109,18 @@ export default {
return result;
}
try {
let timeUnit = this.current.timeUnit
let type = function (input) {
if ((new RegExp(/^\d+-\d+-\d+ \d+:\d+:\d+$/)).test(input)) {
return inputType.normalSecond
}
if ((new RegExp(/^\d+-\d+-\d+ \d+:\d+:\d+\.\d+$/)).test(input)) {
return inputType.normalMillisecond
}
if ((new RegExp(/^\d{10}$/)).test(input)) {
if ((new RegExp(/^\d{10}$/)).test(input) || timeUnit === 'seconds') {
return inputType.unixSecond
}
if ((new RegExp(/^\d{13,}$/)).test(input)) {
if ((new RegExp(/^\d{13,}$/)).test(input) || timeUnit === 'milliseconds') {
return inputType.unixMillisecond
}
return inputType.error
Expand Down Expand Up @@ -146,15 +157,21 @@ export default {
this.current.input = moment().format('YYYY-MM-DD HH:mm:ss.SSS')
} else if (type === "unixSecond") {
this.current.input = moment().format('X')
this.current.timeUnit = 'seconds'
} else {
this.current.input = moment().format('x')
this.current.timeUnit = 'milliseconds'
}
},
currentTimeUnit(unit){
this.current.timeUnit = unit
}
},
data() {
return {
current: {
input: moment().format('YYYY-MM-DD HH:mm:ss')
input: moment().format('YYYY-MM-DD HH:mm:ss'),
timeUnit:'seconds'
},
timer: null,
timestamp: 0,
Expand Down

0 comments on commit 0a38511

Please sign in to comment.