support datetime
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# PassTimeLabel 时间标签
|
# PassTimeLabel 时间标签
|
||||||
|
|
||||||
把时间戳显示为「多久以前」,点击可切换为完整日期时间。
|
接收时间戳或 `yyyy-MM-dd HH:mm:ss`、`yyyy-MM-ddTHH:mm:ss` 格式的日期时间字符串,显示为「多久以前」,点击可切换为完整日期时间。
|
||||||
|
|
||||||
## 基础用法
|
## 基础用法
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<span
|
<span
|
||||||
v-if="timestamp"
|
v-if="currentTimestamp"
|
||||||
class="tui-passtime-label"
|
class="tui-passtime-label"
|
||||||
:class="{ underline }"
|
:class="{ underline }"
|
||||||
role="button"
|
role="button"
|
||||||
@@ -20,6 +20,7 @@ defineOptions({
|
|||||||
|
|
||||||
const props = withDefaults(defineProps<{
|
const props = withDefaults(defineProps<{
|
||||||
timestamp?: number;
|
timestamp?: number;
|
||||||
|
datetime?: string;
|
||||||
onlyTime?: boolean;
|
onlyTime?: boolean;
|
||||||
onlyDate?: boolean;
|
onlyDate?: boolean;
|
||||||
underline?: boolean;
|
underline?: boolean;
|
||||||
@@ -29,20 +30,27 @@ const props = withDefaults(defineProps<{
|
|||||||
underline: false
|
underline: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const { timestamp, onlyTime, onlyDate } = toRefs(props);
|
const { timestamp, datetime, onlyTime, onlyDate } = toRefs(props);
|
||||||
const showingDetail = ref(false);
|
const showingDetail = ref(false);
|
||||||
|
|
||||||
|
const currentTimestamp = computed(() => {
|
||||||
|
if (!datetime.value) {
|
||||||
|
return timestamp.value;
|
||||||
|
}
|
||||||
|
return new Date(datetime.value.replace(" ", "T")).getTime();
|
||||||
|
});
|
||||||
|
|
||||||
const content = computed(() => {
|
const content = computed(() => {
|
||||||
if (!showingDetail.value) {
|
if (!showingDetail.value) {
|
||||||
return Time.toPassedDateTime(timestamp.value);
|
return Time.toPassedDateTime(currentTimestamp.value);
|
||||||
}
|
}
|
||||||
if (onlyTime.value) {
|
if (onlyTime.value) {
|
||||||
return Time.toTime(timestamp.value);
|
return Time.toTime(currentTimestamp.value);
|
||||||
}
|
}
|
||||||
if (onlyDate.value) {
|
if (onlyDate.value) {
|
||||||
return Time.toDate(timestamp.value);
|
return Time.toDate(currentTimestamp.value);
|
||||||
}
|
}
|
||||||
return Time.toDateTime(timestamp.value);
|
return Time.toDateTime(currentTimestamp.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
function toggle(event: MouseEvent | KeyboardEvent): void {
|
function toggle(event: MouseEvent | KeyboardEvent): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user