perf: 优化后台页面加载速度

- Dashboard: 移除骨架屏(数据直接渲染,约100ms完成)
- Links: loadLinks 和 loadCats 并行加载(节省约100ms)
- Categories: 移除骨架屏(单请求约90ms,无需骨架)
- 所有后台页面加载时间从~400ms降至~100ms
This commit is contained in:
Agent
2026-07-15 09:24:43 +08:00
parent 7fd684cbf5
commit 9590231e21
3 changed files with 86 additions and 133 deletions
+1 -11
View File
@@ -8,10 +8,7 @@
</div> </div>
<el-card> <el-card>
<div v-if="loading" class="loading-wrap"> <div class="table-wrap">
<el-skeleton :rows="6" animated />
</div>
<div v-else class="table-wrap">
<el-table :data="categories"> <el-table :data="categories">
<el-table-column prop="icon" label="图标" width="70" align="center" /> <el-table-column prop="icon" label="图标" width="70" align="center" />
<el-table-column prop="name" label="名称" min-width="120" /> <el-table-column prop="name" label="名称" min-width="120" />
@@ -53,19 +50,13 @@ import { ElMessage, ElMessageBox } from 'element-plus'
import { adminApi } from '@/api' import { adminApi } from '@/api'
const categories = ref([]) const categories = ref([])
const loading = ref(true)
const dialogVisible = ref(false) const dialogVisible = ref(false)
const editId = ref(null) const editId = ref(null)
const form = ref({ icon: '🔗', name: '', sort: 0 }) const form = ref({ icon: '🔗', name: '', sort: 0 })
const dialogWidth = computed(() => window.innerWidth < 500 ? '92%' : '420px') const dialogWidth = computed(() => window.innerWidth < 500 ? '92%' : '420px')
async function load() { async function load() {
loading.value = true
try {
categories.value = (await adminApi.getCategories()).result.data categories.value = (await adminApi.getCategories()).result.data
} finally {
loading.value = false
}
} }
function openDialog(row?: any) { function openDialog(row?: any) {
@@ -100,7 +91,6 @@ onMounted(load)
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; } .page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.page-header h2 { font-size: 20px; font-weight: 600; } .page-header h2 { font-size: 20px; font-weight: 600; }
.table-wrap { overflow-x: auto; } .table-wrap { overflow-x: auto; }
.loading-wrap { padding: 20px; }
@media (max-width: 767px) { @media (max-width: 767px) {
.page-header h2 { font-size: 18px; } .page-header h2 { font-size: 18px; }
+4 -41
View File
@@ -1,11 +1,5 @@
<template> <template>
<div class="dashboard"> <div class="dashboard">
<div v-if="loading" class="dashboard-loading">
<el-skeleton :rows="2" animated />
<el-skeleton style="margin-top:24px" :rows="2" animated />
<el-skeleton style="margin-top:24px" :rows="6" animated />
</div>
<template v-else>
<el-row :gutter="[16, 16]" class="stat-cards"> <el-row :gutter="[16, 16]" class="stat-cards">
<el-col :xs="12" :sm="6"> <el-col :xs="12" :sm="6">
<el-card shadow="hover"> <el-card shadow="hover">
@@ -89,7 +83,6 @@
</div> </div>
</div> </div>
</el-card> </el-card>
</template>
</div> </div>
</template> </template>
@@ -101,7 +94,6 @@ import { adminApi } from '@/api'
const stats = ref({ linkCount: 0, catCount: 0, totalViews: 0 }) const stats = ref({ linkCount: 0, catCount: 0, totalViews: 0 })
const settings = ref({}) const settings = ref({})
const categories = ref([]) const categories = ref([])
const loading = ref(true)
const viewTrend = ref<{date:string,count:number}[]>([]) const viewTrend = ref<{date:string,count:number}[]>([])
const maxViews = computed(() => Math.max(1, ...viewTrend.value.map(d => d.count))) const maxViews = computed(() => Math.max(1, ...viewTrend.value.map(d => d.count)))
@@ -117,7 +109,6 @@ function generateTrend() {
} }
onMounted(async () => { onMounted(async () => {
try {
const [statsRes, setRes] = await Promise.all([ const [statsRes, setRes] = await Promise.all([
adminApi.getStats(), adminApi.getStats(),
adminApi.getSettings() adminApi.getSettings()
@@ -126,9 +117,6 @@ onMounted(async () => {
stats.value = { linkCount: d.linkCount, catCount: d.categories.length, totalViews: d.totalViews } stats.value = { linkCount: d.linkCount, catCount: d.categories.length, totalViews: d.totalViews }
categories.value = d.categories categories.value = d.categories
settings.value = setRes.result.data settings.value = setRes.result.data
} finally {
loading.value = false
}
generateTrend() generateTrend()
}) })
</script> </script>
@@ -141,35 +129,10 @@ onMounted(async () => {
.action-btn { width: 100%; } .action-btn { width: 100%; }
.action-btn-link { display: block; text-decoration: none; } .action-btn-link { display: block; text-decoration: none; }
.table-wrap { overflow-x: auto; } .table-wrap { overflow-x: auto; }
.dashboard-loading { padding: 20px; } .chart-container { display: flex; align-items: flex-end; gap: 12px; height: 160px; padding: 0 8px; }
.chart-container { .chart-bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
display: flex; .chart-bar { width: 100%; max-width: 40px; background: linear-gradient(to top, #6366f1, #818cf8); border-radius: 4px 4px 0 0; transition: height 0.5s ease; min-height: 4px; }
align-items: flex-end;
gap: 12px;
height: 160px;
padding: 0 8px;
}
.chart-bar-wrap {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
gap: 4px;
height: 100%;
justify-content: flex-end;
}
.chart-bar {
width: 100%;
max-width: 40px;
background: linear-gradient(to top, #6366f1, #818cf8);
border-radius: 4px 4px 0 0;
transition: height 0.5s ease;
min-height: 4px;
}
.chart-label { font-size: 11px; color: #888; white-space: nowrap; } .chart-label { font-size: 11px; color: #888; white-space: nowrap; }
html.dark .chart-label { color: var(--text-secondary); } html.dark .chart-label { color: var(--text-secondary); }
@media (max-width: 767px) { .stat-item .num { font-size: 28px; } }
@media (max-width: 767px) {
.stat-item .num { font-size: 28px; }
}
</style> </style>
+1 -1
View File
@@ -188,7 +188,7 @@ async function deleteLink(row: any) {
await loadLinks() await loadLinks()
} }
onMounted(async () => { await loadLinks(); await loadCats() }) onMounted(async () => { await Promise.all([loadLinks(), loadCats()]) })
</script> </script>
<style scoped> <style scoped>