This commit is contained in:
linfeng 2025-03-19 22:04:01 +08:00
parent e186c77f61
commit e290a9d51c
1 changed files with 66 additions and 14 deletions

View File

@ -10,6 +10,8 @@ import type { CascaderProps } from 'antd/es/cascader';
import { utils, writeFile } from 'xlsx'; import { utils, writeFile } from 'xlsx';
import { Modal, Input, Button } from 'antd'; import { Modal, Input, Button } from 'antd';
import { api } from '@nice/client'; import { api } from '@nice/client';
import { StaffDto } from 'packages/common/dist';
import DepartmentSelect from '@web/src/components/models/department/department-select';
// 修改函数类型定义 // 修改函数类型定义
@ -42,18 +44,42 @@ export default function StaffTable() {
const [fileNameVisible, setFileNameVisible] = useState(false); const [fileNameVisible, setFileNameVisible] = useState(false);
const [fileName, setFileName] = useState(''); const [fileName, setFileName] = useState('');
const [defaultFileName] = useState(`员工数据_${new Date().toISOString().slice(0, 10)}`); const [defaultFileName] = useState(`员工数据_${new Date().toISOString().slice(0, 10)}`);
const [exporting, setExporting] = useState(false);
const [selectedDepartment, setSelectedDepartment] = useState('');
const [tempExportData, setTempExportData] = useState<any | null>(null);
const [exportScope, setExportScope] = useState<'current' | 'department'>('current');
const handleExport = async () => { const handleExport = async () => {
setConfirmVisible(true); setConfirmVisible(true);
}; };
const handleConfirm = async () => { const handleConfirm = async () => {
setConfirmVisible(false); 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); setFileNameVisible(true);
}; };
// 添加导出处理函数 // 添加导出处理函数
const handleFileNameConfirm = () => { const handleFileNameConfirm = () => {
setFileNameVisible(false) setFileNameVisible(false)
if (!tempExportData) return;
if (!gridApi) return; if (!gridApi) return;
const finalFileName = fileName || defaultFileName; const finalFileName = fileName || defaultFileName;
@ -65,8 +91,13 @@ export default function StaffTable() {
}; };
const allColDefs = flattenColumns(gridApi.getColumnDefs()); const allColDefs = flattenColumns(gridApi.getColumnDefs());
let rowData;
const rowData = gridApi.getRenderedNodes().map((node: any) => { if (exportScope === 'current') {
rowData = gridApi.getDisplayedRowNodes().map((node: any) => node.data) || [];
} else {
rowData = tempExportData || [];
}
rowData.map((node: any) => {
const row: Record<string, any> = {}; const row: Record<string, any> = {};
allColDefs.forEach((colDef: any) => { allColDefs.forEach((colDef: any) => {
const field = colDef.field; const field = colDef.field;
@ -93,7 +124,7 @@ export default function StaffTable() {
// 增强布尔值处理逻辑 // 增强布尔值处理逻辑
if (typeof renderedValue === 'boolean' || if (typeof renderedValue === 'boolean' ||
(typeof renderedValue === 'string' && ['true','false'].includes(renderedValue.toLowerCase()))) { (typeof renderedValue === 'string' && ['true', 'false'].includes(renderedValue.toLowerCase()))) {
const boolValue = typeof renderedValue === 'boolean' ? renderedValue : renderedValue.toLowerCase() === 'true'; const boolValue = typeof renderedValue === 'boolean' ? renderedValue : renderedValue.toLowerCase() === 'true';
renderedValue = boolValue ? '是' : '否'; renderedValue = boolValue ? '是' : '否';
} }
@ -329,7 +360,28 @@ export default function StaffTable() {
okText="确认" okText="确认"
cancelText="取消" cancelText="取消"
> >
<p></p> <div className="mb-4">
<span></span>
<select
value={exportScope}
onChange={(e) => setExportScope(e.target.value as any)}
className="ml-2 p-1 border rounded"
>
<option value="current"></option>
<option value="department"></option>
</select>
</div>
{exportScope === 'department' && (
<div>
<p></p>
<DepartmentSelect
value={selectedDepartment}
// onChange={(value) => setSelectedDepartment(value)}
placeholder="请选择部门"
/>
</div>
)}
</Modal> </Modal>
<Modal <Modal