From 660dc62f3c91c7e9229d69b0d851bd0b7e77ba5e Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Mon, 3 Mar 2025 17:35:29 +0800 Subject: [PATCH] fix: Standardize logging component (#8054) --- frontend/src/components/backup/index.vue | 2 +- frontend/src/components/log-dialog/index.vue | 40 --------- .../{compose-log => log/compose}/index.vue | 2 +- .../log/container-drawer}/index.vue | 1 + .../container}/index.vue | 42 +++++---- .../custom-hightlight}/index.vue | 0 frontend/src/components/log/drawer/index.vue | 85 +++++++++++++++++++ .../{log-file => log/file}/index.vue | 11 ++- .../{log-pro => log/hightlight-log}/index.vue | 0 .../{task-log => log/task}/index.vue | 0 .../task}/log-without-dialog.vue | 0 frontend/src/components/task-list/index.vue | 2 +- frontend/src/components/upload/index.vue | 2 +- frontend/src/views/ai/model/index.vue | 2 +- frontend/src/views/app-store/apps/index.vue | 2 +- .../views/app-store/detail/install/index.vue | 2 +- .../app-store/installed/delete/index.vue | 2 +- .../src/views/app-store/installed/index.vue | 4 +- .../app-store/installed/upgrade/index.vue | 2 +- .../views/container/compose/create/index.vue | 2 +- .../views/container/compose/detail/index.vue | 2 +- .../container/container/command/index.vue | 2 +- .../src/views/container/container/index.vue | 2 +- .../container/container/operate/index.vue | 2 +- .../src/views/container/image/build/index.vue | 2 +- .../src/views/container/image/pull/index.vue | 2 +- .../src/views/container/image/push/index.vue | 2 +- frontend/src/views/cronjob/record/index.vue | 2 +- .../views/database/mysql/setting/index.vue | 2 +- .../database/mysql/setting/slow-log/index.vue | 26 +----- .../database/postgresql/setting/index.vue | 2 +- frontend/src/views/log/system/index.vue | 2 +- frontend/src/views/log/task/index.vue | 2 +- frontend/src/views/log/website/index.vue | 2 +- .../views/setting/snapshot/create/index.vue | 2 +- frontend/src/views/setting/snapshot/index.vue | 2 +- .../views/setting/snapshot/recover/index.vue | 2 +- .../views/terminal/terminal/host-create.vue | 1 - .../toolbox/supervisor/config/log/index.vue | 4 +- .../views/website/runtime/dotnet/index.vue | 2 +- .../src/views/website/runtime/go/index.vue | 2 +- .../src/views/website/runtime/java/index.vue | 2 +- .../src/views/website/runtime/node/index.vue | 2 +- .../src/views/website/runtime/php/index.vue | 4 +- .../views/website/runtime/python/index.vue | 2 +- frontend/src/views/website/ssl/index.vue | 4 +- .../website/config/log/log-fiile/index.vue | 2 +- .../views/website/website/create/index.vue | 3 +- .../src/views/website/website/nginx/index.vue | 2 +- .../website/nginx/module/build/index.vue | 2 +- 50 files changed, 163 insertions(+), 130 deletions(-) delete mode 100644 frontend/src/components/log-dialog/index.vue rename frontend/src/components/{compose-log => log/compose}/index.vue (96%) rename frontend/src/{views/container/container/log => components/log/container-drawer}/index.vue (97%) rename frontend/src/components/{container-log => log/container}/index.vue (86%) rename frontend/src/components/{hightlight => log/custom-hightlight}/index.vue (100%) create mode 100644 frontend/src/components/log/drawer/index.vue rename frontend/src/components/{log-file => log/file}/index.vue (97%) rename frontend/src/components/{log-pro => log/hightlight-log}/index.vue (100%) rename frontend/src/components/{task-log => log/task}/index.vue (100%) rename frontend/src/components/{task-log => log/task}/log-without-dialog.vue (100%) diff --git a/frontend/src/components/backup/index.vue b/frontend/src/components/backup/index.vue index 8f858825d..c24892cef 100644 --- a/frontend/src/components/backup/index.vue +++ b/frontend/src/components/backup/index.vue @@ -119,7 +119,7 @@ import i18n from '@/lang'; import { Backup } from '@/api/interface/backup'; import router from '@/routers'; import { MsgSuccess } from '@/utils/message'; -import TaskLog from '@/components/task-log/index.vue'; +import TaskLog from '@/components/log/task/index.vue'; import { GlobalStore } from '@/store'; const globalStore = GlobalStore(); diff --git a/frontend/src/components/log-dialog/index.vue b/frontend/src/components/log-dialog/index.vue deleted file mode 100644 index c2b7e9e2e..000000000 --- a/frontend/src/components/log-dialog/index.vue +++ /dev/null @@ -1,40 +0,0 @@ - - - - diff --git a/frontend/src/components/compose-log/index.vue b/frontend/src/components/log/compose/index.vue similarity index 96% rename from frontend/src/components/compose-log/index.vue rename to frontend/src/components/log/compose/index.vue index 1a7c4b907..3d5c4a484 100644 --- a/frontend/src/components/compose-log/index.vue +++ b/frontend/src/components/log/compose/index.vue @@ -22,7 +22,7 @@ import i18n from '@/lang'; import { computed, onBeforeUnmount, ref, watch } from 'vue'; import { GlobalStore } from '@/store'; import screenfull from 'screenfull'; -import ContainerLog from '@/components/container-log/index.vue'; +import ContainerLog from '@/components/log/container/index.vue'; const open = ref(false); const resource = ref(''); diff --git a/frontend/src/views/container/container/log/index.vue b/frontend/src/components/log/container-drawer/index.vue similarity index 97% rename from frontend/src/views/container/container/log/index.vue rename to frontend/src/components/log/container-drawer/index.vue index fb0e6b78c..706b8429f 100644 --- a/frontend/src/views/container/container/log/index.vue +++ b/frontend/src/components/log/container-drawer/index.vue @@ -27,6 +27,7 @@ import i18n from '@/lang'; import { computed, onBeforeUnmount, reactive, ref, watch } from 'vue'; import screenfull from 'screenfull'; import { GlobalStore } from '@/store'; +import ContainerLog from '@/components/log/container/index.vue'; const logVisible = ref(false); const mobile = computed(() => { diff --git a/frontend/src/components/container-log/index.vue b/frontend/src/components/log/container/index.vue similarity index 86% rename from frontend/src/components/container-log/index.vue rename to frontend/src/components/log/container/index.vue index 1edd45d92..71e018d21 100644 --- a/frontend/src/components/container-log/index.vue +++ b/frontend/src/components/log/container/index.vue @@ -24,16 +24,6 @@ {{ $t('commons.button.clean') }} - -
logs.value.length); const totalHeight = computed(() => logHeight * logCount.value); const startIndex = ref(0); const containerHeight = ref(500); -const visibleCount = computed(() => Math.ceil(containerHeight.value / logHeight)); +const visibleCount = computed(() => Math.ceil(containerHeight.value / logHeight) + 2); const visibleLogs = computed(() => { - return logs.value.slice(startIndex.value, startIndex.value + visibleCount.value); + const start = Math.max(0, startIndex.value - 1); + const end = startIndex.value + visibleCount.value + 1; + return logs.value.slice(start, end); }); const timeOptions = ref([ @@ -185,10 +177,22 @@ const onClean = async () => { }); }; +const handleScroll = () => { + if (logContainer.value) { + const scrollTop = logContainer.value.scrollTop; + startIndex.value = Math.max(0, Math.floor(scrollTop / logHeight) - 1); + } +}; + onUnmounted(() => { handleClose(); + if (logContainer.value) { + logContainer.value.removeEventListener('scroll', handleScroll); + } }); +const resizeObserver = ref(null); + onMounted(() => { logSearch.container = props.container; logSearch.compose = props.compose; @@ -200,8 +204,12 @@ onMounted(() => { nextTick(() => { if (logContainer.value) { - logContainer.value.scrollTop = totalHeight.value; - containerHeight.value = logContainer.value.getBoundingClientRect().height; + containerHeight.value = logContainer.value.clientHeight; + logContainer.value.addEventListener('scroll', handleScroll); + resizeObserver.value = new ResizeObserver((entries) => { + containerHeight.value = entries[0].contentRect.height; + }); + resizeObserver.value.observe(logContainer.value); } }); @@ -227,7 +235,7 @@ onMounted(() => { } .log-container { - height: calc(100vh - 405px); + height: calc(100vh - 320px); overflow-y: auto; overflow-x: auto; position: relative; diff --git a/frontend/src/components/hightlight/index.vue b/frontend/src/components/log/custom-hightlight/index.vue similarity index 100% rename from frontend/src/components/hightlight/index.vue rename to frontend/src/components/log/custom-hightlight/index.vue diff --git a/frontend/src/components/log/drawer/index.vue b/frontend/src/components/log/drawer/index.vue new file mode 100644 index 000000000..8d2bcbb2d --- /dev/null +++ b/frontend/src/components/log/drawer/index.vue @@ -0,0 +1,85 @@ + + + + diff --git a/frontend/src/components/log-file/index.vue b/frontend/src/components/log/file/index.vue similarity index 97% rename from frontend/src/components/log-file/index.vue rename to frontend/src/components/log/file/index.vue index 3cf1d563f..df8f4e802 100644 --- a/frontend/src/components/log-file/index.vue +++ b/frontend/src/components/log/file/index.vue @@ -17,7 +17,7 @@
-
+
{ await getContent(false); }; +const containerStyle = computed(() => ({ + height: `calc(100vh - ${props.heightDiff}px)`, +})); + onMounted(async () => { firstLoading.value = true; await init(); @@ -330,7 +334,6 @@ defineExpose({ changeTail, onDownload, clearLog });