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:
9
apps/web/src/utils/dayjs.ts
Normal file
9
apps/web/src/utils/dayjs.ts
Normal 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;
|
||||
16
apps/web/src/utils/format.ts
Normal file
16
apps/web/src/utils/format.ts
Normal 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}岁`;
|
||||
};
|
||||
Reference in New Issue
Block a user