feat(log): 默认不展开详情 + Error详情规范化 + 打印/HTML导出图片
This commit is contained in:
@@ -52,13 +52,37 @@ export const useLogStore = defineStore('log', () => {
|
||||
const ss = now.getSeconds().toString().padStart(2, '0');
|
||||
const ms = now.getMilliseconds().toString().padStart(3, '0');
|
||||
|
||||
// Error 对象属性不可枚举(JSON.stringify 会得到 {}),这里先规范化
|
||||
let normalizedDetail = detail;
|
||||
if (detail instanceof Error) {
|
||||
normalizedDetail = {
|
||||
name: detail.name,
|
||||
message: detail.message,
|
||||
stack: detail.stack,
|
||||
cause: (detail as any).cause,
|
||||
__isError: true,
|
||||
};
|
||||
} else if (detail && typeof detail === 'object') {
|
||||
// 避免 Proxy 等响应式包装的干扰 — 简单浅拷贝为纯对象
|
||||
try {
|
||||
normalizedDetail = JSON.parse(JSON.stringify(detail, (_, v) => {
|
||||
if (v instanceof Error) {
|
||||
return { name: v.name, message: v.message, stack: v.stack, __isError: true };
|
||||
}
|
||||
return v;
|
||||
}));
|
||||
} catch {
|
||||
normalizedDetail = String(detail);
|
||||
}
|
||||
}
|
||||
|
||||
const entry: LogEntry = {
|
||||
id: nextId++,
|
||||
time: `${hh}:${mm}:${ss}.${ms}`,
|
||||
level,
|
||||
module,
|
||||
message,
|
||||
detail,
|
||||
detail: normalizedDetail,
|
||||
};
|
||||
|
||||
logs.value.push(entry);
|
||||
|
||||
Reference in New Issue
Block a user