add
This commit is contained in:
parent
4fa3c20664
commit
f3cc347a8e
|
@ -77,6 +77,14 @@ const DeviceTable = forwardRef(({ onSelectedChange }: DeviceTableProps, ref) =>
|
|||
}, [devices]);
|
||||
// const { softDeleteByIds } = useStaff()
|
||||
|
||||
// 添加部门数据查询
|
||||
const { data: departments } = api.department.findMany.useQuery({
|
||||
where: {
|
||||
deletedAt: null,
|
||||
}
|
||||
}, {
|
||||
enabled: true, // 确保此查询被执行
|
||||
});
|
||||
|
||||
const getTermNameById = (termId, termType) => {
|
||||
if (!termId) return "未知";
|
||||
|
@ -138,7 +146,16 @@ const DeviceTable = forwardRef(({ onSelectedChange }: DeviceTableProps, ref) =>
|
|||
key: "deptId",
|
||||
align: "center",
|
||||
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 unitName = row['单位'] ? String(row['单位']) : "";
|
||||
return {
|
||||
systemType: findTermIdByName(row['网系类别'], 'system_type'),
|
||||
deviceType: findTermIdByName(row['故障类型'], 'device_type'),
|
||||
showname: row['故障名称'] ? String(row['故障名称']) : "",
|
||||
deptId: findDeptIdByName(row['单位']),
|
||||
// 尝试关联部门ID
|
||||
deptId: unitName ? findDeptIdByName(unitName) : null,
|
||||
// 同时保存原始单位名称
|
||||
responsiblePerson: unitName,
|
||||
deviceStatus: getStatusKeyByValue(row['故障状态']),
|
||||
notes: row['描述'] ? String(row['描述']) : ""
|
||||
};
|
||||
|
@ -325,11 +345,17 @@ const DeviceTable = forwardRef(({ onSelectedChange }: DeviceTableProps, ref) =>
|
|||
return term?.id || null;
|
||||
};
|
||||
|
||||
// 修改查找部门ID函数,从设备数据中获取部门信息
|
||||
// 改进查找部门ID函数
|
||||
const findDeptIdByName = (name: string) => {
|
||||
if (!name || name === "未知") return null;
|
||||
|
||||
// 从已有设备数据中查找匹配的部门名称和ID
|
||||
// 直接从部门数据中查找
|
||||
const department = departments?.find(dept => dept.name === name);
|
||||
if (department) {
|
||||
return department.id;
|
||||
}
|
||||
|
||||
// 备用:尝试从设备中查找
|
||||
const matchedDevice = devices?.find(device =>
|
||||
(device as any)?.department?.name === name
|
||||
);
|
||||
|
@ -514,8 +540,14 @@ const DeviceTable = forwardRef(({ onSelectedChange }: DeviceTableProps, ref) =>
|
|||
size="middle"
|
||||
tableLayout="fixed"
|
||||
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={() => {
|
||||
return {
|
||||
style: {
|
||||
|
|
|
@ -140,68 +140,50 @@ export default function DeviceMessage() {
|
|||
};
|
||||
|
||||
return (
|
||||
<div className="p-2 min-h-screen bg-gradient-to-br">
|
||||
<div className="pl-4 pr-4 pt-2 text-2xl flex items-center justify-between">
|
||||
<span>故障收录检索</span>
|
||||
<div className="flex space-x-2">
|
||||
<div className="p-2 min-h-screen bg-white">
|
||||
<div className="flex justify-between items-center mb-4">
|
||||
<h1 className="text-xl font-normal">故障收录检索</h1>
|
||||
<Button type="primary" icon={<PlusOutlined />} onClick={handleNew}>
|
||||
新建
|
||||
</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">
|
||||
<div className="flex flex-wrap items-center gap-2 mb-4">
|
||||
<div className="flex-1 min-w-[200px]">
|
||||
<SystemTypeSelect
|
||||
value={selectedSystem}
|
||||
onChange={setSelectedSystem}
|
||||
className="w-1/5"
|
||||
placeholder="选择网系类别"
|
||||
className="w-full"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex-1 min-w-[200px]">
|
||||
<DeviceTypeSelect
|
||||
value={selectedDeviceType}
|
||||
onChange={setSelectedDeviceType}
|
||||
className="w-1/5"
|
||||
placeholder="选择故障类型"
|
||||
className="w-full"
|
||||
systemTypeId={selectedSystemTypeId}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex-1 min-w-[200px]">
|
||||
<DepartmentSelect
|
||||
placeholder="单位"
|
||||
className="w-1/5"
|
||||
className="w-full"
|
||||
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
|
||||
/> */}
|
||||
</div>
|
||||
<div className="flex-1 min-w-[200px]">
|
||||
<DatePicker
|
||||
placeholder="选择日期"
|
||||
className="w-1/5"
|
||||
className="w-full"
|
||||
value={time ? dayjs(time) : null}
|
||||
onChange={(date, dateString) => setTime(dateString as string)}
|
||||
format="YYYY-MM-DD"
|
||||
allowClear
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 右侧按钮区域 */}
|
||||
<div className="flex flex-row justify-between ml-4 space-x-2">
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<SearchOutlined />}
|
||||
|
@ -209,23 +191,27 @@ export default function DeviceMessage() {
|
|||
>
|
||||
查询
|
||||
</Button>
|
||||
<Button icon={<ReloadOutlined />} onClick={handleReset}>
|
||||
<Button
|
||||
icon={<ReloadOutlined />}
|
||||
onClick={handleReset}
|
||||
>
|
||||
重置
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 overflow-auto justify-between">
|
||||
{/* <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}
|
||||
></DeviceTable>
|
||||
<DeviceModal></DeviceModal>
|
||||
/>
|
||||
<DeviceModal />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -51,14 +51,15 @@ export const routes: CustomRouteObject[] = [
|
|||
path: "/admin",
|
||||
element: <WithAuth><AdminLayout></AdminLayout></WithAuth>,
|
||||
children: adminRoute.children,
|
||||
}
|
||||
],
|
||||
},]
|
||||
},
|
||||
{
|
||||
path: "/dashboard",
|
||||
element: <WithAuth><DashboardPage/></WithAuth>,
|
||||
},
|
||||
],
|
||||
},]
|
||||
},
|
||||
|
||||
{
|
||||
path: "/login",
|
||||
breadcrumb: "登录",
|
||||
|
|
Loading…
Reference in New Issue