This commit is contained in:
Li1304553726 2025-03-25 23:07:03 +08:00
parent 4a111e05f9
commit 2f6e6bd0fe
3 changed files with 76 additions and 15 deletions

View File

@ -7,8 +7,11 @@ import { useStaff } from "@nice/client";
import DepartmentChildrenSelect from "@web/src/components/models/department/department-children-select";
import { areaOptions } from './area-options';
import DepartmentSelect from "@web/src/components/models/department/department-select";
import { addLog } from "@web/src/app/main/systemlog/SystemLogPage";
const { TextArea } = Input;
const StaffInformation = () => {
const [modalForm] = Form.useForm();
const [form] = Form.useForm();
@ -58,10 +61,8 @@ const StaffInformation = () => {
message.warning('请输入内容');
}
};
const onFinish = async (values: any) => {
console.log('开始提交表单');
try {
setLoading(true);
const formattedValues = {
@ -74,7 +75,7 @@ const StaffInformation = () => {
hireDate: values.hireDate?.toISOString(),
seniority: values.seniority?.toISOString(),
currentPositionDate: values.currentPositionDate?.toISOString(),
rankDate: values.rankDate?.toISOString(), // 修改这里
rankDate: values.rankDate?.toISOString(),
};
await create.mutateAsync(
@ -87,9 +88,31 @@ const StaffInformation = () => {
console.log('奖励列表:', rewardsList);
console.log('处分列表:', punishmentsList);
// 添加日志记录
addLog(`用户 ${values.username || '未知'} 的人员信息已成功添加`);
addLog(`提交的数据: 姓名=${values.username}, 身份证号=${values.idNumber}, 警号=${values.officerId}, 部门ID=${values.deptId}`);
if (rewardsList.length > 0) {
addLog(`${values.username} 的奖励信息: ${rewardsList.join(' | ')}`);
}
if (punishmentsList.length > 0) {
addLog(`${values.username} 的处分信息: ${punishmentsList.join(' | ')}`);
}
if (equipmentList.length > 0) {
addLog(`${values.username} 的装备信息: ${equipmentList.join(' | ')}`);
}
if (projectsList.length > 0) {
addLog(`${values.username} 的任务信息: ${projectsList.join(' | ')}`);
}
message.success("信息提交成功");
} catch (error) {
console.error('提交出错:', error);
// 添加错误日志
addLog(`提交人员信息失败: ${error instanceof Error ? error.message : '未知错误'}`);
message.error("提交失败,请重试");
} finally {
setLoading(false);

View File

@ -57,10 +57,8 @@ export default function StaffTable() {
const [paginationEnabled, setPaginationEnabled] = useState(true);
const [importVisible, setImportVisible] = useState(false);
const [selectedRows, setSelectedRows] = useState<any[]>([]);
const handleConfirm = async () => {
setFileNameVisible(true);
};
// 添加导出处理函数
const handleFileNameConfirm = () => {
@ -69,7 +67,6 @@ export default function StaffTable() {
console.error('Grid API 未正确初始化');
return;
}
// 修改获取节点方式(使用更可靠的 getRenderedNodes
const rowNodes = gridApi.getRenderedNodes();
@ -147,7 +144,6 @@ export default function StaffTable() {
gridApi.onFilterChanged(); // 触发筛选更新
}
};
const columnDefs: (ColDef | ColGroupDef)[] = [
{
field: 'username',
@ -329,8 +325,6 @@ export default function StaffTable() {
]
}
];
const defaultColDef: ColDef = {
sortable: true,
filter: 'agSetColumnFilter',
@ -474,7 +468,6 @@ export default function StaffTable() {
utils.book_append_sheet(wb, ws, "员工模板");
writeFile(wb, `员工数据模板_${new Date().toISOString().slice(0, 10)}.xlsx`);
};
// 添加导入API钩子
const createManyMutation = api.staff.create.useMutation({
onSuccess: () => {
@ -486,7 +479,6 @@ export default function StaffTable() {
message.error(`导入失败: ${error.message}`);
}
});
// 处理Excel导入数据
const handleImportData = (excelData: any[]) => {
// 转换Excel数据为后端接受的格式

View File

@ -1,3 +1,49 @@
export default function SystemLogPage() {
return <div>SystemLogPage</div>;
"use client";
import React, { useState, useEffect } from 'react';
// 创建一个全局变量来存储日志
let globalLogs: string[] = [];
// 添加日志的函数
export const addLog = (log: string) => {
const timestamp = new Date().toLocaleString();
const formattedLog = `[${timestamp}] ${log}`;
globalLogs = [...globalLogs, formattedLog];
// 如果需要可以将日志保存到localStorage
localStorage.setItem('systemLogs', JSON.stringify(globalLogs));
};
const SystemLogPage = () => {
const [logs, setLogs] = useState<string[]>([]);
// 组件加载时从全局变量或localStorage获取日志
useEffect(() => {
// 尝试从localStorage获取日志
const storedLogs = localStorage.getItem('systemLogs');
if (storedLogs) {
setLogs(JSON.parse(storedLogs));
} else {
setLogs(globalLogs);
}
}, []);
return (
<div className="max-w-4xl mx-auto p-6">
<h1 className="text-2xl font-bold mb-6"></h1>
<div className="bg-white p-6 rounded-lg shadow">
{logs.length === 0 ? (
<p className="text-gray-500"></p>
) : (
<ul className="space-y-2">
{logs.map((log, index) => (
<li key={index} className="p-2 border-b border-gray-200">
{log}
</li>
))}
</ul>
)}
</div>
</div>
);
};
export default SystemLogPage;