mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-03 01:40:21 +08:00
refactor(frontend): 优化模型/提供商组件的数据刷新逻辑
- ModelDetailDrawer: 移除 handleMappingsUpdate 中冗余的 refreshRoutingData 调用,路由刷新改由 @refresh 事件统一处理
- ModelMappingsTab: saveMappings 成功后始终 emit update 和 refresh 事件,确保数据一致性
- BatchAssignModelsDialog: 为批量添加/导入操作增加 try-catch 错误处理,部分操作失败时仍通知父组件刷新
- ProviderDetailDrawer: 移除 modelsTabRef 直接调用子组件 reload 的模式,统一通过 emit('refresh') 由父组件协调刷新
This commit is contained in:
@@ -560,9 +560,7 @@ function refreshRoutingData() {
|
|||||||
// 处理模型映射更新
|
// 处理模型映射更新
|
||||||
function handleMappingsUpdate(_mappings: string[]) {
|
function handleMappingsUpdate(_mappings: string[]) {
|
||||||
// 映射已在 ModelMappingsTab 内部保存到服务器
|
// 映射已在 ModelMappingsTab 内部保存到服务器
|
||||||
// 刷新路由数据以反映可能的候选变化
|
// 路由数据刷新由 @refresh 事件处理,这里只需通知父组件刷新模型数据
|
||||||
refreshRoutingData()
|
|
||||||
// 通知父组件刷新模型数据
|
|
||||||
emit('refreshModel')
|
emit('refreshModel')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -531,12 +531,14 @@ async function saveMappings() {
|
|||||||
// 自动关联未关联的提供商
|
// 自动关联未关联的提供商
|
||||||
if (unlinkedProviderIds.length > 0) {
|
if (unlinkedProviderIds.length > 0) {
|
||||||
toastSuccess(`映射规则已保存,正在关联 ${unlinkedProviderIds.length} 个提供商...`)
|
toastSuccess(`映射规则已保存,正在关联 ${unlinkedProviderIds.length} 个提供商...`)
|
||||||
// linkProviders 处理完成后会由父组件统一刷新数据,无需再 emit update
|
|
||||||
emit('linkProviders', unlinkedProviderIds)
|
emit('linkProviders', unlinkedProviderIds)
|
||||||
} else {
|
} else {
|
||||||
toastSuccess('映射规则已保存')
|
toastSuccess('映射规则已保存')
|
||||||
emit('update', cleanedMappings)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 保存成功后刷新数据
|
||||||
|
emit('update', cleanedMappings)
|
||||||
|
emit('refresh')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.error('保存映射规则失败:', err)
|
log.error('保存映射规则失败:', err)
|
||||||
toastError('保存失败,请重试')
|
toastError('保存失败,请重试')
|
||||||
|
|||||||
@@ -511,6 +511,7 @@ async function handleSave() {
|
|||||||
if (!hasChanges.value || saving.value) return
|
if (!hasChanges.value || saving.value) return
|
||||||
|
|
||||||
saving.value = true
|
saving.value = true
|
||||||
|
let hasAnyOperation = false
|
||||||
try {
|
try {
|
||||||
let totalSuccess = 0
|
let totalSuccess = 0
|
||||||
const allErrors: string[] = []
|
const allErrors: string[] = []
|
||||||
@@ -519,6 +520,7 @@ async function handleSave() {
|
|||||||
for (const globalModelId of globalModelsToRemove.value) {
|
for (const globalModelId of globalModelsToRemove.value) {
|
||||||
const existingModel = existingModels.value.find(m => m.global_model_id === globalModelId)
|
const existingModel = existingModels.value.find(m => m.global_model_id === globalModelId)
|
||||||
if (existingModel) {
|
if (existingModel) {
|
||||||
|
hasAnyOperation = true
|
||||||
try {
|
try {
|
||||||
await deleteModel(props.providerId, existingModel.id)
|
await deleteModel(props.providerId, existingModel.id)
|
||||||
totalSuccess++
|
totalSuccess++
|
||||||
@@ -535,6 +537,7 @@ async function handleSave() {
|
|||||||
m.provider_model_mappings?.some(mapping => mapping.name === modelId)
|
m.provider_model_mappings?.some(mapping => mapping.name === modelId)
|
||||||
)
|
)
|
||||||
if (existingModel) {
|
if (existingModel) {
|
||||||
|
hasAnyOperation = true
|
||||||
try {
|
try {
|
||||||
await deleteModel(props.providerId, existingModel.id)
|
await deleteModel(props.providerId, existingModel.id)
|
||||||
totalSuccess++
|
totalSuccess++
|
||||||
@@ -546,19 +549,29 @@ async function handleSave() {
|
|||||||
|
|
||||||
// 添加全局模型
|
// 添加全局模型
|
||||||
if (globalModelsToAdd.value.length > 0) {
|
if (globalModelsToAdd.value.length > 0) {
|
||||||
const result = await batchAssignModelsToProvider(props.providerId, globalModelsToAdd.value)
|
hasAnyOperation = true
|
||||||
totalSuccess += result.success.length
|
try {
|
||||||
if (result.errors.length > 0) {
|
const result = await batchAssignModelsToProvider(props.providerId, globalModelsToAdd.value)
|
||||||
allErrors.push(...result.errors.map(e => e.error))
|
totalSuccess += result.success.length
|
||||||
|
if (result.errors.length > 0) {
|
||||||
|
allErrors.push(...result.errors.map(e => e.error))
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
allErrors.push(parseApiError(err, '批量添加全局模型失败'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加上游模型
|
// 添加上游模型
|
||||||
if (upstreamModelsToAdd.value.length > 0) {
|
if (upstreamModelsToAdd.value.length > 0) {
|
||||||
const result = await importModelsFromUpstream(props.providerId, upstreamModelsToAdd.value)
|
hasAnyOperation = true
|
||||||
totalSuccess += result.success.length
|
try {
|
||||||
if (result.errors.length > 0) {
|
const result = await importModelsFromUpstream(props.providerId, upstreamModelsToAdd.value)
|
||||||
allErrors.push(...result.errors.map(e => e.error))
|
totalSuccess += result.success.length
|
||||||
|
if (result.errors.length > 0) {
|
||||||
|
allErrors.push(...result.errors.map(e => e.error))
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
allErrors.push(parseApiError(err, '导入上游模型失败'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -574,6 +587,10 @@ async function handleSave() {
|
|||||||
emit('update:open', false)
|
emit('update:open', false)
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
showError(parseApiError(err, '保存失败'), '错误')
|
showError(parseApiError(err, '保存失败'), '错误')
|
||||||
|
// 即使出错,如果已执行过操作,也通知父组件刷新数据
|
||||||
|
if (hasAnyOperation) {
|
||||||
|
emit('changed')
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
saving.value = false
|
saving.value = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -872,7 +872,6 @@
|
|||||||
<!-- 模型查看 -->
|
<!-- 模型查看 -->
|
||||||
<ModelsTab
|
<ModelsTab
|
||||||
v-if="provider"
|
v-if="provider"
|
||||||
ref="modelsTabRef"
|
|
||||||
:key="`models-${provider.id}`"
|
:key="`models-${provider.id}`"
|
||||||
:provider="provider"
|
:provider="provider"
|
||||||
:endpoints="endpoints"
|
:endpoints="endpoints"
|
||||||
@@ -1132,7 +1131,6 @@ const revealedKeys = ref<Map<string, string>>(new Map())
|
|||||||
const modelFormDialogOpen = ref(false)
|
const modelFormDialogOpen = ref(false)
|
||||||
const editingModel = ref<Model | null>(null)
|
const editingModel = ref<Model | null>(null)
|
||||||
const batchAssignDialogOpen = ref(false)
|
const batchAssignDialogOpen = ref(false)
|
||||||
const modelsTabRef = ref<InstanceType<typeof ModelsTab> | null>(null)
|
|
||||||
const modelMappingTabRef = ref<InstanceType<typeof ModelMappingTab> | null>(null)
|
const modelMappingTabRef = ref<InstanceType<typeof ModelMappingTab> | null>(null)
|
||||||
|
|
||||||
// 密钥列表拖拽排序状态
|
// 密钥列表拖拽排序状态
|
||||||
@@ -1466,12 +1464,8 @@ async function confirmDeleteKey() {
|
|||||||
try {
|
try {
|
||||||
await deleteEndpointKey(keyId)
|
await deleteEndpointKey(keyId)
|
||||||
showSuccess('密钥已删除')
|
showSuccess('密钥已删除')
|
||||||
// 并行刷新:端点列表、模型列表、模型映射(删除 Key 触发自动解除模型关联)
|
// 刷新端点列表及模型数据(删除 Key 触发自动解除模型关联)
|
||||||
await Promise.all([
|
await loadEndpoints()
|
||||||
loadEndpoints(),
|
|
||||||
modelsTabRef.value?.reload(),
|
|
||||||
modelMappingTabRef.value?.reload()
|
|
||||||
])
|
|
||||||
emit('refresh')
|
emit('refresh')
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
showError(err.response?.data?.detail || '删除密钥失败', '错误')
|
showError(err.response?.data?.detail || '删除密钥失败', '错误')
|
||||||
@@ -1799,11 +1793,6 @@ async function openAntigravityQuotaDialog(key: EndpointAPIKey) {
|
|||||||
|
|
||||||
async function handleKeyChanged() {
|
async function handleKeyChanged() {
|
||||||
await loadEndpoints()
|
await loadEndpoints()
|
||||||
// 并行刷新模型列表和模型映射(因为模型权限会影响正则映射预览)
|
|
||||||
await Promise.all([
|
|
||||||
modelsTabRef.value?.reload(),
|
|
||||||
modelMappingTabRef.value?.reload()
|
|
||||||
])
|
|
||||||
emit('refresh')
|
emit('refresh')
|
||||||
// 添加/修改 key 后自动获取 Antigravity 配额(新 key 的 upstream_metadata 为空)
|
// 添加/修改 key 后自动获取 Antigravity 配额(新 key 的 upstream_metadata 为空)
|
||||||
void autoRefreshQuotaInBackground()
|
void autoRefreshQuotaInBackground()
|
||||||
@@ -1892,19 +1881,20 @@ function handleBatchAssign() {
|
|||||||
|
|
||||||
// 处理批量关联完成
|
// 处理批量关联完成
|
||||||
async function handleBatchAssignChanged() {
|
async function handleBatchAssignChanged() {
|
||||||
await loadProvider()
|
await loadEndpoints()
|
||||||
emit('refresh')
|
emit('refresh')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理模型映射变更
|
// 处理模型映射变更
|
||||||
async function handleModelMappingChanged() {
|
async function handleModelMappingChanged() {
|
||||||
|
await loadEndpoints()
|
||||||
emit('refresh')
|
emit('refresh')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理模型保存完成
|
// 处理模型保存完成
|
||||||
async function handleModelSaved() {
|
async function handleModelSaved() {
|
||||||
editingModel.value = null
|
editingModel.value = null
|
||||||
await loadProvider()
|
await loadEndpoints()
|
||||||
emit('refresh')
|
emit('refresh')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user