- 切换数据库为PostgreSQL,更新依赖与配置 - 重构权限体系,使用sys_user/sys_role/sys_menu等新实体替代旧模型 - 移除旧的用户角色/权限/系统设置相关代码与实体 - 新增字典、菜单管理模块与基础CRUD接口 - 优化鉴权逻辑,基于菜单权限标识进行接口校验 - 前端同步更新API、路由与权限控制逻辑 - 删除冗余的v-permission指令与相关代码
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
import { Controller, Get, Del, Inject, Query, Param, All } from "@midwayjs/core";
|
|
import { Context } from "@midwayjs/koa";
|
|
import { LogService } from "../service/log.service";
|
|
|
|
@Controller("/api/logs")
|
|
export class LogController {
|
|
@Inject()
|
|
ctx!: Context;
|
|
|
|
@Inject()
|
|
logService!: LogService;
|
|
|
|
@Get("/")
|
|
async list(@Query() query: { page?: number; pageSize?: number; userId?: string; module?: string; action?: string; startDate?: string; endDate?: string }) {
|
|
const result = await this.logService.list(query);
|
|
return result;
|
|
}
|
|
|
|
@Get("/:id")
|
|
async detail(@Param("id") id: string) {
|
|
const result = await this.logService.detail(id);
|
|
return result;
|
|
}
|
|
|
|
@All("/export")
|
|
async export(@Query() query: any) {
|
|
try {
|
|
const csvContent = await this.logService.exportLogs(query);
|
|
|
|
this.ctx.set("Content-Type", "text/csv;charset=utf-8");
|
|
this.ctx.set("Content-Disposition", `attachment; filename=operation_logs_${Date.now()}.csv`);
|
|
|
|
this.ctx.body = csvContent;
|
|
return;
|
|
} catch (error: any) {
|
|
return {
|
|
code: 500,
|
|
message: error?.message || "导出失败"
|
|
};
|
|
}
|
|
}
|
|
|
|
@Del("/clear")
|
|
async clear() {
|
|
const result = await this.logService.cleanExpiredLogs(0);
|
|
return {
|
|
code: 200,
|
|
message: `成功清理 ${result} 条日志`,
|
|
data: { deletedCount: result }
|
|
};
|
|
}
|
|
}
|