yeg
4 天以前 f4d7007b89cf565746af4623623a294b82666ff1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { request, type ApiResponse } from './request'
 
interface PlatformOperationLog {
  operId: number
  operName: string
  title: string
  method: string
  businessType: number
  operParam: string
  operTime: string
  status: number
}
 
export interface OperationLogRecord {
  id: number
  operator: string
  content: string
  operatedAt: string
}
 
function operationContent(item: PlatformOperationLog) {
  if (item.method === 'compare-report.delete') {
    try {
      const identity = JSON.parse(item.operParam)
      if (typeof identity.reportId === 'number' && typeof identity.reportName === 'string')
        return `删除对比报表“${identity.reportName}”(#${identity.reportId})及全部版本`
    } catch { /* 非结构化平台日志仍展示模块与动作。 */ }
  }
  const actions = ['操作', '新增', '修改', '删除', '授权', '导出', '导入', '强退', '生成代码', '清空数据']
  return `${item.title}:${actions[item.businessType] || '操作'}(${item.status === 0 ? '成功' : '失败'})`
}
 
/** 读取正式平台日志供既有本地筛选分页使用,不展示通用请求或响应中的业务内容。 */
export async function listOperationLogs(): Promise<OperationLogRecord[]> {
  const records: PlatformOperationLog[] = []
  for (let pageNum = 1; ; pageNum++) {
    const result = await request<ApiResponse & { rows: PlatformOperationLog[]; total: number }>(`/monitor/operlog/list?pageNum=${pageNum}&pageSize=100`)
    records.push(...result.rows)
    if (!result.rows.length || records.length >= result.total) break
  }
  return records.map(item => ({ id: item.operId, operator: item.operName || '-',
    content: operationContent(item), operatedAt: item.operTime || '',
  }))
}