import { Button, Select, Table, Modal } from "antd" import { StaffDto } from "@nice/common"; import { useStaff, api } from "@nice/client"; import { useEffect, useState } from "react"; import toast from "react-hot-toast"; import React from "react"; import { useMainContext } from "../../layout/MainProvider"; import { render } from "react-dom"; // 提取处理嵌套字段的函数 const getNestedValue = (record: any, dataIndex: string | string[]) => { if (Array.isArray(dataIndex)) { return dataIndex.reduce((obj, key) => obj?.[key], record); } return record[dataIndex]; }; export default function StaffTable() { const{form, setVisible,searchValue} = useMainContext() const { data: staffs, isLoading } = api.staff.findMany.useQuery({ where: { deletedAt: null, username: { contains: searchValue } }, include: { department: true, position: true, trainSituations: { include: { trainContent: { select: { id: true, title: true } } } } } }); useEffect(() => { console.log(staffs); }, [staffs]); const { softDeleteByIds } = useStaff(); const {editingRecord, setEditingRecord} = useMainContext(); const [isTrainingModalVisible, setIsTrainingModalVisible] = useState(false); const [selectedTrainings, setSelectedTrainings] = useState([]); const showTrainingDetails = (situations) => { setSelectedTrainings(situations); setIsTrainingModalVisible(true); }; // 修正拼写错误 const columns = [ { title: "姓名", dataIndex: "username", key: "username", }, { title: "部门", dataIndex: ["department", "name"], key: "deptId", render: (_, record) => record.department?.name || "无部门" }, { title: "职务", dataIndex: ["position", "type"], key: "position", render: (_, record) => record.position?.type || "无职务" }, { title: "在位", dataIndex: "absent", key: "absent", render: (absent) => absent === null ? "未知" : absent ? "否" : "是" }, { title: "培训情况", dataIndex: "trainSituations", key: "trainSituations", render: (situations) => { if (!situations?.length) return "无培训记录"; return (
{column.title} | ))}
---|
{column.render?.( getNestedValue(record, column.dataIndex), record ) || getNestedValue(record, column.dataIndex)} | ))}