fix(admin): 打开余额脚本弹窗时重置表单,避免跨账户残留配置

- 打开弹窗先重置表单字段(baseUrl/apiKey/extra 等),仅保留示例脚本\n- 若后端存在已保存配置,则加载后覆盖\n- 同步清理测试结果与 loading 状态,避免残留误导
This commit is contained in:
atoz03
2025-12-14 14:07:21 +08:00
parent f6f4b5cfec
commit 1c8084a3b1

View File

@@ -139,16 +139,6 @@ const saving = ref(false)
const testing = ref(false)
const testResult = ref(null)
const form = reactive({
baseUrl: '',
apiKey: '',
token: '',
extra: '',
timeoutSeconds: 10,
autoIntervalMinutes: 0,
scriptBody: ''
})
const presetScript = `({
request: {
url: "{{baseUrl}}/api/user/self",
@@ -178,8 +168,36 @@ const presetScript = `({
}
})`
const form = reactive({
baseUrl: '',
apiKey: '',
token: '',
extra: '',
timeoutSeconds: 10,
autoIntervalMinutes: 0,
scriptBody: ''
})
const buildDefaultForm = () => ({
baseUrl: '',
apiKey: '',
token: '',
extra: '',
timeoutSeconds: 10,
autoIntervalMinutes: 0,
// 默认给出示例脚本,字段保持清空,避免“上一个账户的配置污染当前账户”
scriptBody: presetScript
})
const emitClose = () => emit('close')
const resetForm = () => {
Object.assign(form, buildDefaultForm())
testResult.value = null
saving.value = false
testing.value = false
}
const loadConfig = async () => {
if (!props.account?.id || !props.account?.platform) return
try {
@@ -254,9 +272,8 @@ watch(
() => props.show,
(val) => {
if (val) {
applyPreset()
resetForm()
loadConfig()
testResult.value = null
}
}
)