perf(admin): 实现切页即时导航与列表 loading 壳
非阻塞 session 刷新、侧边栏 chunk 预取、KeepAlive 对齐,以及按 tab 延迟加载重型列表页。
This commit is contained in:
@@ -50,11 +50,13 @@ const creditItems = ref<CreditTxRow[]>([]);
|
||||
const creditTotal = ref(0);
|
||||
const creditPage = ref(1);
|
||||
const creditPageSize = ref(10);
|
||||
const creditLoading = ref(false);
|
||||
|
||||
const transferItems = ref<TransferTxRow[]>([]);
|
||||
const transferTotal = ref(0);
|
||||
const transferPage = ref(1);
|
||||
const transferPageSize = ref(10);
|
||||
const transferLoading = ref(false);
|
||||
|
||||
const keyword = ref('');
|
||||
const agentId = ref('');
|
||||
@@ -125,7 +127,9 @@ function dateParams() {
|
||||
};
|
||||
}
|
||||
|
||||
async function loadCredit() {
|
||||
async function loadCredit(opts?: { silent?: boolean }) {
|
||||
if (!opts?.silent) creditLoading.value = true;
|
||||
try {
|
||||
const { data } = await api.get(creditApiPath.value, {
|
||||
params: {
|
||||
page: creditPage.value,
|
||||
@@ -139,9 +143,14 @@ async function loadCredit() {
|
||||
});
|
||||
creditItems.value = (data.data?.items ?? []) as CreditTxRow[];
|
||||
creditTotal.value = data.data?.total ?? 0;
|
||||
} finally {
|
||||
if (!opts?.silent) creditLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadTransfer() {
|
||||
async function loadTransfer(opts?: { silent?: boolean }) {
|
||||
if (!opts?.silent) transferLoading.value = true;
|
||||
try {
|
||||
const parentRaw = parentAgentKeyword.value.trim();
|
||||
const parentIsId = parentRaw && /^\d+$/.test(parentRaw);
|
||||
const { data } = await api.get(transferApiPath.value, {
|
||||
@@ -157,6 +166,9 @@ async function loadTransfer() {
|
||||
});
|
||||
transferItems.value = (data.data?.items ?? []) as TransferTxRow[];
|
||||
transferTotal.value = data.data?.total ?? 0;
|
||||
} finally {
|
||||
if (!opts?.silent) transferLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function onSearch() {
|
||||
@@ -206,10 +218,9 @@ onMounted(() => {
|
||||
if (activeTab.value === 'credit') void loadCredit();
|
||||
else void loadTransfer();
|
||||
});
|
||||
// KeepAlive 激活时静默刷新
|
||||
onActivated(() => {
|
||||
if (activeTab.value === 'credit' && creditItems.value.length > 0) void loadCredit();
|
||||
else if (activeTab.value === 'transfer' && transferItems.value.length > 0) void loadTransfer();
|
||||
if (activeTab.value === 'credit' && creditItems.value.length > 0) void loadCredit({ silent: true });
|
||||
else if (activeTab.value === 'transfer' && transferItems.value.length > 0) void loadTransfer({ silent: true });
|
||||
});
|
||||
|
||||
watch(
|
||||
@@ -321,7 +332,7 @@ watch(
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<el-card v-show="activeTab === 'credit'" class="data-card" shadow="never">
|
||||
<el-card v-show="activeTab === 'credit'" v-loading="creditLoading" class="data-card" shadow="never">
|
||||
<div class="table-wrap">
|
||||
<el-table :key="`${locale}-credit`" :data="creditItems" stripe>
|
||||
<template #empty>
|
||||
@@ -392,7 +403,7 @@ watch(
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<el-card v-show="activeTab === 'transfer'" class="data-card" shadow="never">
|
||||
<el-card v-show="activeTab === 'transfer'" v-loading="transferLoading" class="data-card" shadow="never">
|
||||
<div class="table-wrap">
|
||||
<el-table :key="`${locale}-transfer`" :data="transferItems" stripe>
|
||||
<template #empty>
|
||||
|
||||
Reference in New Issue
Block a user