From f33b0e434400f0f1a5b4221bf63102128f3b714e Mon Sep 17 00:00:00 2001 From: nanhaoluo <3075912108@qq.com> Date: Mon, 26 Jan 2026 11:21:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=A4=9A=20API=20?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD=E7=9A=84=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=92=8C=E4=BF=9D=E5=AD=98=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除 API 前检查是否为当前激活的配置,防止误删 - 保存 API 配置时正确保留激活状态 - 添加新 API 时,如果是第一个自动设置为激活 - 优化用户体验,提供明确的错误提示 --- settings.php | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/settings.php b/settings.php index 8580fec..2a31c28 100644 --- a/settings.php +++ b/settings.php @@ -2238,15 +2238,24 @@ function themeoptions_page(){ // 删除 API 配置 $(document).on('click', '.argon-delete-api', function() { - if (!confirm('')) { - return; - } - var provider = $(this).data('provider'); var index = $(this).data('index'); var apiList = $('.argon-api-list[data-provider="' + provider + '"]'); var apisData = JSON.parse(apiList.find('.argon-apis-data').val() || '[]'); + // 检查是否是当前激活的 API + var activeApiId = $('input[name="argon_ai_' + provider + '_active_api"]:checked').val(); + var apiToDelete = apisData[index]; + + if (apiToDelete && apiToDelete.id === activeApiId) { + alert(''); + return; + } + + if (!confirm('')) { + return; + } + // 删除指定索引的 API apisData.splice(index, 1); @@ -2280,6 +2289,9 @@ function themeoptions_page(){ return; } + // 获取当前激活的 API ID + var activeApiId = $('input[name="argon_ai_' + provider + '_active_api"]:checked').val(); + var apiConfig = { id: index >= 0 ? apisData[index].id : 'api_' + Date.now(), name: name, @@ -2289,12 +2301,26 @@ function themeoptions_page(){ is_active: false }; + // 如果是编辑现有配置,保留其激活状态 + if (index >= 0 && apisData[index]) { + apiConfig.is_active = (apisData[index].id === activeApiId); + } + if (index >= 0) { // 编辑现有配置 apisData[index] = apiConfig; } else { // 添加新配置 apisData.push(apiConfig); + + // 如果是第一个 API,自动设置为激活 + if (apisData.length === 1) { + apiConfig.is_active = true; + // 更新单选框 + setTimeout(function() { + $('input[name="argon_ai_' + provider + '_active_api"][value="' + apiConfig.id + '"]').prop('checked', true); + }, 100); + } } // 更新隐藏字段