/**
* 册10 SC-04 审计日志页(运营侧宿主;现路由 /audit-logs)。
* 契约:docs/.../10-第10册-定时任务与审计视图/14-页面契约本册逐页.md §14.4、作业§5。
* 接线现状:
* - 行集=/audit/get_list@v1 [实] 游标翻页(⛔ 总数、⛔ 跳页);11001 ⇒ 整页 W35;其余失败 ⇒ W36+重试(横幅保留);
* - 六列 W31:操作人「姓名快照+角色码」与对象「object_display 快照」后端未下发(I38 写侧待平台接通),
* 操作人列显 username/user_id 真值;对象列走 D-71 回落链=契约快照 → 写侧随流水落下的名称快照
* (`detail_json.object`/`after` 里的 `plan_name`/`contract_no`/`name` 等白名单键)→ 都取不到才 W32
* +对象类型小字(⚠️ 不留空、不猜、⛔ 拿当前库里的名字顶替历史行=B-42/I38);
* - 操作类型=编译期注册表(lib/audit-registry.ts,册1/2/3/5/10 登记表并集 + 真库实际机器名)机器名→中文名;
* 查表前先 `normalizeAuditAction` 归一(D-59:写侧混用 `bos.` 前缀/点分变体/中文串三种形态);
* 未登记动作 ⇒ 原样+「未登记动作」小字(作业§9.4 纪律②,⚠️ 不隐藏该行);
* - 前后值区都为空时把 `detail_json` 以「明细:」并列进「变更后」列(D-67,⛔ 新增第七列);
* - 导出=`/audit/export@v1` [实] 已声明并接线:按钮仅 admin/regAdmin 渲染(U-77),确认弹窗三行 W37a–c 缺一即缺陷;
* ⚠️ 键 `bos.audit.export@v1` 尚未绑给运营三角色(2026-11-18 补绑撞平台 grant ceiling)⇒ 未绑期仍回
* `11001`(按 `AUDIT_EXPORT_WIRING_NOTE` 提示,⛔ 说成「接口未声明」),KLT-R20903 ⇒ W38,KLT-S405 ⇒ W39。
*/
import { useState } from "react";
import { PageIntro } from "../components/PageIntro";
import { Download, Search } from "lucide-react";
import { Button } from "../components/ui/button";
import { Input } from "../components/ui/input";
import { FilterSelect } from "../components/ui/filter-select";
import { DateRangeFilter } from "../components/ui/date-range-filter";
import { OpsNotice, OpsTableColumns, OpsTableEmpty } from "../components/OperationsKit";
import { useDemoIdentity } from "../lib/demo-session";
import { EMPTY_AUDIT_FILTER, auditDetailLines, auditObjectSnapshot, auditSeatLines, formatAuditValue, submitAuditExport, useAuditList, type AuditFilter } from "../lib/audit-logs";
import {
AUDIT_ACTION_DISPLAY,
AUDIT_ACTION_UNREGISTERED,
AUDIT_OBJECT_TYPES,
AUDIT_OBJECT_TYPE_DISPLAY,
normalizeAuditAction,
normalizeAuditObjectType,
} from "../lib/audit-registry";
import {
BTN_CANCEL,
BTN_CONFIRM_EXPORT,
EXPORT_DIALOG_TITLE,
W15,
W31_COLUMNS,
W32,
W33A,
W33B,
W33C,
W33D,
W34A,
W34B,
W35,
W36,
W37A,
W37B,
W37C,
} from "../lib/copy-jobs";
import type { AuditItem } from "../lib/api/types";
import "../styles/operations.css";
/** occurred_at → 东八区「日期+时刻」两行(总则§10.2,⚠️ 不显 UTC 串);null ⇒ 「—」(时刻未知,⛔ 猜) */
function TimeCell({ at }: { at: string | null }) {
if (!at) return <>—>;
const date = new Date(at);
if (Number.isNaN(date.getTime())) return <>{at}>;
const dateText = new Intl.DateTimeFormat("zh-CN", { timeZone: "Asia/Shanghai", year: "numeric", month: "2-digit", day: "2-digit" }).format(date);
const timeText = new Intl.DateTimeFormat("zh-CN", { timeZone: "Asia/Shanghai", hour: "2-digit", minute: "2-digit", second: "2-digit", hour12: false }).format(date);
return (
<>
{dateText}
{timeText}
>
);
}
/** 第 3 列:中文动作名(注册表命中)/原样+未登记小字(作业§9.4②) */
function ActionCell({ action }: { action: string }) {
// D-59:写侧同一动作有三种形态(`bos.` 前缀/点分变体/中文串)⇒ 先归一再查表,查不到才判未登记
const display = AUDIT_ACTION_DISPLAY[normalizeAuditAction(action)];
if (display) return <>{display}>;
return (
<>
{action}
{AUDIT_ACTION_UNREGISTERED}
>
);
}
/**
* 第 4 列:对象名回落链(D-71)=契约 `object_display` 快照 → 写侧随流水落下的名称快照
* (`detail_json.object`/前后值区的白名单名称键)→ 都取不到才 W32;三种形态都并列「类型 · 主键」小字。
* ⛔ 拿当前库里的名字顶替历史行(I38:改名会伪造流水),⛔ 留空。
*/
function ObjectCell({ item }: { item: AuditItem }) {
const typeText = AUDIT_OBJECT_TYPE_DISPLAY[normalizeAuditObjectType(item.object.type)] ?? item.object.type;
const snapshot = auditObjectSnapshot(item);
return (
<>
{snapshot ? (
{snapshot.text}
) : (
W32
)}
{typeText} · {item.object.id}
>
);
}
function ValueCell({ value }: { value: unknown }) {
return (
<>
{formatAuditValue(value).map((line, index) => (
{W33A}
; if (role === "enterprise" || role === "sub") return{W33C}
; if (role === "partner" || role === "operator" || role === "teamLead") { // 只读横幅三行:partner/operator 必挂,teamLead 建议挂(② 范围口径句各取 W33b/W33d) return ( <>{W34A}
{role === "teamLead" ? W33D : W33B}
{W34B}
> ); } return null; // admin 无追加句;ops 无本册横幅句 } /** 导出二次确认弹窗(契约 14.4.4):正文三行缺一即缺陷;按钮「取消/确认导出」 */ function ExportDialog({ filter, onCancel, onDone }: { filter: AuditFilter; onCancel: () => void; onDone: (message: string) => void }) { const [pending, setPending] = useState(false); const [error, setError] = useState{W37A}
{W37B}
{W37C}
{error && ({error}
)}{filterError}
)} {list.phase.kind === "error" && ({W36}:{list.phase.message}{" "}
)}| {column} | ))}|||||
|---|---|---|---|---|---|
|
|
{item.actor.username ?? item.actor.user_id ?? "—"} |
|
|
|
|