立项配置数据入库、审计日志数据入库、编辑页UI界面美化、设备管理内容补充、审计日志显示优化
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import { auditDict } from "./auditDict";
|
||||
import { roleDict, getDictLabel, statusDict } from "../dictionaries";
|
||||
import { useAuthStore } from "../store/auth";
|
||||
import { useStudyStore } from "../store/study";
|
||||
import { TEXT } from "../locales";
|
||||
|
||||
export interface AuditEvent {
|
||||
@@ -250,47 +248,9 @@ export const normalizeAuditEvent = (raw: any, userMap: Record<string, string>):
|
||||
|
||||
export { auditDict };
|
||||
|
||||
const LOCAL_KEY_PREFIX = "audit_local_";
|
||||
const getLocalKey = (studyId?: string | null) => `${LOCAL_KEY_PREFIX}${studyId || "global"}`;
|
||||
|
||||
const appendLocalAudit = (studyId: string | null, log: any) => {
|
||||
try {
|
||||
const key = getLocalKey(studyId);
|
||||
const existingRaw = localStorage.getItem(key);
|
||||
const existing = existingRaw ? JSON.parse(existingRaw) : [];
|
||||
existing.unshift(log);
|
||||
localStorage.setItem(key, JSON.stringify(existing.slice(0, 200)));
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
};
|
||||
|
||||
// 前端占位的 logAudit:不修改后端接口,落地到本地存储,失败不影响主流程
|
||||
// Deprecated: keep API-compatible no-op to avoid accidental reliance on browser local storage.
|
||||
export const logAudit = async (eventType: string, payload: Record<string, any>) => {
|
||||
try {
|
||||
const auth = useAuthStore();
|
||||
const study = useStudyStore();
|
||||
const user = auth.user;
|
||||
const studyId = study.currentStudy?.id || null;
|
||||
const log = {
|
||||
action: eventType,
|
||||
operator_id: user?.id || user?.username || TEXT.audit.currentUser,
|
||||
operator_role: user?.role || "",
|
||||
entity_type: payload.targetType || TEXT.audit.localClient,
|
||||
entity_id: payload.targetId || "",
|
||||
created_at: new Date().toISOString(),
|
||||
detail: JSON.stringify({
|
||||
targetName: payload.targetName,
|
||||
before: payload.before,
|
||||
after: payload.after,
|
||||
reason: payload.reason,
|
||||
severity: payload.severity,
|
||||
result: payload.severity === "normal" ? "SUCCESS" : "FAIL",
|
||||
}),
|
||||
};
|
||||
appendLocalAudit(studyId, log);
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
void eventType;
|
||||
void payload;
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user