fix: 修复租户模型获取问题,统一前后端数据结构
This commit is contained in:
parent
f52f3b27aa
commit
7bd4ee2a6f
@ -154,10 +154,9 @@ const showTenantModels = async (tenantId: string) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
console.log('完整API响应:', JSON.stringify(res, null, 2))
|
console.log('完整API响应:', JSON.stringify(res, null, 2))
|
||||||
console.log('响应数据:', res.data)
|
console.log('响应数据:', res)
|
||||||
console.log('响应数据.models:', res.data?.models)
|
if (res?.models?.models) {
|
||||||
if (res?.data?.models?.models) {
|
models.value = res.models.models.map((m: ModelItem) => ({
|
||||||
models.value = res.data.models.models.map((m: ModelItem) => ({
|
|
||||||
id: m.id,
|
id: m.id,
|
||||||
model_name: m.model_name,
|
model_name: m.model_name,
|
||||||
provider_name: m.provider_name,
|
provider_name: m.provider_name,
|
||||||
@ -180,8 +179,8 @@ const showTenantModels = async (tenantId: string) => {
|
|||||||
const handleTenantChange = async (tenantId: string) => {
|
const handleTenantChange = async (tenantId: string) => {
|
||||||
try {
|
try {
|
||||||
const res = await getTenantModels(tenantId)
|
const res = await getTenantModels(tenantId)
|
||||||
if (res?.data?.models?.models) {
|
if (res?.models?.models) {
|
||||||
models.value = res.data.models.models.map((m: ModelItem) => ({
|
models.value = res.models.models.map((m: ModelItem) => ({
|
||||||
id: m.id,
|
id: m.id,
|
||||||
model_name: m.model_name,
|
model_name: m.model_name,
|
||||||
provider_name: m.provider_name,
|
provider_name: m.provider_name,
|
||||||
@ -215,15 +214,28 @@ const uploadModel = async () => {
|
|||||||
|
|
||||||
const loadModels = async () => {
|
const loadModels = async () => {
|
||||||
try {
|
try {
|
||||||
|
// 检查是否已登录
|
||||||
|
const token = localStorage.getItem('access_token')
|
||||||
|
if (!token) {
|
||||||
|
ElMessage.warning('请先登录')
|
||||||
|
window.location.href = '/login'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 从store获取当前租户ID
|
// 从store获取当前租户ID
|
||||||
const currentTenantId = localStorage.getItem('currentTenantId')
|
const currentTenantId = localStorage.getItem('currentTenantId')
|
||||||
if (!currentTenantId) {
|
if (!currentTenantId) {
|
||||||
ElMessage.warning('请先选择租户')
|
ElMessage.warning('请先选择租户')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await getTenantModels(currentTenantId)
|
const res = await getTenantModels(currentTenantId)
|
||||||
if (res?.data?.models?.models) {
|
if (!res) {
|
||||||
models.value = res.data.models.models.map((m: ModelItem) => ({
|
throw new Error('API返回空响应')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res?.models?.models) {
|
||||||
|
models.value = res.models.models.map((m: ModelItem) => ({
|
||||||
id: m.id,
|
id: m.id,
|
||||||
model_name: m.model_name,
|
model_name: m.model_name,
|
||||||
provider_name: m.provider_name,
|
provider_name: m.provider_name,
|
||||||
@ -233,8 +245,15 @@ const loadModels = async () => {
|
|||||||
} else {
|
} else {
|
||||||
ElMessage.error('获取模型列表失败: 返回数据格式不正确')
|
ElMessage.error('获取模型列表失败: 返回数据格式不正确')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
ElMessage.error('加载模型列表失败')
|
console.error('加载模型列表失败:', error)
|
||||||
|
if (error.response?.status === 401) {
|
||||||
|
ElMessage.error('登录已过期,请重新登录')
|
||||||
|
localStorage.removeItem('access_token')
|
||||||
|
window.location.href = '/login'
|
||||||
|
} else {
|
||||||
|
ElMessage.error(`加载模型列表失败: ${error.message || '未知错误'}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user