perf(admin): 实现切页即时导航与列表 loading 壳
非阻塞 session 刷新、侧边栏 chunk 预取、KeepAlive 对齐,以及按 tab 延迟加载重型列表页。
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, watch } from 'vue';
|
||||
defineOptions({ name: 'AdminMediaLibrary' });
|
||||
|
||||
import { ref, computed, onMounted, onActivated, watch } from 'vue';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import { useAdminLocale } from '../composables/useAdminLocale';
|
||||
import api from '../api';
|
||||
@@ -54,8 +56,8 @@ function formatDate(iso: string) {
|
||||
return new Date(iso).toLocaleString();
|
||||
}
|
||||
|
||||
async function loadFiles() {
|
||||
loading.value = true;
|
||||
async function loadFiles(opts?: { silent?: boolean }) {
|
||||
if (!opts?.silent) loading.value = true;
|
||||
try {
|
||||
const params: Record<string, string | number> = { page: currentPage.value, pageSize };
|
||||
if (activeCategory.value) params.category = activeCategory.value;
|
||||
@@ -65,7 +67,7 @@ async function loadFiles() {
|
||||
} catch {
|
||||
ElMessage.error(t('common.loading'));
|
||||
} finally {
|
||||
loading.value = false;
|
||||
if (!opts?.silent) loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,9 +76,14 @@ watch(activeCategory, () => {
|
||||
loadFiles();
|
||||
});
|
||||
|
||||
watch(currentPage, loadFiles);
|
||||
watch(currentPage, () => {
|
||||
void loadFiles();
|
||||
});
|
||||
|
||||
onMounted(loadFiles);
|
||||
onMounted(() => void loadFiles());
|
||||
onActivated(() => {
|
||||
if (files.value.length > 0) void loadFiles({ silent: true });
|
||||
});
|
||||
|
||||
async function confirmDelete(file: MediaFile) {
|
||||
await ElMessageBox.confirm(t('media.delete_confirm'), { type: 'warning' });
|
||||
|
||||
Reference in New Issue
Block a user