From 1bca2fb095e7f301714616bb6663479bdfa29376 Mon Sep 17 00:00:00 2001 From: mike Date: Thu, 15 Oct 2026 10:55:47 +0800 Subject: [PATCH] Update App.jsx via upload script - 2026-10-15 10:55:43 --- App.jsx | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/App.jsx b/App.jsx index ae787fe..e501195 100644 --- a/App.jsx +++ b/App.jsx @@ -2296,6 +2296,10 @@ function MainApp({ username, onLogout }) { const [aiKeyInput, setAiKeyInput] = useState(''); const [aiSaving, setAiSaving] = 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 [sellerProfiles, setSellerProfiles] = useState(DEFAULT_SELLER_PROFILES); @@ -2338,7 +2342,10 @@ function MainApp({ username, onLogout }) { const [backPanelTemplates, setBackPanelTemplates] = useState([]); 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(() => { @@ -2640,6 +2647,42 @@ function MainApp({ username, onLogout }) { 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 startEditCustomer(c) { setDraft({ ...c, productLines: [...(c.productLines || [])] }); setSelectedId(c.id); } function cancelDraft() { setDraft(null); } @@ -4119,7 +4162,7 @@ function MainApp({ username, onLogout }) {
-
AI 跟进文案(DeepSeek)
+
AI(主力:DeepSeek)
状态:{aiConfigHasKey ? 已配置 : 未配置} @@ -4142,6 +4185,46 @@ function MainApp({ username, onLogout }) {
+
+
备用 AI(阿里云百炼 · 通义千问)
+
+
+ 状态:{aiBackup.hasKey ? 已配置 : 未配置} +
+
+ 阿里云百炼 API Key + setAiBackupKeyInput(e.target.value)} + placeholder={aiBackup.hasKey ? '已设置,重新填写可覆盖' : '在 bailian.console.aliyun.com 申请(sk- 开头)'} + /> +
+
+ + +
+
+ + + {aiBackup.hasKey && } +
+
+ DeepSeek 繁忙(503/429 等)或连不上时,系统重试一次后自动切换到阿里云,目录导入、词汇翻译、网站翻译都适用。DeepSeek 正常时不会调用阿里云、不产生费用。改了地域或模型也要点"保存"(Key 可以不重填)。 +
+
+
+ )}