修复编辑后输入框无法选中的焦点管理问题
- 移除阻塞式alert调用,避免焦点管理冲突 - 清理不必要的CSS z-index层级设置 - 优化EditProviderModal的useEffect依赖管理 - 改用console日志记录操作结果 问题原因:alert()强制抢夺焦点,在模态框关闭时打断正常焦点流转
This commit is contained in:
@@ -58,9 +58,10 @@ function App() {
|
|||||||
const success = await window.electronAPI.switchProvider(id)
|
const success = await window.electronAPI.switchProvider(id)
|
||||||
if (success) {
|
if (success) {
|
||||||
setCurrentProviderId(id)
|
setCurrentProviderId(id)
|
||||||
alert('切换成功!')
|
// 移除阻塞式alert
|
||||||
|
console.log('供应商切换成功')
|
||||||
} else {
|
} else {
|
||||||
alert('切换失败,请检查配置')
|
console.error('切换失败,请检查配置')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,10 +70,17 @@ function App() {
|
|||||||
await window.electronAPI.updateProvider(provider)
|
await window.electronAPI.updateProvider(provider)
|
||||||
await loadProviders()
|
await loadProviders()
|
||||||
setEditingProviderId(null)
|
setEditingProviderId(null)
|
||||||
alert('保存成功!')
|
// 移除阻塞式alert,避免焦点管理问题
|
||||||
|
setTimeout(() => {
|
||||||
|
console.log('供应商更新成功')
|
||||||
|
}, 100)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('更新供应商失败:', error)
|
console.error('更新供应商失败:', error)
|
||||||
alert('保存失败,请重试')
|
setEditingProviderId(null)
|
||||||
|
// 错误情况下也避免alert
|
||||||
|
setTimeout(() => {
|
||||||
|
console.error('保存失败,请重试')
|
||||||
|
}, 100)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,8 +81,6 @@
|
|||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
font-size: 0.95rem;
|
font-size: 0.95rem;
|
||||||
transition: border-color 0.2s;
|
transition: border-color 0.2s;
|
||||||
position: relative;
|
|
||||||
z-index: 1;
|
|
||||||
background: white;
|
background: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +150,6 @@
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
width: 32px;
|
width: 32px;
|
||||||
height: 32px;
|
height: 32px;
|
||||||
z-index: 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.password-toggle svg {
|
.password-toggle svg {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ const EditProviderModal: React.FC<EditProviderModalProps> = ({ provider, onSave,
|
|||||||
apiKey: provider.apiKey,
|
apiKey: provider.apiKey,
|
||||||
websiteUrl: provider.websiteUrl || ''
|
websiteUrl: provider.websiteUrl || ''
|
||||||
})
|
})
|
||||||
}, [provider])
|
}, [provider.id, provider.name, provider.apiUrl, provider.apiKey, provider.websiteUrl])
|
||||||
|
|
||||||
const handleSubmit = (e: React.FormEvent) => {
|
const handleSubmit = (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@@ -86,7 +86,7 @@ const EditProviderModal: React.FC<EditProviderModalProps> = ({ provider, onSave,
|
|||||||
type="text"
|
type="text"
|
||||||
id="name"
|
id="name"
|
||||||
name="name"
|
name="name"
|
||||||
value={formData.name || ''}
|
value={formData.name}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
placeholder="例如:官方 Anthropic"
|
placeholder="例如:官方 Anthropic"
|
||||||
required
|
required
|
||||||
@@ -100,7 +100,7 @@ const EditProviderModal: React.FC<EditProviderModalProps> = ({ provider, onSave,
|
|||||||
type="url"
|
type="url"
|
||||||
id="apiUrl"
|
id="apiUrl"
|
||||||
name="apiUrl"
|
name="apiUrl"
|
||||||
value={formData.apiUrl || ''}
|
value={formData.apiUrl}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
onBlur={handleApiUrlBlur}
|
onBlur={handleApiUrlBlur}
|
||||||
placeholder="https://api.anthropic.com"
|
placeholder="https://api.anthropic.com"
|
||||||
@@ -115,7 +115,7 @@ const EditProviderModal: React.FC<EditProviderModalProps> = ({ provider, onSave,
|
|||||||
type="text"
|
type="text"
|
||||||
id="websiteUrl"
|
id="websiteUrl"
|
||||||
name="websiteUrl"
|
name="websiteUrl"
|
||||||
value={formData.websiteUrl || ''}
|
value={formData.websiteUrl}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
placeholder="https://example.com(可选)"
|
placeholder="https://example.com(可选)"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
@@ -130,7 +130,7 @@ const EditProviderModal: React.FC<EditProviderModalProps> = ({ provider, onSave,
|
|||||||
type={showPassword ? "text" : "password"}
|
type={showPassword ? "text" : "password"}
|
||||||
id="apiKey"
|
id="apiKey"
|
||||||
name="apiKey"
|
name="apiKey"
|
||||||
value={formData.apiKey || ''}
|
value={formData.apiKey}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
placeholder={formData.name && formData.name.includes('YesCode') ? 'cr_...' : 'sk-...'}
|
placeholder={formData.name && formData.name.includes('YesCode') ? 'cr_...' : 'sk-...'}
|
||||||
required
|
required
|
||||||
|
|||||||
Reference in New Issue
Block a user