This commit is contained in:
Your Name 2025-05-20 15:37:08 +08:00
parent 4fa3c20664
commit f3cc347a8e
3 changed files with 115 additions and 96 deletions

View File

@ -77,6 +77,14 @@ const DeviceTable = forwardRef(({ onSelectedChange }: DeviceTableProps, ref) =>
}, [devices]); }, [devices]);
// const { softDeleteByIds } = useStaff() // const { softDeleteByIds } = useStaff()
// 添加部门数据查询
const { data: departments } = api.department.findMany.useQuery({
where: {
deletedAt: null,
}
}, {
enabled: true, // 确保此查询被执行
});
const getTermNameById = (termId, termType) => { const getTermNameById = (termId, termType) => {
if (!termId) return "未知"; if (!termId) return "未知";
@ -138,7 +146,16 @@ const DeviceTable = forwardRef(({ onSelectedChange }: DeviceTableProps, ref) =>
key: "deptId", key: "deptId",
align: "center", align: "center",
render: (text, record) => { render: (text, record) => {
return (record as any)?.department?.name || "未知"; // 如果有部门关联,显示部门名称
if (record.deptId && (record as any)?.department?.name) {
return (record as any)?.department?.name;
}
// 否则显示responsiblePerson如果存在
if (record.responsiblePerson) {
return record.responsiblePerson;
}
// 最后才显示未知
return "未知";
}, },
}, },
{ {
@ -289,12 +306,15 @@ const DeviceTable = forwardRef(({ onSelectedChange }: DeviceTableProps, ref) =>
// 转换为符合系统格式的数据 // 转换为符合系统格式的数据
const records = jsonData.map((row: any) => { const records = jsonData.map((row: any) => {
// 转换字段名和值映射 const unitName = row['单位'] ? String(row['单位']) : "";
return { return {
systemType: findTermIdByName(row['网系类别'], 'system_type'), systemType: findTermIdByName(row['网系类别'], 'system_type'),
deviceType: findTermIdByName(row['故障类型'], 'device_type'), deviceType: findTermIdByName(row['故障类型'], 'device_type'),
showname: row['故障名称'] ? String(row['故障名称']) : "", showname: row['故障名称'] ? String(row['故障名称']) : "",
deptId: findDeptIdByName(row['单位']), // 尝试关联部门ID
deptId: unitName ? findDeptIdByName(unitName) : null,
// 同时保存原始单位名称
responsiblePerson: unitName,
deviceStatus: getStatusKeyByValue(row['故障状态']), deviceStatus: getStatusKeyByValue(row['故障状态']),
notes: row['描述'] ? String(row['描述']) : "" notes: row['描述'] ? String(row['描述']) : ""
}; };
@ -302,7 +322,7 @@ const DeviceTable = forwardRef(({ onSelectedChange }: DeviceTableProps, ref) =>
// 确认是否有有效数据 // 确认是否有有效数据
if (records.length === 0) { if (records.length === 0) {
toast.error("未找到有效数据"); toast.error("未找到有效数据");
return; return;
} }
// 批量创建记录 // 批量创建记录
await batchImportRecords(records); await batchImportRecords(records);
@ -325,11 +345,17 @@ const DeviceTable = forwardRef(({ onSelectedChange }: DeviceTableProps, ref) =>
return term?.id || null; return term?.id || null;
}; };
// 改查找部门ID函数,从设备数据中获取部门信息 // 查找部门ID函数
const findDeptIdByName = (name: string) => { const findDeptIdByName = (name: string) => {
if (!name || name === "未知") return null; if (!name || name === "未知") return null;
// 从已有设备数据中查找匹配的部门名称和ID // 直接从部门数据中查找
const department = departments?.find(dept => dept.name === name);
if (department) {
return department.id;
}
// 备用:尝试从设备中查找
const matchedDevice = devices?.find(device => const matchedDevice = devices?.find(device =>
(device as any)?.department?.name === name (device as any)?.department?.name === name
); );
@ -457,7 +483,7 @@ const DeviceTable = forwardRef(({ onSelectedChange }: DeviceTableProps, ref) =>
onChange={(e) => { onChange={(e) => {
const checked = e.target.checked; const checked = e.target.checked;
const newSelectedRowKeys = checked ? (devices || []).map(item => item.id) : []; const newSelectedRowKeys = checked ? (devices || []).map(item => item.id) : [];
onSelectChange(newSelectedRowKeys, checked ? devices: []); onSelectChange(newSelectedRowKeys, checked ? devices : []);
}} }}
/> />
<span className="ml-1.5 text-xs whitespace-nowrap"></span> <span className="ml-1.5 text-xs whitespace-nowrap"></span>
@ -514,8 +540,14 @@ const DeviceTable = forwardRef(({ onSelectedChange }: DeviceTableProps, ref) =>
size="middle" size="middle"
tableLayout="fixed" tableLayout="fixed"
rowClassName={(record, index) => rowClassName={(record, index) =>
index % 2 === 0 ? "bg-white" : "bg-gray-100" index % 2 === 0 ? "bg-white hover:bg-blue-100" : "bg-gray-100 hover:bg-blue-100"
} }
onRow={(record) => {
return {
style: { cursor: 'pointer' },
onMouseEnter: () => { }, // 触发悬停效果
};
}}
onHeaderRow={() => { onHeaderRow={() => {
return { return {
style: { style: {

View File

@ -140,92 +140,78 @@ export default function DeviceMessage() {
}; };
return ( return (
<div className="p-2 min-h-screen bg-gradient-to-br"> <div className="p-2 min-h-screen bg-white">
<div className="pl-4 pr-4 pt-2 text-2xl flex items-center justify-between"> <div className="flex justify-between items-center mb-4">
<span></span> <h1 className="text-xl font-normal"></h1>
<div className="flex space-x-2"> <Button type="primary" icon={<PlusOutlined />} onClick={handleNew}>
<Button type="primary" icon={<PlusOutlined />} onClick={handleNew}>
</Button>
</Button>
</div>
</div> </div>
<Form>
<div className="p-2 h-full flex">
<div className="max-w-full mx-auto flex-1 flex flex-col">
{/* 搜索区域 - 分为左右两块布局 */}
<div className="mb-2">
<div className="flex w-full">
{/* 左侧搜索框区域 */}
<div className="flex-1 flex flex-col space-y-3">
{/* 第一行搜索框 - 始终显示 */}
<div className="flex w-full space-x-3">
<SystemTypeSelect
value={selectedSystem}
onChange={setSelectedSystem}
className="w-1/5"
/>
<DeviceTypeSelect
value={selectedDeviceType}
onChange={setSelectedDeviceType}
className="w-1/5"
systemTypeId={selectedSystemTypeId}
/>
<DepartmentSelect
placeholder="单位"
className="w-1/5"
value={selectedDept}
onChange={handleDeptChange}
/>
{/* <Select
placeholder="状态"
className="w-1/5"
options={[
{ label: "正常", value: "normal" },
{ label: "故障", value: "fault" },
{ label: "维修", value: "repair" },
]}
value={status}
onChange={setStatus}
allowClear
/> */}
<DatePicker
placeholder="选择日期"
className="w-1/5"
value={time ? dayjs(time) : null}
onChange={(date, dateString) => setTime(dateString as string)}
format="YYYY-MM-DD"
allowClear
/>
</div>
</div>
{/* 右侧按钮区域 */} <div className="flex flex-wrap items-center gap-2 mb-4">
<div className="flex flex-row justify-between ml-4 space-x-2"> <div className="flex-1 min-w-[200px]">
<Button <SystemTypeSelect
type="primary" value={selectedSystem}
icon={<SearchOutlined />} onChange={setSelectedSystem}
onClick={handleSearch} placeholder="选择网系类别"
> className="w-full"
/>
</Button>
<Button icon={<ReloadOutlined />} onClick={handleReset}>
</Button>
</div>
</div>
</div>
<div className="flex-1 overflow-auto justify-between">
<DeviceTable
ref={tableRef}
onSelectedChange={handleSelectedChange}
></DeviceTable>
<DeviceModal></DeviceModal>
</div>
</div>
</div> </div>
</Form> <div className="flex-1 min-w-[200px]">
<DeviceTypeSelect
value={selectedDeviceType}
onChange={setSelectedDeviceType}
placeholder="选择故障类型"
className="w-full"
systemTypeId={selectedSystemTypeId}
/>
</div>
<div className="flex-1 min-w-[200px]">
<DepartmentSelect
placeholder="单位"
className="w-full"
value={selectedDept}
onChange={handleDeptChange}
/>
</div>
<div className="flex-1 min-w-[200px]">
<DatePicker
placeholder="选择日期"
className="w-full"
value={time ? dayjs(time) : null}
onChange={(date, dateString) => setTime(dateString as string)}
format="YYYY-MM-DD"
allowClear
/>
</div>
<Button
type="primary"
icon={<SearchOutlined />}
onClick={handleSearch}
>
</Button>
<Button
icon={<ReloadOutlined />}
onClick={handleReset}
>
</Button>
</div>
{/* <div className="flex justify-end gap-2 mb-4 border-b pb-2">
<Button icon={<ExportOutlined />}></Button>
<Button icon={<ImportOutlined />}></Button>
<Button icon={<ExportOutlined />}></Button>
</div> */}
<div>
<DeviceTable
ref={tableRef}
onSelectedChange={handleSelectedChange}
/>
<DeviceModal />
</div>
</div> </div>
); );
} }

View File

@ -51,14 +51,15 @@ export const routes: CustomRouteObject[] = [
path: "/admin", path: "/admin",
element: <WithAuth><AdminLayout></AdminLayout></WithAuth>, element: <WithAuth><AdminLayout></AdminLayout></WithAuth>,
children: adminRoute.children, children: adminRoute.children,
} },
{
path: "/dashboard",
element: <WithAuth><DashboardPage/></WithAuth>,
},
], ],
},] },]
}, },
{
path: "/dashboard",
element: <WithAuth><DashboardPage/></WithAuth>,
},
{ {
path: "/login", path: "/login",
breadcrumb: "登录", breadcrumb: "登录",