From 7bd4ee2a6f658a11331ce8edfac10bcf7afbd471 Mon Sep 17 00:00:00 2001 From: xin Date: Fri, 9 May 2025 01:32:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=A7=9F=E6=88=B7?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E8=8E=B7=E5=8F=96=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=89=8D=E5=90=8E=E7=AB=AF=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/views/Model/index.vue | 39 ++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/web/src/views/Model/index.vue b/web/src/views/Model/index.vue index 5286bec..0b85afa 100644 --- a/web/src/views/Model/index.vue +++ b/web/src/views/Model/index.vue @@ -154,10 +154,9 @@ const showTenantModels = async (tenantId: string) => { throw err }) console.log('完整API响应:', JSON.stringify(res, null, 2)) - console.log('响应数据:', res.data) - console.log('响应数据.models:', res.data?.models) - if (res?.data?.models?.models) { - models.value = res.data.models.models.map((m: ModelItem) => ({ + console.log('响应数据:', res) + if (res?.models?.models) { + models.value = res.models.models.map((m: ModelItem) => ({ id: m.id, model_name: m.model_name, provider_name: m.provider_name, @@ -180,8 +179,8 @@ const showTenantModels = async (tenantId: string) => { const handleTenantChange = async (tenantId: string) => { try { const res = await getTenantModels(tenantId) - if (res?.data?.models?.models) { - models.value = res.data.models.models.map((m: ModelItem) => ({ + if (res?.models?.models) { + models.value = res.models.models.map((m: ModelItem) => ({ id: m.id, model_name: m.model_name, provider_name: m.provider_name, @@ -215,15 +214,28 @@ const uploadModel = async () => { const loadModels = async () => { try { + // 检查是否已登录 + const token = localStorage.getItem('access_token') + if (!token) { + ElMessage.warning('请先登录') + window.location.href = '/login' + return + } + // 从store获取当前租户ID const currentTenantId = localStorage.getItem('currentTenantId') if (!currentTenantId) { ElMessage.warning('请先选择租户') return } + const res = await getTenantModels(currentTenantId) - if (res?.data?.models?.models) { - models.value = res.data.models.models.map((m: ModelItem) => ({ + if (!res) { + throw new Error('API返回空响应') + } + + if (res?.models?.models) { + models.value = res.models.models.map((m: ModelItem) => ({ id: m.id, model_name: m.model_name, provider_name: m.provider_name, @@ -233,8 +245,15 @@ const loadModels = async () => { } else { ElMessage.error('获取模型列表失败: 返回数据格式不正确') } - } catch (error) { - ElMessage.error('加载模型列表失败') + } catch (error: any) { + console.error('加载模型列表失败:', error) + if (error.response?.status === 401) { + ElMessage.error('登录已过期,请重新登录') + localStorage.removeItem('access_token') + window.location.href = '/login' + } else { + ElMessage.error(`加载模型列表失败: ${error.message || '未知错误'}`) + } } }