feat(admin): Add activity logs page and fix AI chat markdown rendering

- Add paginated activity logs API with filters (date, module, action, keyword)

- Add ActivityLogsPage with table, filters, and detail modal

- Add markdown rendering support for AI chat messages

- Remove prototype placeholder content from chat sidebar

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-02-01 21:04:21 +08:00
parent aaa29ea9d3
commit 4c2c9b437b
9 changed files with 795 additions and 9 deletions

View File

@@ -290,6 +290,113 @@ export const activityService = {
};
},
/**
* 分页查询运营日志(支持筛选)
*
* @param options 查询选项
*/
async getActivityLogs(options: {
page: number;
pageSize: number;
startDate?: Date;
endDate?: Date;
module?: string;
action?: string;
keyword?: string;
}): Promise<{
data: Array<{
id: string;
createdAt: Date;
tenantId: string;
tenantName: string | null;
userId: string;
userName: string | null;
module: string;
feature: string;
action: string;
info: string | null;
}>;
total: number;
page: number;
pageSize: number;
}> {
const { page, pageSize, startDate, endDate, module, action, keyword } = options;
// 构建 where 条件
const where: any = {};
// 日期范围筛选
if (startDate || endDate) {
where.created_at = {};
if (startDate) where.created_at.gte = startDate;
if (endDate) {
// endDate 设置到当天结束
const endOfDay = new Date(endDate);
endOfDay.setHours(23, 59, 59, 999);
where.created_at.lte = endOfDay;
}
}
// 模块筛选
if (module) {
where.module = module;
}
// 动作筛选
if (action) {
where.action = action;
}
// 关键词搜索(用户名或租户名)
if (keyword) {
where.OR = [
{ user_name: { contains: keyword, mode: 'insensitive' } },
{ tenant_name: { contains: keyword, mode: 'insensitive' } },
];
}
// 并行查询数据和总数
const [logs, total] = await Promise.all([
prisma.simple_logs.findMany({
where,
orderBy: { created_at: 'desc' },
skip: (page - 1) * pageSize,
take: pageSize,
select: {
id: true,
created_at: true,
tenant_id: true,
tenant_name: true,
user_id: true,
user_name: true,
module: true,
feature: true,
action: true,
info: true,
}
}),
prisma.simple_logs.count({ where }),
]);
return {
data: logs.map(log => ({
id: log.id,
createdAt: log.created_at,
tenantId: log.tenant_id,
tenantName: log.tenant_name,
userId: log.user_id,
userName: log.user_name,
module: log.module,
feature: log.feature,
action: log.action,
info: log.info,
})),
total,
page,
pageSize,
};
},
/**
* 清理过期日志180天前的数据
* 用于定时任务调用