This commit is contained in:
Li1304553726 2025-03-27 10:18:38 +08:00
parent 9a1485661d
commit 0efb7787a7
3 changed files with 18 additions and 7 deletions

View File

@ -5,8 +5,11 @@ import EventBus, { CrudOperation } from "@server/utils/event-bus";
@Injectable()
export class SystemLogService extends BaseService<Prisma.SystemLogDelegate> {
protected readonly prismaClient: any;
constructor() {
super(db, ObjectType.SYSTEM_LOG, false); // 不自动处理更新时间和删除时间
super(db, ObjectType.SYSTEM_LOG, false);
this.prismaClient = db;
}
async create(args: Prisma.SystemLogCreateArgs) {
@ -31,20 +34,19 @@ export class SystemLogService extends BaseService<Prisma.SystemLogDelegate> {
return super.findMany(args); // 放弃分页结构
}
// 添加分页查询方法
async findManyWithPagination({ page = 1, pageSize = 20, where = {}, ...rest }: any) {
const skip = (page - 1) * pageSize;
try {
const [items, total] = await Promise.all([
this.delegate.findMany({
this.prismaClient.systemLog.findMany({
where,
skip,
take: pageSize,
orderBy: { timestamp: 'desc' },
...rest
}),
this.delegate.count({ where })
this.prismaClient.systemLog.count({ where })
]);
return {
@ -119,7 +121,6 @@ export class SystemLogService extends BaseService<Prisma.SystemLogDelegate> {
};
}
});
return { changes };
}

View File

@ -4,7 +4,10 @@ import React, { useState, useEffect } from 'react';
// 创建一个全局变量来存储日志
let globalLogs: string[] = [];
const clearLogs = () => {
localStorage.removeItem('systemLogs');
setLogs([]);
};
// 添加日志的函数
export const addLog = (log: string) => {
const timestamp = new Date().toLocaleString();
@ -29,6 +32,9 @@ const SystemLogPage = () => {
return (
<div className="max-w-4xl mx-auto p-6">
<h1 className="text-2xl font-bold mb-6"></h1>
<button onClick={clearLogs} className="mb-4 bg-red-500 text-white p-2 rounded">
</button>
<div className="bg-white p-6 rounded-lg shadow">
{logs.length === 0 ? (
<p className="text-gray-500"></p>
@ -47,3 +53,7 @@ const SystemLogPage = () => {
};
export default SystemLogPage;
function setLogs(arg0: undefined[]) {
throw new Error('Function not implemented.');
}

View File

@ -567,7 +567,7 @@ model SystemLog {
// 关联部门
departmentId String? @map("department_id")
department Department? @relation(fields: [departmentId], references: [id])
message String @map("message") // 完整的日志文本内容
message String? @map("message") // 完整的日志文本内容
// 优化索引
@@index([timestamp])
@@index([level])