From 35cb9c750cc7d9e952dfd24e5dc5cad3c9b672b8 Mon Sep 17 00:00:00 2001 From: ZLY Date: Wed, 20 Aug 2025 17:08:17 +0800 Subject: [PATCH] =?UTF-8?q?feat(utils):=20=E6=B7=BB=E5=8A=A0=E9=80=9A?= =?UTF-8?q?=E7=94=A8=E6=A0=BC=E5=BC=8F=E5=8C=96=E5=B7=A5=E5=85=B7=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增格式化实例类型和状态的函数 - 实现时间戳格式化函数 - 为项目提供统一的格式化处理工具 --- src/utils/common.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/utils/common.ts diff --git a/src/utils/common.ts b/src/utils/common.ts new file mode 100644 index 0000000..b1b2c7b --- /dev/null +++ b/src/utils/common.ts @@ -0,0 +1,42 @@ +import dayjs from 'dayjs'; + +// 格式化实例类型 +export function formatInstanceType(value: string): string { + switch (value) { + case 'MANUAL': + return '运行应用'; + default: + return value; + } +} + +export function formatInstanceStatus(value: string): string { + switch (value) { + case 'RUNNING': + return '运行中'; + case 'STOPPED': + return '已停止'; + case 'STARTING': + return '启动中'; + case 'STOPPING': + return '停止中'; + case 'DELETING': + return '删除中'; + case 'DELETED': + return '已删除'; + case 'FAILED': + return '失败'; + default: + return value; + } +} + +//格式化时间戳 +export function formatTimestamp(timestamp: number): string { + // 判断时间戳是秒级还是毫秒级 + const isMillisecond = timestamp.toString().length >= 13; + + const millisecondTimestamp = isMillisecond ? timestamp : timestamp * 1000; + + return dayjs(millisecondTimestamp).format('YYYY-MM-DD HH:mm:ss'); +} \ No newline at end of file