refactor time-label
This commit is contained in:
@@ -86,11 +86,11 @@ export const COMPONENT_LIST: ComponentMeta[] = [
|
|||||||
entry: "src/components/description-grid/index.vue"
|
entry: "src/components/description-grid/index.vue"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "PassTimeLabel",
|
name: "TimeLabel",
|
||||||
title: "PassTimeLabel 时间标签",
|
title: "TimeLabel 时间标签",
|
||||||
description: "把时间戳显示为「多久以前」,点击可切换为完整日期时间。",
|
description: "把时间戳显示为过去或未来的相对时间,点击可切换为完整日期时间。",
|
||||||
category: "数据展示",
|
category: "数据展示",
|
||||||
entry: "src/components/passtime-label/index.vue"
|
entry: "src/components/time-label/index.vue"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ContactNumber",
|
name: "ContactNumber",
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
| --- | --- |
|
| --- | --- |
|
||||||
| [AnimatedNumber](/components/animated-number) | 数值变化时按缓动函数滚动过渡,支持小数位与千分位。 |
|
| [AnimatedNumber](/components/animated-number) | 数值变化时按缓动函数滚动过渡,支持小数位与千分位。 |
|
||||||
| [DescriptionGrid](/components/description-grid) | 键值对描述列表,可指定列数、对齐方式与逐项具名插槽。 |
|
| [DescriptionGrid](/components/description-grid) | 键值对描述列表,可指定列数、对齐方式与逐项具名插槽。 |
|
||||||
| [PassTimeLabel](/components/passtime-label) | 把时间戳显示为「多久以前」,点击可切换为完整日期时间。 |
|
| [TimeLabel](/components/time-label) | 把时间戳显示为过去或未来的相对时间,点击可切换为完整日期时间。 |
|
||||||
| [ContactNumber](/components/contact-number) | 按号段分组的电话号码展示,可点击拨号并支持前置图标。 |
|
| [ContactNumber](/components/contact-number) | 按号段分组的电话号码展示,可点击拨号并支持前置图标。 |
|
||||||
|
|
||||||
## 内容与浮层
|
## 内容与浮层
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
# PassTimeLabel 时间标签
|
|
||||||
|
|
||||||
接收时间戳或 `yyyy-MM-dd HH:mm:ss`、`yyyy-MM-ddTHH:mm:ss` 格式的日期时间字符串,显示为「多久以前」,点击可切换为完整日期时间。
|
|
||||||
|
|
||||||
## 基础用法
|
|
||||||
|
|
||||||
:::preview 基础用法 || 点击标签在相对时间与完整时间之间切换
|
|
||||||
|
|
||||||
demo-preview=../demos/passtime-label/basic.vue
|
|
||||||
|
|
||||||
:::
|
|
||||||
|
|
||||||
## 何时使用
|
|
||||||
|
|
||||||
动态列表、评论、消息流里的时间展示。用户往往更关心「多久之前」,需要精确时间时点一下即可。
|
|
||||||
|
|
||||||
## 交互与可访问性
|
|
||||||
|
|
||||||
标签带 `role="button"` 与 `tabindex="0"`,支持键盘回车与空格触发切换,因此可以安全地放在列表项里。
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
<api-table name="PassTimeLabel" />
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
# TimeLabel 时间标签
|
||||||
|
|
||||||
|
接收时间戳或 `yyyy-MM-dd HH:mm:ss`、`yyyy-MM-ddTHH:mm:ss` 格式的日期时间字符串,自动显示过去或未来的相对时间;超过 3 天时显示具体日期时间。点击可切换为完整日期时间。
|
||||||
|
|
||||||
|
## 基础用法
|
||||||
|
|
||||||
|
:::preview 基础用法 || 点击标签在相对时间与完整时间之间切换
|
||||||
|
|
||||||
|
demo-preview=../demos/time-label/basic.vue
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
## 何时使用
|
||||||
|
|
||||||
|
动态列表、评论、消息流里的时间展示。用户通常关心时间间隔,需要精确时间时点一下即可。
|
||||||
|
|
||||||
|
## 交互与可访问性
|
||||||
|
|
||||||
|
标签带 `role="button"` 与 `tabindex="0"`,支持键盘回车与空格触发切换,因此可以安全地放在列表项里。
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
<api-table name="TimeLabel" />
|
||||||
@@ -2,28 +2,33 @@
|
|||||||
<div class="demo">
|
<div class="demo">
|
||||||
<div v-for="item in timeList" :key="item.offset" class="row">
|
<div v-for="item in timeList" :key="item.offset" class="row">
|
||||||
<span class="label" v-text="item.label" />
|
<span class="label" v-text="item.label" />
|
||||||
<pass-time-label :timestamp="item.timestamp" underline />
|
<TimeLabel :timestamp="item.timestamp" underline />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<span class="label" v-text="'仅时间 / 仅日期'" />
|
<span class="label" v-text="'仅时间 / 仅日期'" />
|
||||||
<pass-time-label :timestamp="now" only-time underline />
|
<TimeLabel :timestamp="now" only-time underline />
|
||||||
<pass-time-label :timestamp="now" only-date underline />
|
<TimeLabel :timestamp="now" only-date underline />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { PassTimeLabel } from "timi-web";
|
import { TimeLabel } from "timi-web";
|
||||||
|
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
/** 点击标签可在「多久以前」与完整时间之间切换。 */
|
/** 点击标签可在相对时间与完整时间之间切换。 */
|
||||||
const timeList = [
|
const timeList = [
|
||||||
{ offset: 30_000, label: "30 秒前" },
|
{ offset: 30_000, label: "30 秒前" },
|
||||||
{ offset: 30 * 60_000, label: "30 分钟前" },
|
{ offset: 30 * 60_000, label: "30 分钟前" },
|
||||||
{ offset: 5 * 3600_000, label: "5 小时前" },
|
{ offset: 5 * 3600_000, label: "5 小时前" },
|
||||||
{ offset: 3 * 86400_000, label: "3 天前" }
|
{ offset: 3 * 86400_000, label: "3 天前" },
|
||||||
|
{ offset: -30_000, label: "30 秒后" },
|
||||||
|
{ offset: -30 * 60_000, label: "30 分钟后" },
|
||||||
|
{ offset: -5 * 3600_000, label: "5 小时后" },
|
||||||
|
{ offset: -2 * 86400_000, label: "2 天后" },
|
||||||
|
{ offset: -4 * 86400_000, label: "4 天后" }
|
||||||
].map(item => ({
|
].map(item => ({
|
||||||
...item,
|
...item,
|
||||||
timestamp: now - item.offset
|
timestamp: now - item.offset
|
||||||
@@ -9,5 +9,4 @@ CenterTips.install = (app: App) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** 兼容旧组件名。 */
|
/** 兼容旧组件名。 */
|
||||||
export const EmptyTips = CenterTips;
|
|
||||||
export default CenterTips;
|
export default CenterTips;
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import HoverPopup, { VPopupComponent } from "./v-popup";
|
|||||||
import Captcha from "./captcha";
|
import Captcha from "./captcha";
|
||||||
import Loading from "./loading";
|
import Loading from "./loading";
|
||||||
import Copyright from "./copyright";
|
import Copyright from "./copyright";
|
||||||
import CenterTips, { EmptyTips } from "./center-tips";
|
import CenterTips from "./center-tips";
|
||||||
import MarkdownView from "./markdown-view";
|
import MarkdownView from "./markdown-view";
|
||||||
import BEFlowerFall from "./background-effect/flower-fall";
|
import BEFlowerFall from "./background-effect/flower-fall";
|
||||||
import MarkdownEditor from "./markdown-editor";
|
import MarkdownEditor from "./markdown-editor";
|
||||||
import PassTimeLabel from "./passtime-label";
|
import TimeLabel from "./time-label";
|
||||||
import ContactNumber from "./contact-number";
|
import ContactNumber from "./contact-number";
|
||||||
import AnimatedNumber from "./animated-number";
|
import AnimatedNumber from "./animated-number";
|
||||||
import AnimatedAmount from "./animated-amount";
|
import AnimatedAmount from "./animated-amount";
|
||||||
@@ -26,7 +26,7 @@ export default [
|
|||||||
MarkdownView,
|
MarkdownView,
|
||||||
BEFlowerFall,
|
BEFlowerFall,
|
||||||
MarkdownEditor,
|
MarkdownEditor,
|
||||||
PassTimeLabel,
|
TimeLabel,
|
||||||
ContactNumber,
|
ContactNumber,
|
||||||
AnimatedNumber,
|
AnimatedNumber,
|
||||||
AnimatedAmount,
|
AnimatedAmount,
|
||||||
@@ -42,11 +42,10 @@ export {
|
|||||||
Loading,
|
Loading,
|
||||||
Copyright,
|
Copyright,
|
||||||
CenterTips,
|
CenterTips,
|
||||||
EmptyTips,
|
|
||||||
MarkdownView,
|
MarkdownView,
|
||||||
BEFlowerFall,
|
BEFlowerFall,
|
||||||
MarkdownEditor,
|
MarkdownEditor,
|
||||||
PassTimeLabel,
|
TimeLabel,
|
||||||
ContactNumber,
|
ContactNumber,
|
||||||
AnimatedNumber,
|
AnimatedNumber,
|
||||||
AnimatedAmount,
|
AnimatedAmount,
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
import view from "./index.vue";
|
|
||||||
import WebToolkit from "../../utils/WebToolkit";
|
|
||||||
|
|
||||||
export const PassTimeLabel = WebToolkit.withInstall(view);
|
|
||||||
export default PassTimeLabel;
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import view from "./index.vue";
|
||||||
|
import WebToolkit from "../../utils/WebToolkit";
|
||||||
|
|
||||||
|
export const TimeLabel = WebToolkit.withInstall(view);
|
||||||
|
export default TimeLabel;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<span
|
<span
|
||||||
v-if="currentTimestamp"
|
v-if="currentTimestamp"
|
||||||
class="tui-passtime-label"
|
class="tui-time-label"
|
||||||
:class="{ underline }"
|
:class="{ underline }"
|
||||||
role="button"
|
role="button"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
import { Time } from "timi-ts";
|
import { Time } from "timi-ts";
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: "PassTimeLabel"
|
name: "TimeLabel"
|
||||||
});
|
});
|
||||||
|
|
||||||
const props = withDefaults(defineProps<{
|
const props = withDefaults(defineProps<{
|
||||||
@@ -42,7 +42,7 @@ const currentTimestamp = computed(() => {
|
|||||||
|
|
||||||
const content = computed(() => {
|
const content = computed(() => {
|
||||||
if (!showingDetail.value) {
|
if (!showingDetail.value) {
|
||||||
return Time.toPassedDateTime(currentTimestamp.value);
|
return Time.formatDateTime(currentTimestamp.value);
|
||||||
}
|
}
|
||||||
if (onlyTime.value) {
|
if (onlyTime.value) {
|
||||||
return Time.toTime(currentTimestamp.value);
|
return Time.toTime(currentTimestamp.value);
|
||||||
@@ -61,7 +61,7 @@ function toggle(event: MouseEvent | KeyboardEvent): void {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
.tui-passtime-label {
|
.tui-time-label {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
&.underline {
|
&.underline {
|
||||||
Reference in New Issue
Block a user