fix(ui): 模型列表加载与工作区状态解耦

loadInitialData 先请求 /api/status 再拉取模型列表,未创建工作区时
status 503 导致 fetchModels 不执行、模型选择器为空。现将 fetchModels
提前到 status 请求之前,无工作区也能看到已配置的模型。
This commit is contained in:
JOJO 2026-07-29 23:21:13 +08:00
parent 72f6a9e8e8
commit a0ea599c05

View File

@ -228,6 +228,13 @@ export const socketMethods = {
try { try {
debugLog('加载初始数据...'); debugLog('加载初始数据...');
// 模型列表与工作区状态解耦:即使 /api/status 不可用(如尚未创建工作区),
// 也要先加载已配置的模型,保证模型选择器可用
const modelStore = useModelStore();
await modelStore.fetchModels().catch((err) => {
console.warn('加载模型列表失败,使用前端默认列表:', err);
});
const statusResponse = await fetch('/api/status'); const statusResponse = await fetch('/api/status');
if (!statusResponse.ok) { if (!statusResponse.ok) {
throw new Error(`状态接口请求失败: ${statusResponse.status}`); throw new Error(`状态接口请求失败: ${statusResponse.status}`);
@ -243,10 +250,6 @@ export const socketMethods = {
this.fetchPendingToolApprovals(); this.fetchPendingToolApprovals();
// 立即更新配额和运行模式,避免等待其他慢接口 // 立即更新配额和运行模式,避免等待其他慢接口
this.fetchUsageQuota(); this.fetchUsageQuota();
const modelStore = useModelStore();
await modelStore.fetchModels().catch((err) => {
console.warn('加载模型列表失败,使用前端默认列表:', err);
});
if (statusData && typeof statusData.model_key === 'string') { if (statusData && typeof statusData.model_key === 'string') {
modelStore.setModel(statusData.model_key); modelStore.setModel(statusData.model_key);
this.currentModelKey = modelStore.currentModelKey; this.currentModelKey = modelStore.currentModelKey;