Update App.jsx via upload script - 2026-10-15 10:55:43
This commit is contained in:
parent
4ef9398e47
commit
1bca2fb095
87
App.jsx
87
App.jsx
|
|
@ -2296,6 +2296,10 @@ function MainApp({ username, onLogout }) {
|
||||||
const [aiKeyInput, setAiKeyInput] = useState('');
|
const [aiKeyInput, setAiKeyInput] = useState('');
|
||||||
const [aiSaving, setAiSaving] = useState(false);
|
const [aiSaving, setAiSaving] = useState(false);
|
||||||
const [aiTesting, setAiTesting] = useState(false);
|
const [aiTesting, setAiTesting] = useState(false);
|
||||||
|
// 备用AI服务商(阿里云百炼):DeepSeek繁忙时自动切换
|
||||||
|
const [aiBackup, setAiBackup] = useState({ hasKey: false, model: 'qwen-plus', region: 'cn' });
|
||||||
|
const [aiBackupKeyInput, setAiBackupKeyInput] = useState('');
|
||||||
|
const [aiBackupBusy, setAiBackupBusy] = useState('');
|
||||||
|
|
||||||
const [quotes, setQuotes] = useState([]);
|
const [quotes, setQuotes] = useState([]);
|
||||||
const [sellerProfiles, setSellerProfiles] = useState(DEFAULT_SELLER_PROFILES);
|
const [sellerProfiles, setSellerProfiles] = useState(DEFAULT_SELLER_PROFILES);
|
||||||
|
|
@ -2338,7 +2342,10 @@ function MainApp({ username, onLogout }) {
|
||||||
const [backPanelTemplates, setBackPanelTemplates] = useState([]);
|
const [backPanelTemplates, setBackPanelTemplates] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getAiConfig().then((res) => setAiConfigHasKey(!!res.hasKey)).catch(() => {});
|
getAiConfig().then((res) => {
|
||||||
|
setAiConfigHasKey(!!res.hasKey);
|
||||||
|
if (res.backup) setAiBackup({ hasKey: !!res.backup.hasKey, model: res.backup.model || 'qwen-plus', region: res.backup.region || 'cn' });
|
||||||
|
}).catch(() => {});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -2640,6 +2647,42 @@ function MainApp({ username, onLogout }) {
|
||||||
notify('已清除');
|
notify('已清除');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function aiBackupRequest(method, url, body) {
|
||||||
|
const r = await fetch(url, { method, headers: body ? { 'Content-Type': 'application/json' } : undefined, body: body ? JSON.stringify(body) : undefined });
|
||||||
|
const data = await r.json().catch(() => ({}));
|
||||||
|
if (!r.ok) throw new Error(data.error || `HTTP ${r.status}`);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
async function handleSaveAiBackup() {
|
||||||
|
if (!aiBackup.hasKey && !aiBackupKeyInput.trim()) { notify('请输入阿里云 API Key'); return; }
|
||||||
|
setAiBackupBusy('save');
|
||||||
|
try {
|
||||||
|
await aiBackupRequest('PUT', '/api/ai-config/backup', { apiKey: aiBackupKeyInput.trim(), model: aiBackup.model.trim(), region: aiBackup.region });
|
||||||
|
setAiBackup((b) => ({ ...b, hasKey: true, model: b.model.trim() || 'qwen-plus' }));
|
||||||
|
setAiBackupKeyInput('');
|
||||||
|
notify('已保存');
|
||||||
|
} catch (e) {
|
||||||
|
notify('保存失败:' + e.message);
|
||||||
|
} finally { setAiBackupBusy(''); }
|
||||||
|
}
|
||||||
|
async function handleTestAiBackup() {
|
||||||
|
setAiBackupBusy('test');
|
||||||
|
try {
|
||||||
|
await aiBackupRequest('POST', '/api/ai-config/backup/test');
|
||||||
|
notify('阿里云连接成功');
|
||||||
|
} catch (e) {
|
||||||
|
notify('连接失败:' + e.message.slice(0, 160));
|
||||||
|
} finally { setAiBackupBusy(''); }
|
||||||
|
}
|
||||||
|
async function handleClearAiBackup() {
|
||||||
|
if (!window.confirm('确定清除备用的阿里云 API Key?')) return;
|
||||||
|
try {
|
||||||
|
await aiBackupRequest('DELETE', '/api/ai-config/backup');
|
||||||
|
setAiBackup({ hasKey: false, model: 'qwen-plus', region: 'cn' });
|
||||||
|
notify('已清除');
|
||||||
|
} catch (e) { notify('清除失败'); }
|
||||||
|
}
|
||||||
|
|
||||||
function startNewCustomer() { setDraft(blankCustomer()); setSelectedId(null); }
|
function startNewCustomer() { setDraft(blankCustomer()); setSelectedId(null); }
|
||||||
function startEditCustomer(c) { setDraft({ ...c, productLines: [...(c.productLines || [])] }); setSelectedId(c.id); }
|
function startEditCustomer(c) { setDraft({ ...c, productLines: [...(c.productLines || [])] }); setSelectedId(c.id); }
|
||||||
function cancelDraft() { setDraft(null); }
|
function cancelDraft() { setDraft(null); }
|
||||||
|
|
@ -4119,7 +4162,7 @@ function MainApp({ username, onLogout }) {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="panel">
|
<div className="panel">
|
||||||
<div className="panel-header"><div className="panel-title"><Sparkles size={15} />AI 跟进文案(DeepSeek)</div></div>
|
<div className="panel-header"><div className="panel-title"><Sparkles size={15} />AI(主力:DeepSeek)</div></div>
|
||||||
<div className="panel-body" style={{ padding: 18 }}>
|
<div className="panel-body" style={{ padding: 18 }}>
|
||||||
<div style={{ fontSize: 12.5, color: 'var(--ink-soft)', marginBottom: 12 }}>
|
<div style={{ fontSize: 12.5, color: 'var(--ink-soft)', marginBottom: 12 }}>
|
||||||
状态:{aiConfigHasKey ? <span style={{ color: 'var(--led-green)', fontWeight: 600 }}>已配置</span> : <span>未配置</span>}
|
状态:{aiConfigHasKey ? <span style={{ color: 'var(--led-green)', fontWeight: 600 }}>已配置</span> : <span>未配置</span>}
|
||||||
|
|
@ -4142,6 +4185,46 @@ function MainApp({ username, onLogout }) {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="panel">
|
||||||
|
<div className="panel-header"><div className="panel-title"><Sparkles size={15} />备用 AI(阿里云百炼 · 通义千问)</div></div>
|
||||||
|
<div className="panel-body" style={{ padding: 18 }}>
|
||||||
|
<div style={{ fontSize: 12.5, color: 'var(--ink-soft)', marginBottom: 12 }}>
|
||||||
|
状态:{aiBackup.hasKey ? <span style={{ color: 'var(--led-green)', fontWeight: 600 }}>已配置</span> : <span>未配置</span>}
|
||||||
|
</div>
|
||||||
|
<div className="field">
|
||||||
|
<span className="field-label">阿里云百炼 API Key</span>
|
||||||
|
<input
|
||||||
|
type="password" className="input" value={aiBackupKeyInput} onChange={e => setAiBackupKeyInput(e.target.value)}
|
||||||
|
placeholder={aiBackup.hasKey ? '已设置,重新填写可覆盖' : '在 bailian.console.aliyun.com 申请(sk- 开头)'}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div style={{ display: 'flex', gap: 10 }}>
|
||||||
|
<label className="field" style={{ flex: 1 }}>
|
||||||
|
<span className="field-label">Key 所属地域</span>
|
||||||
|
<select className="input" value={aiBackup.region} onChange={e => setAiBackup(b => ({ ...b, region: e.target.value }))}>
|
||||||
|
<option value="cn">中国大陆(北京)</option>
|
||||||
|
<option value="intl">国际(新加坡)</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label className="field" style={{ flex: 1 }}>
|
||||||
|
<span className="field-label">模型</span>
|
||||||
|
<input className="input" list="aliyun-models" value={aiBackup.model} onChange={e => setAiBackup(b => ({ ...b, model: e.target.value }))} placeholder="qwen-plus" />
|
||||||
|
<datalist id="aliyun-models">
|
||||||
|
<option value="qwen-plus" /><option value="qwen-flash" /><option value="qwen-turbo" /><option value="qwen-max" />
|
||||||
|
</datalist>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div style={{ display: 'flex', gap: 8 }}>
|
||||||
|
<button className="btn btn-primary" disabled={!!aiBackupBusy} onClick={handleSaveAiBackup}><Save size={13} />保存</button>
|
||||||
|
<button className="btn" disabled={!aiBackup.hasKey || !!aiBackupBusy} onClick={handleTestAiBackup}>{aiBackupBusy === 'test' ? '测试中…' : '测试连接'}</button>
|
||||||
|
{aiBackup.hasKey && <button className="btn btn-danger" onClick={handleClearAiBackup}>清除</button>}
|
||||||
|
</div>
|
||||||
|
<div className="disclaimer" style={{ marginTop: 14 }}>
|
||||||
|
DeepSeek 繁忙(503/429 等)或连不上时,系统重试一次后<b>自动切换到阿里云</b>,目录导入、词汇翻译、网站翻译都适用。DeepSeek 正常时不会调用阿里云、不产生费用。改了地域或模型也要点"保存"(Key 可以不重填)。
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue