添加切换供应商的确认对话框

- 切换供应商前显示确认对话框
- 防止误操作导致的意外切换
- 提升用户操作安全性
This commit is contained in:
farion1231
2025-08-06 07:45:54 +08:00
parent 779e24ee49
commit 558103171e

View File

@@ -77,23 +77,37 @@ function App() {
} }
const handleSwitchProvider = async (id: string) => { const handleSwitchProvider = async (id: string) => {
const success = await window.electronAPI.switchProvider(id) const provider = providers[id]
if (success) { if (!provider) return
setCurrentProviderId(id)
setMessageModal({ // 如果是当前供应商,直接返回
show: true, if (id === currentProviderId) return
title: '切换成功',
message: '供应商已成功切换!', setConfirmModal({
type: 'success' show: true,
}) title: '切换供应商',
} else { message: `确定要切换到"${provider.name}"吗?`,
setMessageModal({ onConfirm: async () => {
show: true, const success = await window.electronAPI.switchProvider(id)
title: '切换失败', if (success) {
message: '切换失败,请检查配置', setCurrentProviderId(id)
type: 'error' setMessageModal({
}) show: true,
} title: '切换成功',
message: '供应商已成功切换!',
type: 'success'
})
} else {
setMessageModal({
show: true,
title: '切换失败',
message: '切换失败,请检查配置',
type: 'error'
})
}
setConfirmModal(null)
}
})
} }
const handleEditProvider = async (provider: Provider) => { const handleEditProvider = async (provider: Provider) => {