From e290a9d51cfdcb5c35d239cde157be7cb7b663ae Mon Sep 17 00:00:00 2001 From: linfeng <2819853134@qq.com> Date: Wed, 19 Mar 2025 22:04:01 +0800 Subject: [PATCH] lin --- .../app/main/staffpage/stafftable/page.tsx | 80 +++++++++++++++---- 1 file changed, 66 insertions(+), 14 deletions(-) diff --git a/apps/web/src/app/main/staffpage/stafftable/page.tsx b/apps/web/src/app/main/staffpage/stafftable/page.tsx index 98fc853..61b27a5 100644 --- a/apps/web/src/app/main/staffpage/stafftable/page.tsx +++ b/apps/web/src/app/main/staffpage/stafftable/page.tsx @@ -10,6 +10,8 @@ import type { CascaderProps } from 'antd/es/cascader'; import { utils, writeFile } from 'xlsx'; import { Modal, Input, Button } from 'antd'; import { api } from '@nice/client'; +import { StaffDto } from 'packages/common/dist'; +import DepartmentSelect from '@web/src/components/models/department/department-select'; // 修改函数类型定义 @@ -42,31 +44,60 @@ export default function StaffTable() { const [fileNameVisible, setFileNameVisible] = useState(false); const [fileName, setFileName] = useState(''); const [defaultFileName] = useState(`员工数据_${new Date().toISOString().slice(0, 10)}`); + const [exporting, setExporting] = useState(false); + const [selectedDepartment, setSelectedDepartment] = useState(''); + const [tempExportData, setTempExportData] = useState(null); + const [exportScope, setExportScope] = useState<'current' | 'department'>('current'); const handleExport = async () => { setConfirmVisible(true); }; const handleConfirm = async () => { setConfirmVisible(false); + setExporting(true); + if (exportScope === 'current') { + setExporting(false); + try { + const allStaffs = await api.staff.findMany.useQuery({ + where: { + deletedAt: null, + department: { name: selectedDepartment } // 添加部门过滤条件 + }, + include: { department: true } + }); + + setTempExportData(allStaffs); + } finally { + setExporting(false); + } + } setFileNameVisible(true); + }; // 添加导出处理函数 const handleFileNameConfirm = () => { setFileNameVisible(false) + if (!tempExportData) return; + if (!gridApi) return; - + const finalFileName = fileName || defaultFileName; - + const flattenColumns = (cols: any[]): any[] => { - return cols.flatMap(col => + return cols.flatMap(col => col.children ? flattenColumns(col.children) : col ); }; - + const allColDefs = flattenColumns(gridApi.getColumnDefs()); - - const rowData = gridApi.getRenderedNodes().map((node: any) => { + let rowData; + if (exportScope === 'current') { + rowData = gridApi.getDisplayedRowNodes().map((node: any) => node.data) || []; + } else { + rowData = tempExportData || []; + } + rowData.map((node: any) => { const row: Record = {}; allColDefs.forEach((colDef: any) => { const field = colDef.field; @@ -74,7 +105,7 @@ export default function StaffTable() { const value = node.data[field]; const formatter = colDef.valueFormatter; const renderer = colDef.cellRenderer; - + let renderedValue = value; if (formatter) { renderedValue = formatter({ value }); @@ -90,14 +121,14 @@ export default function StaffTable() { renderedValue = html.replace(//gi, '\n'); } } - + // 增强布尔值处理逻辑 - if (typeof renderedValue === 'boolean' || - (typeof renderedValue === 'string' && ['true','false'].includes(renderedValue.toLowerCase()))) { + if (typeof renderedValue === 'boolean' || + (typeof renderedValue === 'string' && ['true', 'false'].includes(renderedValue.toLowerCase()))) { const boolValue = typeof renderedValue === 'boolean' ? renderedValue : renderedValue.toLowerCase() === 'true'; renderedValue = boolValue ? '是' : '否'; } - + row[colDef.headerName] = renderedValue; } }); @@ -313,7 +344,7 @@ export default function StaffTable() { }} > {!isLoading && ( -