From 6a0ffa441143e4d8b8f6558f75fa5eff09b68815 Mon Sep 17 00:00:00 2001 From: Rewrite0 Date: Fri, 8 Mar 2024 11:05:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=97=A5=E5=BF=97=E7=9D=80=E8=89=B2=20?= =?UTF-8?q?&=20=E6=97=A5=E5=BF=97=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=9B=B4=E6=94=B9=E4=B8=BA=2010s=20&=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=AB=8B=E5=8D=B3=E6=9B=B4=E6=96=B0=E6=97=A5=E5=BF=97=E6=8C=89?= =?UTF-8?q?=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webui/src/i18n/en.json | 3 +- webui/src/i18n/zh-CN.json | 3 +- webui/src/pages/index/log.vue | 76 +++++++++++++++++++++++++++++++++-- webui/src/store/log.ts | 6 +-- 4 files changed, 80 insertions(+), 8 deletions(-) diff --git a/webui/src/i18n/en.json b/webui/src/i18n/en.json index 03537a69..86fdc7c4 100644 --- a/webui/src/i18n/en.json +++ b/webui/src/i18n/en.json @@ -98,7 +98,8 @@ "go": "Go", "join": "Join", "reset": "Reset", - "title": "Log" + "title": "Log", + "update_now": "Update Now" }, "login": { "login_btn": "Login", diff --git a/webui/src/i18n/zh-CN.json b/webui/src/i18n/zh-CN.json index a8efc40b..08a1e0a2 100644 --- a/webui/src/i18n/zh-CN.json +++ b/webui/src/i18n/zh-CN.json @@ -98,7 +98,8 @@ "go": "访问", "join": "加入", "reset": "重置", - "title": "日志" + "title": "日志", + "update_now": "立即更新" }, "login": { "login_btn": "登录", diff --git a/webui/src/pages/index/log.vue b/webui/src/pages/index/log.vue index e6fb5792..e50b6a3f 100644 --- a/webui/src/pages/index/log.vue +++ b/webui/src/pages/index/log.vue @@ -3,12 +3,57 @@ definePage({ name: 'Log', }); -const { onUpdate, offUpdate, reset, copy } = useLogStore(); +const { onUpdate, offUpdate, reset, copy, getLog } = useLogStore(); const { log } = storeToRefs(useLogStore()); const { version } = useAppInfo(); +const formatLog = computed(() => { + const list = log.value + .trim() + .split('\n') + .filter((i) => i !== ''); + const startIndex = list.findIndex((i) => /Version/.test(i)); + + return list.slice(startIndex === -1 ? 0 : startIndex).map((i, index) => { + const date = i.match(/\[\d+-\d+-\d+\ \d+:\d+:\d+\]/)?.[0] || ''; + const type = i.match(/(INFO)|(WARNING)|(ERROR)|(DEBUG)/)?.[0] || ''; + const content = i.replace(date, '').replace(`${type}:`, '').trim(); + + return { + index, + date, + type, + content, + }; + }); +}); + +function typeColor(type: string) { + const M = { + INFO: '#4e3c94', + WARNING: '#A76E18', + ERROR: '#C70E0E', + DEBUG: '#A0A0A0', + }; + return M[type]; +} + +const logContainer = ref(null); + +function backToBottom() { + if (logContainer.value) { + logContainer.value.scrollTop = logContainer.value.scrollHeight; + } +} + onActivated(() => { onUpdate(); + + watchOnce(log, () => { + nextTick(() => { + backToBottom(); + }); + }); }); onDeactivated(() => { @@ -20,11 +65,36 @@ onDeactivated(() => {
-
-
{{ log }}
+
+ +
+ + {{ $t('log.update_now') }} + + {{ $t('log.reset') }} diff --git a/webui/src/store/log.ts b/webui/src/store/log.ts index 80de37dc..2af37444 100644 --- a/webui/src/store/log.ts +++ b/webui/src/store/log.ts @@ -5,7 +5,7 @@ export const useLogStore = defineStore('log', () => { const log = ref(''); - function get() { + function getLog() { if (isLoggedIn.value) { apiLog.getLog().then((res) => { log.value = res; @@ -20,7 +20,7 @@ export const useLogStore = defineStore('log', () => { }, }); - const { pause: offUpdate, resume: onUpdate } = useIntervalFn(get, 3000, { + const { pause: offUpdate, resume: onUpdate } = useIntervalFn(getLog, 10000, { immediate: false, immediateCallback: true, }); @@ -37,7 +37,7 @@ export const useLogStore = defineStore('log', () => { return { log, - get, + getLog, reset, onUpdate, offUpdate,