feat(M5): 前端完善 + 部署 — Vue3 全量页面、仪表盘统计与我的审计接口、systemd/sudoers/迁移脚本、部署文档
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
// 展示层工具:时间/状态格式化、审计动作中文映射。
|
||||
|
||||
export function fmtTime(v: string | null | undefined): string {
|
||||
if (!v) return '-'
|
||||
const d = new Date(v)
|
||||
if (Number.isNaN(d.getTime())) return v
|
||||
return d.toLocaleString('zh-CN', { hour12: false })
|
||||
}
|
||||
|
||||
export function fmtDate(v: string | null | undefined): string {
|
||||
if (!v) return '-'
|
||||
const d = new Date(v)
|
||||
if (Number.isNaN(d.getTime())) return v
|
||||
return d.toLocaleDateString('zh-CN')
|
||||
}
|
||||
|
||||
export function daysLeft(expireAt: string | null): number | null {
|
||||
if (!expireAt) return null
|
||||
const diff = new Date(expireAt).getTime() - Date.now()
|
||||
return Math.ceil(diff / 86400000)
|
||||
}
|
||||
|
||||
// 用户状态中文
|
||||
export const userStatusText: Record<string, string> = {
|
||||
active: '正常',
|
||||
disabled: '已禁用',
|
||||
expired: '已过期',
|
||||
}
|
||||
|
||||
// 申请单状态中文
|
||||
export const approvalStatusText: Record<string, string> = {
|
||||
pending: '待审批',
|
||||
approved: '已通过',
|
||||
rejected: '已拒绝',
|
||||
}
|
||||
|
||||
// 审计动作中文映射(未知动作回显原文)
|
||||
const actionTextMap: Record<string, string> = {
|
||||
'auth.admin_login': '管理员登录',
|
||||
'auth.otp_send': '发送 OTP',
|
||||
'auth.otp_login': 'OTP 登录',
|
||||
'auth.logout': '登出',
|
||||
'user.create': '创建用户',
|
||||
'user.update': '更新用户',
|
||||
'user.disable': '禁用用户',
|
||||
'user.enable': '启用用户',
|
||||
'user.extend': '延期用户',
|
||||
'user.delete': '删除用户',
|
||||
'key.create': '上传密钥',
|
||||
'key.rename': '重命名密钥',
|
||||
'key.revoke': '吊销密钥',
|
||||
'approval.submit': '提交申请',
|
||||
'approval.review': '审批申请',
|
||||
'lifecycle.expire': '到期锁定',
|
||||
'lifecycle.recycle': '回收删除',
|
||||
}
|
||||
|
||||
export function actionText(action: string): string {
|
||||
return actionTextMap[action] || action
|
||||
}
|
||||
|
||||
/** 解析审计 detail(JSON 字符串),解析失败返回原文 */
|
||||
export function parseDetail(detail: string): string {
|
||||
try {
|
||||
return JSON.stringify(JSON.parse(detail))
|
||||
} catch {
|
||||
return detail
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user