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