wsj
3 days ago 0d9778720a5258876079d02bb8603dd202e6b1a8
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { useMemo } from 'react';
import { Descriptions, Drawer, Tag } from 'antd';
import type { DescriptionsProps } from 'antd';
import dayjs from 'dayjs';
import { getActionText, getModuleText, resultStatusMeta } from '../columns';
import type { AuditLogVO } from '../types';
import '../AuditLogs.scss';
 
interface AuditLogDetailDrawerProps {
  open: boolean;
  /** 待展示的审计日志,关闭时为 null。 */
  record: AuditLogVO | null;
  onClose: () => void;
}
 
const renderTag = (meta?: { text: string; color: string }) =>
  meta ? (
    <Tag color={meta.color} bordered={false}>
      {meta.text}
    </Tag>
  ) : (
    '-'
  );
 
const AuditLogDetailDrawer = ({ open, record, onClose }: AuditLogDetailDrawerProps) => {
  const items = useMemo<DescriptionsProps['items']>(() => {
    if (!record) return [];
 
    return [
      { key: 'logId', label: '日志 ID', children: record.logId },
      {
        key: 'createdAt',
        label: '操作时间',
        children: record.createdAt ? dayjs(record.createdAt).format('YYYY-MM-DD HH:mm:ss') : '-',
      },
      {
        key: 'operator',
        label: '操作人',
        children: `${record.operatorName || '-'}${record.operatorRole ? `(${record.operatorRole})` : ''}`,
      },
      { key: 'operatorId', label: '操作人 ID', children: record.operatorId ?? '-' },
      { key: 'tenantId', label: '租户 ID', children: record.tenantId || '-' },
      { key: 'module', label: '业务模块', children: getModuleText(record.module) },
      { key: 'action', label: '操作动作', children: getActionText(record.action) },
      { key: 'operationDesc', label: '操作描述', children: record.operationDesc || '-' },
      { key: 'entityType', label: '实体类型', children: record.entityType || '-' },
      { key: 'entityId', label: '实体 ID', children: record.entityId || '-' },
      { key: 'entityName', label: '实体名称', children: record.entityName || '-' },
      {
        key: 'resultStatus',
        label: '结果状态',
        children: renderTag(record.resultStatus ? resultStatusMeta[record.resultStatus] : undefined),
      },
      { key: 'errorMessage', label: '错误信息', children: record.errorMessage || '-' },
      { key: 'requestMethod', label: '请求方法', children: record.requestMethod || '-' },
      { key: 'requestPath', label: '请求路径', children: record.requestPath || '-' },
      { key: 'requestIp', label: '来源 IP', children: record.requestIp || '-' },
      {
        key: 'userAgent',
        label: 'User-Agent',
        children: <span className="text-muted">{record.userAgent || '-'}</span>,
      },
      {
        key: 'changeDetail',
        label: '变更明细',
        children: record.changeDetail ? (
          <pre className="audit-log-page__change-detail">{record.changeDetail}</pre>
        ) : (
          '-'
        ),
      },
    ];
  }, [record]);
 
  return (
    <Drawer title="审计日志详情" width={560} open={open} onClose={onClose}>
      {record && <Descriptions column={1} bordered size="small" items={items} />}
    </Drawer>
  );
};
 
export default AuditLogDetailDrawer;