From 538f2f5b38191490f4973a5cd06762e3ca7784c4 Mon Sep 17 00:00:00 2001 From: Li1304553726 <1304553726@qq.com> Date: Wed, 26 Mar 2025 16:21:41 +0800 Subject: [PATCH] add --- .../src/models/sys-logs/systemLog.router.ts | 86 --- .../staffinfo_write/staffinfo_write.page.tsx | 28 +- .../src/app/main/systemlog/SystemLogPage.tsx | 566 +++++++++++------- packages/client/src/api/hooks/useStaff.ts | 2 + 4 files changed, 369 insertions(+), 313 deletions(-) diff --git a/apps/server/src/models/sys-logs/systemLog.router.ts b/apps/server/src/models/sys-logs/systemLog.router.ts index 218d5ec..3eda41d 100644 --- a/apps/server/src/models/sys-logs/systemLog.router.ts +++ b/apps/server/src/models/sys-logs/systemLog.router.ts @@ -193,91 +193,5 @@ export class SystemLogRouter { } }); }), - - // 高级搜索日志 - searchLogs: this.trpc.procedure - .input(z.object({ - page: z.number().default(1), - pageSize: z.number().default(20), - level: z.enum(['info', 'warning', 'error', 'debug']).optional(), - module: z.string().optional(), - action: z.string().optional(), - operatorId: z.string().optional(), - targetId: z.string().optional(), - targetType: z.string().optional(), - status: z.enum(['success', 'failure']).optional(), - startTime: z.string().optional(), - endTime: z.string().optional(), - keyword: z.string().optional(), - departmentId: z.string().optional(), - })) - .query(async ({ input }) => { - // 构建查询条件 - const where: Prisma.SystemLogWhereInput = {}; - - if (input.level) where.level = input.level; - if (input.module) where.module = input.module; - if (input.action) where.action = input.action; - if (input.operatorId) where.operatorId = input.operatorId; - if (input.targetId) where.targetId = input.targetId; - if (input.targetType) where.targetType = input.targetType; - if (input.status) where.status = input.status; - if (input.departmentId) where.departmentId = input.departmentId; - - // 时间范围查询 - if (input.startTime || input.endTime) { - where.timestamp = {}; - if (input.startTime) where.timestamp.gte = new Date(input.startTime); - if (input.endTime) where.timestamp.lte = new Date(input.endTime); - } - - // 关键词搜索 - if (input.keyword) { - where.OR = [ - { targetName: { contains: input.keyword } }, - { action: { contains: input.keyword } }, - { module: { contains: input.keyword } }, - { errorMessage: { contains: input.keyword } }, - ]; - } - - // 使用select代替include - return this.systemLogService.findManyWithPagination({ - page: input.page, - pageSize: input.pageSize, - where, - select: { - id: true, - level: true, - module: true, - action: true, - timestamp: true, - operatorId: true, - ipAddress: true, - targetId: true, - targetType: true, - targetName: true, - details: true, - beforeData: true, - afterData: true, - status: true, - errorMessage: true, - departmentId: true, - operator: { - select: { - id: true, - username: true, - showname: true, - } - }, - department: { - select: { - id: true, - name: true, - } - } - } - }); - }), }) } \ No newline at end of file diff --git a/apps/web/src/app/main/staffinfo_write/staffinfo_write.page.tsx b/apps/web/src/app/main/staffinfo_write/staffinfo_write.page.tsx index 0bd1667..9b8fe79 100644 --- a/apps/web/src/app/main/staffinfo_write/staffinfo_write.page.tsx +++ b/apps/web/src/app/main/staffinfo_write/staffinfo_write.page.tsx @@ -47,7 +47,7 @@ const StaffInfoWrite = () => { // 按分组组织字段 const fieldGroups = useMemo(() => { if (!fields) return {}; - return fields.reduce((groups: any, field: any) => { + return (fields as any[]).reduce((groups: any, field: any) => { const group = field.group || '其他信息'; if (!groups[group]) { groups[group] = []; @@ -157,28 +157,38 @@ const StaffInfoWrite = () => { } }; - const onFinish = async (values: any) => { + const onFinish = async (e, values: any) => { + // values.preventDefault(); + e.preventDefault() + console.log(values) try { setLoading(true); // 创建基础员工记录 + if (!values.username) { + message.error("用户名不能为空"); + return; + } + + // 创建基础员工记录 + console.log('准备创建用户,数据:', { username: values.username }); const staff = await create.mutateAsync({ data: { username: values.username, password: '123456' } }); - + console.log('创建员工记录:', staff); // 过滤有效字段并转换值 const validEntries = Object.entries(values) - .filter(([_, value]) => value !== undefined && value !== null && value !== '') + .filter(([key, value]) => key !== 'username' && value !== undefined && value !== null && value !== '') .map(([fieldName, value]) => { - const field = fields?.find((f: any) => f.name === fieldName); + const field = fields && Array.isArray(fields) ? fields.find((f: any) => f.name === fieldName) : undefined; let processedValue = value; // 处理特殊字段类型 - if (field?.type === 'date' && value instanceof moment) { - processedValue = value.format('YYYY-MM-DD'); + if (field?.type === 'date') { + processedValue = value.toString(); } else if (field?.type === 'cascader' && Array.isArray(value)) { processedValue = value.join('/'); } @@ -197,8 +207,10 @@ const StaffInfoWrite = () => { }) ) ); + console.log('自定义字段提交成功',staff.username); message.success("信息提交成功"); + form.resetFields(); } catch (error) { console.error('提交出错:', error); message.error("提交失败,请重试"); @@ -218,7 +230,6 @@ const StaffInfoWrite = () => {