From 924ad44e6c39f144c56bfc1b61aab6fd3beb3918 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 28 Nov 2025 11:10:22 +0800 Subject: [PATCH] fix(usage): correct selectedTemplate initialization logic Previously, selectedTemplate was initialized to null when no NEW_API credentials were detected, which caused the credentials config section to be hidden even for new configurations or GENERAL template users. Now properly detects: - NEW_API template (has accessToken or userId) - GENERAL template (has apiKey or baseUrl) - Default to GENERAL for new configurations (matches default code template) --- src/components/UsageScriptModal.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/UsageScriptModal.tsx b/src/components/UsageScriptModal.tsx index e7fb8b3dc..f55ceb676 100644 --- a/src/components/UsageScriptModal.tsx +++ b/src/components/UsageScriptModal.tsx @@ -176,10 +176,16 @@ const UsageScriptModal: React.FC = ({ const [selectedTemplate, setSelectedTemplate] = useState( () => { const existingScript = provider.meta?.usage_script; + // 检测 NEW_API 模板(有 accessToken 或 userId) if (existingScript?.accessToken || existingScript?.userId) { return TEMPLATE_KEYS.NEW_API; } - return null; + // 检测 GENERAL 模板(有 apiKey 或 baseUrl) + if (existingScript?.apiKey || existingScript?.baseUrl) { + return TEMPLATE_KEYS.GENERAL; + } + // 新配置或无凭证:默认使用 GENERAL(与默认代码模板一致) + return TEMPLATE_KEYS.GENERAL; }, );