From 208987107e13c8d36ea768c49ade154d6c53ec0d Mon Sep 17 00:00:00 2001 From: farion1231 Date: Wed, 6 Aug 2025 11:42:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DURL=E6=8E=A8=E6=B5=8B?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=9A=E6=94=AF=E6=8C=81=E4=B8=8D=E5=AE=8C?= =?UTF-8?q?=E6=95=B4URL=E8=BE=93=E5=85=A5=E5=B9=B6=E4=BF=9D=E6=8C=81?= =?UTF-8?q?=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复inferWebsiteUrl函数,支持无协议URL的推测 - 在API地址失焦时自动补全https://协议 - 同时更新API地址和网站地址字段 - 保持URL输入验证,确保API地址有效性 - 提升用户体验:用户可输入api.example.com等简化格式 --- src/renderer/components/AddProviderModal.tsx | 21 ++++++++++++++++++- src/renderer/components/EditProviderModal.tsx | 21 ++++++++++++++++++- src/shared/utils.ts | 9 +++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/renderer/components/AddProviderModal.tsx b/src/renderer/components/AddProviderModal.tsx index 9d6a161..f466bcc 100644 --- a/src/renderer/components/AddProviderModal.tsx +++ b/src/renderer/components/AddProviderModal.tsx @@ -43,6 +43,24 @@ const AddProviderModal: React.FC = ({ onAdd, onClose }) = setFormData(newFormData) } + const handleApiUrlBlur = (e: React.FocusEvent) => { + const apiUrl = e.target.value.trim() + if (apiUrl) { + let normalizedApiUrl = apiUrl + + // 如果没有协议,添加 https:// + if (!normalizedApiUrl.match(/^https?:\/\//)) { + normalizedApiUrl = 'https://' + normalizedApiUrl + } + + setFormData(prev => ({ + ...prev, + apiUrl: normalizedApiUrl, + websiteUrl: inferWebsiteUrl(normalizedApiUrl) + })) + } + } + // 预设的供应商配置 const presets = [ { @@ -109,6 +127,7 @@ const AddProviderModal: React.FC = ({ onAdd, onClose }) = name="apiUrl" value={formData.apiUrl} onChange={handleChange} + onBlur={handleApiUrlBlur} placeholder="https://api.anthropic.com" required /> @@ -117,7 +136,7 @@ const AddProviderModal: React.FC = ({ onAdd, onClose }) =
= ({ provider, onSave, setFormData(newFormData) } + const handleApiUrlBlur = (e: React.FocusEvent) => { + const apiUrl = e.target.value.trim() + if (apiUrl) { + let normalizedApiUrl = apiUrl + + // 如果没有协议,添加 https:// + if (!normalizedApiUrl.match(/^https?:\/\//)) { + normalizedApiUrl = 'https://' + normalizedApiUrl + } + + setFormData(prev => ({ + ...prev, + apiUrl: normalizedApiUrl, + websiteUrl: inferWebsiteUrl(normalizedApiUrl) + })) + } + } + return (
e.stopPropagation()}> @@ -84,6 +102,7 @@ const EditProviderModal: React.FC = ({ provider, onSave, name="apiUrl" value={formData.apiUrl || ''} onChange={handleChange} + onBlur={handleApiUrlBlur} placeholder="https://api.anthropic.com" required autoComplete="off" @@ -93,7 +112,7 @@ const EditProviderModal: React.FC = ({ provider, onSave,