feat(utils): 添加通用格式化工具函数

- 新增格式化实例类型和状态的函数
- 实现时间戳格式化函数
- 为项目提供统一的格式化处理工具
master
钟良源 6 months ago
parent 735387fa31
commit 35cb9c750c

@ -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');
}
Loading…
Cancel
Save