Skip to content

Commit 1b8c602

Browse files
committed
refactor: simplify pagination logic and update theme change listener
1 parent 92598ef commit 1b8c602

3 files changed

Lines changed: 12 additions & 44 deletions

File tree

frontend/src/components/complex-table/index.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,7 @@ const responsivePaginationLayout = computed(() => {
213213
});
214214
215215
const responsivePagerCount = computed(() => {
216-
if (mobile.value || props.paginationConfig?.small) {
217-
return 5;
218-
}
219-
if (paginationWidth.value < 520) {
220-
return 3;
221-
}
222-
if (paginationWidth.value < 720) {
216+
if (mobile.value || props.paginationConfig?.small || paginationWidth.value < 720) {
223217
return 5;
224218
}
225219
return 7;

frontend/src/global/use-theme.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { onUnmounted } from 'vue';
1+
import { getCurrentScope, onScopeDispose } from 'vue';
22
import { GlobalStore } from '@/store';
33
import { setPrimaryColor } from '@/utils/theme';
44

@@ -27,7 +27,6 @@ export const useTheme = () => {
2727
}
2828
};
2929

30-
// Listen for OS theme changes when theme is set to "auto"
3130
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
3231
const onSystemThemeChange = () => {
3332
const globalStore = GlobalStore();
@@ -36,9 +35,11 @@ export const useTheme = () => {
3635
}
3736
};
3837
mediaQuery.addEventListener('change', onSystemThemeChange);
39-
onUnmounted(() => {
40-
mediaQuery.removeEventListener('change', onSystemThemeChange);
41-
});
38+
if (getCurrentScope()) {
39+
onScopeDispose(() => {
40+
mediaQuery.removeEventListener('change', onSystemThemeChange);
41+
});
42+
}
4243

4344
return {
4445
switchTheme,

frontend/src/views/host/file-management/code-editor/history/index.vue

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102

103103
<div class="table-box history-table-box">
104104
<div class="history-table-wrap">
105-
<el-table
105+
<ComplexTable
106106
:pagination-config="paginationConfig"
107107
:data="historyItems"
108108
v-loading="historyLoading"
@@ -142,7 +142,7 @@
142142
{{ computeSize(row.contentSize) }}
143143
</template>
144144
</el-table-column>
145-
<el-table-column :label="$t('commons.table.operate')" min-width="110" fixed="right">
145+
<el-table-column :label="$t('commons.table.operate')" min-width="150" fixed="right">
146146
<template #default="{ row }">
147147
<el-button link type="primary" @click.stop="openHistoryRecord(row)">
148148
{{ $t('commons.button.view') }}
@@ -152,23 +152,8 @@
152152
</el-button>
153153
</template>
154154
</el-table-column>
155-
</el-table>
155+
</ComplexTable>
156156
</div>
157-
158-
<el-pagination
159-
v-model:current-page="pagination.currentPage"
160-
v-model:page-size="pagination.pageSize"
161-
:page-sizes="[5, 10, 20, 50, 100, 200, 500]"
162-
:size="mobile || paginationConfig.small ? 'small' : 'default'"
163-
:layout="
164-
mobile || paginationConfig.small
165-
? 'total, prev, pager, next'
166-
: 'total, sizes, prev, pager, next, jumper'
167-
"
168-
:total="pagination.total"
169-
@current-change="handlePageChange"
170-
@size-change="handleSizeChange"
171-
/>
172157
</div>
173158
</el-card>
174159

@@ -235,8 +220,8 @@ import { Setting } from '@/api/interface/setting';
235220
import { loadMonacoLanguageSupport, setupMonacoEnvironment } from '@/utils/monaco';
236221
import { ElMessageBox, type FormInstance, type FormRules } from 'element-plus';
237222
import { Languages } from '@/global/mimetype';
238-
import { GlobalStore } from '@/store';
239223
import i18n from '@/lang';
224+
import ComplexTable from '@/components/complex-table/index.vue';
240225
241226
type MonacoEditorApi = typeof import('monaco-editor/esm/vs/editor/editor.api');
242227
@@ -258,10 +243,7 @@ const historySettingFormRef = ref<FormInstance>();
258243
const scope = ref<'current' | 'all'>('current');
259244
const operationFilter = ref('');
260245
const activeCollapse = ref([]);
261-
const globalStore = GlobalStore();
262-
const mobile = computed(() => {
263-
return globalStore.isMobile();
264-
});
246+
265247
const paginationConfig = reactive({
266248
cacheSizeKey: 'file-history-page-size',
267249
currentPage: 1,
@@ -602,15 +584,6 @@ const handleScopeChange = async () => {
602584
await loadHistoryList(true);
603585
};
604586
605-
const handlePageChange = async (page: number) => {
606-
pagination.value.currentPage = page;
607-
await loadHistoryList();
608-
};
609-
610-
const handleSizeChange = async () => {
611-
await loadHistoryList(true);
612-
};
613-
614587
const handleClose = () => {
615588
drawerVisible.value = false;
616589
disposeDiffEditor();

0 commit comments

Comments
 (0)