fix: 修复租户模型获取问题,统一前后端数据结构

This commit is contained in:
xin 2025-05-09 01:32:27 +08:00
parent f52f3b27aa
commit 7bd4ee2a6f

View File

@ -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
}
// storeID
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 || '未知错误'}`)
}
}
}