wsj
3 days ago d4610c829833996f91704b3891a5c5845bfe0d6b
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import { Button, Space, Tag } from 'antd';
import type { ProColumns } from '@ant-design/pro-components';
import dayjs from 'dayjs';
import type { AuditLogResultStatus, AuditLogVO } from './types';
 
/** 业务模块(后端可能扩展,未命中的直接展示原值)。 */
export const moduleText: Record<string, string> = {
  EMPLOYEE: '员工',
  ORG: '组织',
  ROLE: '角色',
  CUSTOMER: '客户',
  FOLLOW_UP: '跟进',
  TENANT: '租户',
  SYSTEM: '系统',
};
 
/** 操作动作(后端可能扩展,未命中的直接展示原值)。 */
export const actionText: Record<string, string> = {
  CREATE: '新增',
  UPDATE: '修改',
  DELETE: '删除',
  IMPORT: '导入',
  EXPORT: '导出',
  LOGIN: '登录',
  LOGOUT: '退出',
};
 
export const resultStatusMeta: Record<AuditLogResultStatus, { text: string; color: string }> = {
  SUCCESS: { text: '成功', color: 'success' },
  FAILURE: { text: '失败', color: 'error' },
};
 
const toValueEnum = (meta: Record<string, string>) =>
  Object.fromEntries(Object.entries(meta).map(([value, text]) => [value, { text }]));
 
export const getModuleText = (value?: string) => (value ? moduleText[value] ?? value : '-');
 
export const getActionText = (value?: string) => (value ? actionText[value] ?? value : '-');
 
export const createAuditLogColumns = (options: {
  onDetail: (record: AuditLogVO) => void;
}): ProColumns<AuditLogVO>[] => [
  {
    title: '日志 ID',
    dataIndex: 'logId',
    width: 100,
    search: false,
  },
  {
    title: '操作时间',
    dataIndex: 'createdAt',
    valueType: 'dateTime',
    width: 170,
    search: false,
  },
  {
    title: '操作人',
    dataIndex: 'operatorName',
    width: 140,
    search: false,
    render: (_value, record) => (
      <Space direction="vertical" size={0}>
        <span>{record.operatorName || '-'}</span>
        {record.operatorRole && <span className="text-muted">{record.operatorRole}</span>}
      </Space>
    ),
  },
  {
    title: '操作人 ID',
    dataIndex: 'operatorId',
    valueType: 'digit',
    hideInTable: true,
    fieldProps: { placeholder: '请输入操作人 ID' },
  },
  {
    title: '业务模块',
    dataIndex: 'module',
    width: 100,
    valueEnum: toValueEnum(moduleText),
    render: (_value, record) => getModuleText(record.module),
  },
  {
    title: '操作动作',
    dataIndex: 'action',
    width: 100,
    valueEnum: toValueEnum(actionText),
    render: (_value, record) => getActionText(record.action),
  },
  {
    title: '操作描述',
    dataIndex: 'operationDesc',
    width: 120,
    search: false,
    ellipsis: true,
    render: (_value, record) => record.operationDesc || '-',
  },
  {
    title: '操作对象',
    dataIndex: 'entityName',
    width: 180,
    search: false,
    ellipsis: true,
    render: (_value, record) => record.entityName || '-',
  },
  {
    title: '实体类型',
    dataIndex: 'entityType',
    hideInTable: true,
    fieldProps: { placeholder: '请输入实体类型' },
  },
  {
    title: '请求',
    dataIndex: 'requestPath',
    width: 220,
    search: false,
    ellipsis: true,
    render: (_value, record) => (
      <Space size={4}>
        <Tag bordered={false}>{record.requestMethod || '-'}</Tag>
        <span>{record.requestPath || '-'}</span>
      </Space>
    ),
  },
  {
    title: '来源 IP',
    dataIndex: 'requestIp',
    width: 130,
    search: false,
  },
  {
    title: '结果',
    dataIndex: 'resultStatus',
    width: 90,
    valueEnum: {
      SUCCESS: { text: resultStatusMeta.SUCCESS.text },
      FAILURE: { text: resultStatusMeta.FAILURE.text },
    },
    render: (_value, record) => {
      const meta = record.resultStatus ? resultStatusMeta[record.resultStatus] : undefined;
      return meta ? (
        <Tag color={meta.color} bordered={false}>
          {meta.text}
        </Tag>
      ) : (
        '-'
      );
    },
  },
  {
    title: '操作',
    key: 'option',
    valueType: 'option',
    width: 80,
    render: (_value, record) => (
      <Button type="link" size="small" onClick={() => options.onDetail(record)}>
        详情
      </Button>
    ),
  },
  {
    title: '操作时间',
    dataIndex: 'timeRange',
    valueType: 'dateRange',
    hideInTable: true,
    search: {
      transform: (value: [string, string]) => ({
        start: value?.[0] ? dayjs(value[0]).format('YYYY-MM-DD 00:00:00') : undefined,
        end: value?.[1] ? dayjs(value[1]).format('YYYY-MM-DD 23:59:59') : undefined,
      }),
    },
  },
];