feat: Add base project structure with API and web components

This commit is contained in:
Ke Sun
2025-12-02 20:28:01 +08:00
parent f3de6d6cc9
commit c1adc62ec6
817 changed files with 111226 additions and 106 deletions

32
web/src/utils/format.ts Normal file
View File

@@ -0,0 +1,32 @@
/**
* 格式化日期时间
* @param value 时间戳(毫秒)或日期字符串
* @param format 目标格式,支持 YYYY-MM-DD HH:mm:ss、YYYY/MM/DD HH:mm:ss、HH:mm 等
* @returns 格式化后的日期时间字符串
*/
import dayjs from 'dayjs';
import timezone from 'dayjs/plugin/timezone';
import utc from 'dayjs/plugin/utc';
// 扩展dayjs插件
dayjs.extend(utc);
dayjs.extend(timezone);
export const formatDateTime = (
value: string | number | null | undefined,
format: string = 'YYYY-MM-DD HH:mm:ss'
): string => {
if (!value) return '';
// 检查日期是否有效
if (!dayjs(value).isValid()) {
return '';
}
// 每次调用都获取最新的时区设置
const currentTimeZone = localStorage.getItem('timeZone') || 'Asia/Shanghai';
dayjs.tz.setDefault(currentTimeZone);
// 使用最新时区格式化日期
return dayjs.tz(value).format(format);
};