From 1b8c60260603f611ff773c8447df69d3df3a0d36 Mon Sep 17 00:00:00 2001 From: lan-yonghui Date: Wed, 22 Apr 2026 15:54:56 +0800 Subject: [PATCH] refactor: simplify pagination logic and update theme change listener --- .../src/components/complex-table/index.vue | 8 +--- frontend/src/global/use-theme.ts | 11 +++--- .../code-editor/history/index.vue | 37 +++---------------- 3 files changed, 12 insertions(+), 44 deletions(-) diff --git a/frontend/src/components/complex-table/index.vue b/frontend/src/components/complex-table/index.vue index b4372b680cd9..3579e28544ba 100644 --- a/frontend/src/components/complex-table/index.vue +++ b/frontend/src/components/complex-table/index.vue @@ -213,13 +213,7 @@ const responsivePaginationLayout = computed(() => { }); const responsivePagerCount = computed(() => { - if (mobile.value || props.paginationConfig?.small) { - return 5; - } - if (paginationWidth.value < 520) { - return 3; - } - if (paginationWidth.value < 720) { + if (mobile.value || props.paginationConfig?.small || paginationWidth.value < 720) { return 5; } return 7; diff --git a/frontend/src/global/use-theme.ts b/frontend/src/global/use-theme.ts index 541664e4d646..e072eb9a2fae 100644 --- a/frontend/src/global/use-theme.ts +++ b/frontend/src/global/use-theme.ts @@ -1,4 +1,4 @@ -import { onUnmounted } from 'vue'; +import { getCurrentScope, onScopeDispose } from 'vue'; import { GlobalStore } from '@/store'; import { setPrimaryColor } from '@/utils/theme'; @@ -27,7 +27,6 @@ export const useTheme = () => { } }; - // Listen for OS theme changes when theme is set to "auto" const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)'); const onSystemThemeChange = () => { const globalStore = GlobalStore(); @@ -36,9 +35,11 @@ export const useTheme = () => { } }; mediaQuery.addEventListener('change', onSystemThemeChange); - onUnmounted(() => { - mediaQuery.removeEventListener('change', onSystemThemeChange); - }); + if (getCurrentScope()) { + onScopeDispose(() => { + mediaQuery.removeEventListener('change', onSystemThemeChange); + }); + } return { switchTheme, diff --git a/frontend/src/views/host/file-management/code-editor/history/index.vue b/frontend/src/views/host/file-management/code-editor/history/index.vue index b78f41145d0c..917a22c35895 100644 --- a/frontend/src/views/host/file-management/code-editor/history/index.vue +++ b/frontend/src/views/host/file-management/code-editor/history/index.vue @@ -102,7 +102,7 @@
- - + - +
- -
@@ -235,8 +220,8 @@ import { Setting } from '@/api/interface/setting'; import { loadMonacoLanguageSupport, setupMonacoEnvironment } from '@/utils/monaco'; import { ElMessageBox, type FormInstance, type FormRules } from 'element-plus'; import { Languages } from '@/global/mimetype'; -import { GlobalStore } from '@/store'; import i18n from '@/lang'; +import ComplexTable from '@/components/complex-table/index.vue'; type MonacoEditorApi = typeof import('monaco-editor/esm/vs/editor/editor.api'); @@ -258,10 +243,7 @@ const historySettingFormRef = ref(); const scope = ref<'current' | 'all'>('current'); const operationFilter = ref(''); const activeCollapse = ref([]); -const globalStore = GlobalStore(); -const mobile = computed(() => { - return globalStore.isMobile(); -}); + const paginationConfig = reactive({ cacheSizeKey: 'file-history-page-size', currentPage: 1, @@ -602,15 +584,6 @@ const handleScopeChange = async () => { await loadHistoryList(true); }; -const handlePageChange = async (page: number) => { - pagination.value.currentPage = page; - await loadHistoryList(); -}; - -const handleSizeChange = async () => { - await loadHistoryList(true); -}; - const handleClose = () => { drawerVisible.value = false; disposeDiffEditor();