mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-27 08:14:33 +08:00
0cfd65cb90
- 新增 importCurrentConfigAsDefault 函数,创建 ID 为 'default' 的特殊供应商 - 默认供应商不生成独立配置文件,直接使用现有 settings.json - 首次启动时自动导入现有配置为默认供应商,并设为选中状态 - 切换到默认供应商时无需文件操作,直接使用原配置 - 删除默认供应商时保护原配置文件不被误删 - 简化 ImportConfigModal 组件,移除 isEmpty 相关逻辑 - 提升用户体验:无需手动操作,开箱即用
67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
import React, { useState } from 'react'
|
||
import './AddProviderModal.css'
|
||
|
||
interface ImportConfigModalProps {
|
||
onImport: (name: string) => void
|
||
onClose: () => void
|
||
}
|
||
|
||
const ImportConfigModal: React.FC<ImportConfigModalProps> = ({ onImport, onClose }) => {
|
||
const [name, setName] = useState('')
|
||
const [error, setError] = useState('')
|
||
|
||
const handleSubmit = (e: React.FormEvent) => {
|
||
e.preventDefault()
|
||
setError('')
|
||
|
||
if (!name.trim()) {
|
||
setError('请输入供应商名称')
|
||
return
|
||
}
|
||
|
||
onImport(name.trim())
|
||
}
|
||
|
||
return (
|
||
<div className="modal-overlay">
|
||
<div className="modal-content">
|
||
<h2>导入当前配置</h2>
|
||
|
||
<p style={{marginBottom: '1.5rem', color: '#666', fontSize: '0.9rem'}}>
|
||
将当前的 <code>~/.claude/settings.json</code> 配置文件导入为一个新的供应商。
|
||
<br />
|
||
<strong>注意:</strong>这不会修改您当前的配置文件。
|
||
</p>
|
||
|
||
{error && <div className="error-message">{error}</div>}
|
||
|
||
<form onSubmit={handleSubmit}>
|
||
<div className="form-group">
|
||
<label htmlFor="name">供应商名称 *</label>
|
||
<input
|
||
type="text"
|
||
id="name"
|
||
name="name"
|
||
value={name}
|
||
onChange={(e) => setName(e.target.value)}
|
||
placeholder="例如:我的当前配置"
|
||
required
|
||
autoFocus
|
||
/>
|
||
</div>
|
||
|
||
<div className="form-actions">
|
||
<button type="button" className="cancel-btn" onClick={onClose}>
|
||
取消
|
||
</button>
|
||
<button type="submit" className="submit-btn">
|
||
导入
|
||
</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
)
|
||
}
|
||
|
||
export default ImportConfigModal |