fix(models): clear form state when loading model data for edit

Reset model selection, search query, and expanded provider state
when switching to edit mode to prevent stale UI state carrying over
from previous operations. Also ensure tieredPricing is properly set
or reset based on model data.
This commit is contained in:
fawney19
2025-12-16 18:42:58 +08:00
parent 73d3c9d3e4
commit 50abb55c94

View File

@@ -604,6 +604,11 @@ function resetForm() {
// 加载模型数据(编辑模式) // 加载模型数据(编辑模式)
function loadModelData() { function loadModelData() {
if (!props.model) return if (!props.model) return
// 先重置创建模式的残留状态
selectedModel.value = null
searchQuery.value = ''
expandedProvider.value = null
form.value = { form.value = {
name: props.model.name, name: props.model.name,
display_name: props.model.display_name, display_name: props.model.display_name,
@@ -612,9 +617,10 @@ function loadModelData() {
config: props.model.config ? { ...props.model.config } : { streaming: true }, config: props.model.config ? { ...props.model.config } : { streaming: true },
is_active: props.model.is_active, is_active: props.model.is_active,
} }
if (props.model.default_tiered_pricing) { // 确保 tieredPricing 也被正确设置或重置
tieredPricing.value = JSON.parse(JSON.stringify(props.model.default_tiered_pricing)) tieredPricing.value = props.model.default_tiered_pricing
} ? JSON.parse(JSON.stringify(props.model.default_tiered_pricing))
: null
} }
// 使用 useFormDialog 统一处理对话框逻辑 // 使用 useFormDialog 统一处理对话框逻辑