const OPERATION_RESULT_META = {
|
1: { text: '成功', type: 'success' },
|
0: { text: '失败', type: 'danger' }
|
}
|
|
export const OPERATION_RECORD_REPORT_TITLE = '操作日志报表'
|
|
export function createOperationRecordSearchState() {
|
return {
|
condition: '',
|
namespace: '',
|
url: '',
|
clientIp: '',
|
result: '',
|
timeStart: '',
|
timeEnd: ''
|
}
|
}
|
|
export function getOperationRecordPaginationKey() {
|
return {
|
current: 'current',
|
size: 'pageSize'
|
}
|
}
|
|
export function buildOperationRecordSearchParams(params = {}) {
|
return {
|
condition: String(params.condition || '').trim(),
|
namespace: String(params.namespace || '').trim(),
|
url: String(params.url || '').trim(),
|
clientIp: String(params.clientIp || '').trim(),
|
...(params.result !== '' && params.result !== null && params.result !== undefined
|
? { result: Number(params.result) }
|
: {}),
|
...(params.timeStart ? { timeStart: params.timeStart } : {}),
|
...(params.timeEnd ? { timeEnd: params.timeEnd } : {})
|
}
|
}
|
|
export function buildOperationRecordPageQueryParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...buildOperationRecordSearchParams(params)
|
}
|
}
|
|
export function getOperationResultMeta(value) {
|
return OPERATION_RESULT_META[Number(value)] || { text: '-', type: 'info' }
|
}
|
|
export function formatOperationTimestamp(value) {
|
if (value === '' || value === null || value === undefined) {
|
return ''
|
}
|
|
const timestamp = Number(value)
|
const date = Number.isNaN(timestamp) ? new Date(value) : new Date(timestamp)
|
if (Number.isNaN(date.getTime())) {
|
return String(value)
|
}
|
|
const pad = (segment) => String(segment).padStart(2, '0')
|
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(
|
date.getMinutes()
|
)}:${pad(date.getSeconds())}`
|
}
|
|
export function normalizeOperationRecordRow(record = {}) {
|
const resultMeta = getOperationResultMeta(record.result)
|
return {
|
...record,
|
namespace: record.namespace || '',
|
url: record.url || '',
|
appkey: record.appkey || '',
|
request: record.request || '',
|
response: record.response || '',
|
err: record.err || '',
|
memo: record.memo || '',
|
clientIp: record.clientIp || '',
|
spendTime: record.spendTime ?? 0,
|
userLabel: record['userId$'] || record.userLabel || (record.userId ? String(record.userId) : ''),
|
timestampText: formatOperationTimestamp(record.timestamp),
|
createTimeText: record['createTime$'] || record.createTime || '',
|
resultText: resultMeta.text,
|
resultType: resultMeta.type
|
}
|
}
|
|
export function mergeOperationRecordDetail(detail = {}, fallback = {}) {
|
return normalizeOperationRecordRow({
|
...fallback,
|
...detail
|
})
|
}
|
|
export function getOperationRecordReportColumns() {
|
return [
|
{ prop: 'namespace', label: '名称空间' },
|
{ prop: 'url', label: '接口地址' },
|
{ prop: 'userLabel', label: '操作用户' },
|
{ prop: 'clientIp', label: '客户端IP' },
|
{ prop: 'spendTimeText', label: '耗时(ms)' },
|
{ prop: 'resultText', label: '结果' },
|
{ prop: 'timestampText', label: '操作时间' }
|
]
|
}
|
|
export function buildOperationRecordPrintRows(records = []) {
|
return records.map((record) => {
|
const row = normalizeOperationRecordRow(record)
|
return {
|
namespace: row.namespace || '--',
|
url: row.url || '--',
|
userLabel: row.userLabel || '--',
|
clientIp: row.clientIp || '--',
|
spendTimeText: row.spendTime ?? '--',
|
resultText: row.resultText || '--',
|
timestampText: row.timestampText || '--'
|
}
|
})
|
}
|