From 69a80477432148f531b9b8a4cfffee0fd0f7f466 Mon Sep 17 00:00:00 2001 From: Julian Freeman Date: Wed, 25 Mar 2026 18:21:07 -0400 Subject: [PATCH] rebuild logs ui --- src/App.vue | 113 ++++++++++++++++++++++++++++++++--------- src/stores/settings.ts | 5 +- 2 files changed, 93 insertions(+), 25 deletions(-) diff --git a/src/App.vue b/src/App.vue index fc33cf4..c722486 100644 --- a/src/App.vue +++ b/src/App.vue @@ -96,6 +96,26 @@ const copyHistoryText = async (text: string) => { } }; +// Logs Management +const selectedLogId = ref(null); +const selectedLogItem = computed(() => + settings.logs.find(l => l.id === selectedLogId.value) || null +); + +watch(() => settings.logs, (newVal) => { + if (newVal.length > 0 && !selectedLogId.value) { + selectedLogId.value = newVal[0].id; + } +}, { immediate: true }); + +const getLogSummary = (log: any) => { + if (log.type === 'error') return String(log.content); + if (typeof log.content === 'string') return log.content; + if (log.content && log.content.model) return `Model: ${log.content.model}`; + if (log.content && log.content.score) return `Score: ${log.content.score}`; + return 'JSON Data'; +}; + // Profile Management const newProfileName = ref(''); const isSavingProfile = ref(false); @@ -1301,42 +1321,89 @@ const translate = async () => { -
-
-
-

日志

- -
-
-
- 暂无日志记录。请尝试进行翻译。 +
+ +
+
+
+

系统日志

+
-
+ +
+
+ +

暂无日志记录

+
+
-
- [{{ log.timestamp }}] +
{{ log.type === 'request' ? '请求' : log.type === 'response' ? '响应' : '错误' }} + {{ log.timestamp.split(' ')[1] }}
-
{{ typeof log.content === 'object' ? JSON.stringify(log.content, null, 2) : log.content }}
+

{{ getLogSummary(log) }}

+ + +
+ +
+
+ +
+

请从左侧选择一条日志查看详情

+
+
diff --git a/src/stores/settings.ts b/src/stores/settings.ts index b6b6176..312f784 100644 --- a/src/stores/settings.ts +++ b/src/stores/settings.ts @@ -159,7 +159,7 @@ export const useSettingsStore = defineStore('settings', () => { set: (val) => { toneRegisterMap.value[sourceLang.value.code] = val; } }); - const logs = ref<{ timestamp: string; type: 'request' | 'response' | 'error'; content: any }[]>([]); + const logs = ref<{ id: string; timestamp: string; type: 'request' | 'response' | 'error'; content: any }[]>([]); const history = useLocalStorage('translation-history-v1', []); const addLog = (type: 'request' | 'response' | 'error', content: any) => { @@ -167,11 +167,12 @@ export const useSettingsStore = defineStore('settings', () => { const timestamp = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')} ${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}:${String(now.getSeconds()).padStart(2, '0')}`; logs.value.unshift({ + id: crypto.randomUUID(), timestamp, type, content }); - if (logs.value.length > 20) logs.value.pop(); + if (logs.value.length > 50) logs.value.pop(); // 稍微增加日志保留数量 }; const addHistory = (item: Omit) => {