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,