perf: 优化管理端生产加载体验

- 图标与重型组件按需加载,优化菜单预取和页面请求链路

- 开启 gzip 与静态缓存并修复子路由 KeepAlive 冲突
This commit is contained in:
2026-07-22 20:35:55 +08:00
parent 9f06c238d3
commit 19059fde96
27 changed files with 750 additions and 233 deletions

View File

@@ -213,7 +213,7 @@ const loadProviderDetail = async (
if (!options.keepDraft) {
syncProviderDraft();
}
return;
return undefined;
}
isDetailLoading.value = true;
@@ -234,30 +234,64 @@ const loadProviderDetail = async (
if (!options.keepDraft) {
syncProviderDraft(selectedProvider.value);
}
return res.data;
} else {
ElMessage.error(res.message || $t('ui.actionMessage.operationFailed'));
}
} finally {
isDetailLoading.value = false;
}
return undefined;
};
const refreshProviderCounts = async (list: any[]) => {
const entries = await Promise.all(
list.map(async (provider) => {
let providerCountRequestId = 0;
const PROVIDER_COUNT_CONCURRENCY = 2;
const refreshProviderCounts = async (
list: any[],
excludedProviderId?: string,
) => {
const currentRequestId = ++providerCountRequestId;
const pendingProviders = list.filter(
(provider) => String(provider.id) !== excludedProviderId,
);
const entries: Array<[string, number]> = [];
let cursor = 0;
const worker = async () => {
while (cursor < pendingProviders.length) {
const provider = pendingProviders[cursor++];
const providerId = String(provider.id);
try {
const res = await api.get(
`/api/v1/model/getList?providerId=${provider.id}`,
`/api/v1/model/getList?providerId=${providerId}`,
{},
);
return [provider.id, res.errorCode === 0 ? countModels(res.data) : 0];
entries.push([
providerId,
res.errorCode === 0 ? countModels(res.data) : 0,
]);
} catch {
return [provider.id, 0];
entries.push([providerId, 0]);
}
}),
}
};
await Promise.all(
Array.from(
{
length: Math.min(PROVIDER_COUNT_CONCURRENCY, pendingProviders.length),
},
worker,
),
);
providerCounts.value = Object.fromEntries(entries);
if (currentRequestId === providerCountRequestId) {
providerCounts.value = {
...providerCounts.value,
...Object.fromEntries(entries),
};
}
};
const loadProviders = async (
@@ -272,12 +306,15 @@ const loadProviders = async (
const res = await getLlmProviderList();
const list = res?.data || [];
providers.value = list;
if (refreshCounts) {
await refreshProviderCounts(list);
}
providerCounts.value = Object.fromEntries(
list.map((provider: any) => [
String(provider.id),
providerCounts.value[String(provider.id)] ?? 0,
]),
);
if (list.length === 0) {
providerCountRequestId += 1;
selectedProviderId.value = '';
syncProviderDraft();
syncGroupedModels({});
@@ -300,6 +337,9 @@ const loadProviders = async (
await loadProviderDetail(nextProviderId, {
keepDraft: keepDraft && previousId === nextProviderId,
});
if (refreshCounts) {
void refreshProviderCounts(list, String(nextProviderId));
}
} finally {
isPageLoading.value = false;
}