feat: 重构用户管理页面,集成 msw mock,统一路径别名和 API 命名规范

This commit is contained in:
2026-05-15 15:44:27 +08:00
parent 790b6905ef
commit 311ce55fb7
19 changed files with 1307 additions and 40 deletions

View File

@@ -0,0 +1,66 @@
import { Card, Col, Table, Tag } from 'antd';
import { useEffect, useState } from 'react';
import { listUser, type UserRecord } from '@/api/system/user';
/** 状态值与 Tag 颜色的映射 */
const statusColorMap: Record<string, string> = {
: 'success',
: 'error',
};
const columns = [
{ title: '用户名', dataIndex: 'username', key: 'username' },
{ title: '姓名', dataIndex: 'name', key: 'name' },
{ title: '邮箱', dataIndex: 'email', key: 'email' },
{
title: '状态',
dataIndex: 'status',
key: 'status',
render: (status: string) => (
<Tag color={statusColorMap[status] ?? 'default'}>{status}</Tag>
),
},
];
interface UserTableProps {
deptKey: string;
}
const UserTable = ({ deptKey }: UserTableProps) => {
const [loading, setLoading] = useState(false);
const [data, setData] = useState<UserRecord[]>([]);
useEffect(() => {
let cancelled = false;
const load = async () => {
setLoading(true);
try {
const res = await listUser(deptKey);
// 用 cancelled 标志位防止组件卸载后的竞态更新
if (!cancelled) setData(res.data ?? []);
} finally {
if (!cancelled) setLoading(false);
}
};
load();
return () => { cancelled = true; };
}, [deptKey]);
return (
<Col xs={24} sm={24} md={17} lg={18} xl={19} style={{ display: 'flex' }}>
<Card title="用户列表" style={{ width: '100%' }}>
<Table
columns={columns}
dataSource={data}
rowKey="username"
loading={loading}
pagination={{ pageSize: 10 }}
/>
</Card>
</Col>
);
};
export default UserTable;