feat(web): 提取共享基础组件 — dayjs/format/EntityName/FilterBar/PageContainer/DrawerForm

- utils/dayjs.ts: 集中初始化 relativeTime 插件 + zh-cn locale
- utils/format.ts: formatDate/formatDateTime/formatRelative/calcAge
- components/EntityName.tsx: UUID→姓名兜底显示
- components/FilterBar.tsx: 统一筛选栏容器
- components/PageContainer.tsx: 统一页面容器(标题+筛选+表格+暗色模式)
- components/DrawerForm.tsx: 抽屉式表单容器(分组+双列网格)
- AlertList.tsx: 迁移到集中 dayjs 导入
This commit is contained in:
iven
2026-04-28 01:45:48 +08:00
parent 16a776c213
commit 5b47f13ecf
7 changed files with 253 additions and 6 deletions

View File

@@ -0,0 +1,9 @@
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import 'dayjs/locale/zh-cn';
dayjs.extend(relativeTime);
dayjs.locale('zh-cn');
export { dayjs };
export default dayjs;

View File

@@ -0,0 +1,16 @@
import { dayjs } from './dayjs';
export const formatDate = (v: string | null | undefined): string =>
v ? dayjs(v).format('YYYY-MM-DD') : '--';
export const formatDateTime = (v: string | null | undefined): string =>
v ? dayjs(v).format('YYYY-MM-DD HH:mm') : '--';
export const formatRelative = (v: string | null | undefined): string =>
v ? dayjs(v).fromNow() : '--';
export const calcAge = (birthDate: string | null | undefined): string => {
if (!birthDate) return '--';
const age = dayjs().diff(dayjs(birthDate), 'year');
return `${age}`;
};