diff --git a/src/stores/log.ts b/src/stores/log.ts index b5a967d..9589db8 100644 --- a/src/stores/log.ts +++ b/src/stores/log.ts @@ -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); diff --git a/src/views/LogView.vue b/src/views/LogView.vue index 887665b..96a1359 100644 --- a/src/views/LogView.vue +++ b/src/views/LogView.vue @@ -46,6 +46,14 @@ {{ expandedAll ? '收起详情' : '展开详情' }} + +