fix: 审计日志补充关键操作详情,前端改为可读格式显示
This commit is contained in:
@@ -63,6 +63,57 @@ const ENTITY_LABELS: Record<string, string> = {
|
||||
NotificationSetting: '通知设置',
|
||||
}
|
||||
|
||||
/** 审计日志 detail 字段中文标签映射 */
|
||||
const DETAIL_LABELS: Record<string, string> = {
|
||||
employeeName: '员工',
|
||||
department: '部门',
|
||||
name: '姓名',
|
||||
reason: '原因',
|
||||
type: '类型',
|
||||
terminationDate: '离职日期',
|
||||
compensation: '补偿金',
|
||||
contractType: '合同类型',
|
||||
startDate: '开始日期',
|
||||
endDate: '结束日期',
|
||||
employeeId: '员工ID',
|
||||
count: '数量',
|
||||
years: '续签年限',
|
||||
hireDate: '入职日期',
|
||||
oldSalary: '原薪资',
|
||||
newSalary: '新薪资',
|
||||
oldDepartment: '原部门',
|
||||
newDepartment: '新部门',
|
||||
comment: '备注',
|
||||
resignationReason: '离职原因',
|
||||
batch: '批量',
|
||||
violationType: '违纪类型',
|
||||
severity: '严重程度',
|
||||
action: '处理措施',
|
||||
topic: '培训主题',
|
||||
trainer: '培训师',
|
||||
duration: '时长',
|
||||
period: '考核周期',
|
||||
score: '得分',
|
||||
grade: '等级',
|
||||
reviewer: '考评人',
|
||||
}
|
||||
|
||||
/** 将 detail 对象格式化为可读字符串 */
|
||||
function formatDetail(detail: any): string {
|
||||
if (!detail || typeof detail !== 'object') return ''
|
||||
const entries = Object.entries(detail).filter(([, v]) => v !== '' && v !== null && v !== undefined)
|
||||
if (entries.length === 0) return ''
|
||||
return entries.map(([k, v]) => {
|
||||
const label = DETAIL_LABELS[k] || k
|
||||
let val = String(v)
|
||||
if (k === 'compensation' && val && val !== '0') val = `¥${val}`
|
||||
if (k === 'startDate' || k === 'endDate' || k === 'terminationDate' || k === 'hireDate') {
|
||||
val = String(v).slice(0, 10)
|
||||
}
|
||||
return `${label}: ${val}`
|
||||
}).join(' | ')
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统操作日志页面
|
||||
*/
|
||||
@@ -168,11 +219,11 @@ export default function AuditLog() {
|
||||
<span className="text-sm font-medium">{ACTION_LABELS[log.action] || log.action}</span>
|
||||
<span className="px-1.5 py-0.5 rounded text-xs bg-gray-100 text-gray-600">{ENTITY_LABELS[log.entity] || log.entity}</span>
|
||||
</div>
|
||||
{log.detail && (
|
||||
{log.detail && (() => { const formatted = formatDetail(log.detail); return formatted ? (
|
||||
<div className="text-xs text-gray-500 mt-0.5 truncate">
|
||||
{typeof log.detail === 'object' ? JSON.stringify(log.detail).slice(0, 100) : String(log.detail).slice(0, 100)}
|
||||
{formatted}
|
||||
</div>
|
||||
)}
|
||||
) : null; })()}
|
||||
</div>
|
||||
<div className="text-xs text-gray-400 flex-shrink-0 text-right">
|
||||
<div>{new Date(log.createdAt).toLocaleString('zh-CN', { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' })}</div>
|
||||
|
||||
Reference in New Issue
Block a user