Update App.jsx via upload script - 2026-11-17 16:57:58

This commit is contained in:
mike 2026-11-17 16:58:18 +08:00
parent 111c44c9fb
commit 5920c64bbd
1 changed files with 84 additions and 0 deletions

84
App.jsx
View File

@ -2352,6 +2352,23 @@ const Styles = () => (
.cv-edit { display: grid; gap: 8px; } .cv-edit { display: grid; gap: 8px; }
@media (max-width: 760px) { .cv-grid { grid-template-columns: 1fr; } } @media (max-width: 760px) { .cv-grid { grid-template-columns: 1fr; } }
/* 沟通记录:聊天样式 */ /* 沟通记录:聊天样式 */
.cv-match-btn { background: #0f766e !important; border-color: #0f766e !important; }
.cv-match { border-color: #99d5cc; background: linear-gradient(180deg, #f0fbf8, #fff 60%); }
.cv-match .cv-ai-badge { color: #0f766e; }
.cv-mg { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-top: 10px; background: #fff; }
.cv-mg-h { display: flex; gap: 8px; align-items: baseline; font-size: 13.5px; margin-bottom: 4px; }
.cv-mg-h span { color: var(--ink-soft); font-weight: 600; font-size: 12.5px; white-space: nowrap; }
.cv-mg-none { font-size: 12.5px; color: #b54708; margin-top: 4px; }
.cv-mm { border-top: 1px dashed var(--line); padding: 7px 0 4px; }
.cv-mm:first-of-type { border-top: 0; }
.cv-mm-h { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cv-mm-h b { font-size: 13.5px; }
.cv-mm-h small { color: var(--ink-soft); font-size: 12px; }
.cv-fit { font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 99px; white-space: nowrap; }
.cv-fit.f-h { background: #dcfce7; color: #166534; } .cv-fit.f-m { background: #e0f2fe; color: #075985; } .cv-fit.f-l { background: #fef3c7; color: #92400e; }
.cv-mm-r { font-size: 12.8px; line-height: 1.55; margin-top: 3px; }
.cv-mm-c { font-size: 12.5px; color: #0f766e; margin-top: 2px; }
.cv-mm-g { margin: 3px 0 0; padding-left: 18px; font-size: 12.3px; color: #b54708; line-height: 1.5; }
.cv-search { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 8px; padding: 0 6px; background: var(--bg); color: var(--ink-soft); height: 30px; } .cv-search { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 8px; padding: 0 6px; background: var(--bg); color: var(--ink-soft); height: 30px; }
.cv-search input { border: 0; outline: 0; background: transparent; width: 120px; font-size: 12.5px; color: var(--ink); } .cv-search input { border: 0; outline: 0; background: transparent; width: 120px; font-size: 12.5px; color: var(--ink); }
.cv-search button { border: 0; background: none; cursor: pointer; color: var(--ink-soft); display: inline-flex; padding: 0; } .cv-search button { border: 0; background: none; cursor: pointer; color: var(--ink-soft); display: inline-flex; padding: 0; }
@ -7350,6 +7367,9 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
const [aiBusy, setAiBusy] = useState(false); const [aiBusy, setAiBusy] = useState(false);
const [aiSecs, setAiSecs] = useState(0); const [aiSecs, setAiSecs] = useState(0);
const [aiOpen, setAiOpen] = useState(true); const [aiOpen, setAiOpen] = useState(true);
const [mBusy, setMBusy] = useState(false);
const [mSecs, setMSecs] = useState(0);
const [mOpen, setMOpen] = useState(true);
const [ask, setAsk] = useState(''); const [ask, setAsk] = useState('');
const [answer, setAnswer] = useState(null); const [answer, setAnswer] = useState(null);
const [asking, setAsking] = useState(false); const [asking, setAsking] = useState(false);
@ -7480,6 +7500,23 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
} catch (e) { onNotify('AI 分析失败:' + e.message); } } catch (e) { onNotify('AI 分析失败:' + e.message); }
finally { clearInterval(tick); setAiBusy(false); } finally { clearInterval(tick); setAiBusy(false); }
} }
// AI 匹配产品:读产品库,按需求挑出合适 / 接近的型号
async function matchProducts() {
setMBusy(true); setMSecs(0); setMOpen(true);
const t0 = Date.now(), tick = setInterval(() => setMSecs(Math.round((Date.now() - t0) / 1000)), 1000);
try {
const { jobId } = await convoApi('POST', `/api/convos/${c.id}/match`);
for (;;) {
await new Promise(r => setTimeout(r, 2000));
const j = await convoApi('GET', `/api/ai/jobs/${jobId}`);
if (j.status === 'running') continue;
if (j.status === 'done' && j.data && j.data.match) { setData(d => ({ ...d, match: j.data.match })); onNotify('AI 匹配产品完成'); }
else throw new Error((j.data && j.data.error) || 'AI 匹配失败');
break;
}
} catch (e) { onNotify('AI 匹配产品失败:' + e.message); }
finally { clearInterval(tick); setMBusy(false); }
}
async function doAsk() { async function doAsk() {
if (!ask.trim()) return; if (!ask.trim()) return;
setAsking(true); setAnswer(null); setAsking(true); setAnswer(null);
@ -7515,6 +7552,9 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
<button className="btn btn-sm btn-primary" disabled={!items.length || aiBusy} onClick={analyze} title={items.length ? '' : '先记录沟通内容'}> <button className="btn btn-sm btn-primary" disabled={!items.length || aiBusy} onClick={analyze} title={items.length ? '' : '先记录沟通内容'}>
<Sparkles size={13} />{aiBusy ? `AI 分析中… ${aiSecs}s` : an ? '重新 AI 分析' : 'AI 分析'} <Sparkles size={13} />{aiBusy ? `AI 分析中… ${aiSecs}s` : an ? '重新 AI 分析' : 'AI 分析'}
</button> </button>
<button className="btn btn-sm btn-primary cv-match-btn" disabled={!items.length || mBusy} onClick={matchProducts} title={an ? '按客户需求从产品库里挑型号' : '建议先做 AI 分析,匹配会更准'}>
<Boxes size={13} />{mBusy ? `匹配中… ${mSecs}s` : data && data.match ? '重新匹配产品' : 'AI 匹配产品'}
</button>
</div> </div>
</div> </div>
@ -7620,6 +7660,50 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
)} )}
{/* AI 匹配产品结果 */}
{data && data.match && data.match.result && (() => {
const M = data.match.result;
const fitCls = (f) => (/^符合/.test(f || '') ? 'f-h' : /基本/.test(f || '') ? 'f-m' : 'f-l');
const stale = items.filter(x => (x.createdAt || 0) > data.match.at || (x.updatedAt || 0) > data.match.at).length;
return (
<div className="cv-ai cv-match">
<div className="cv-ai-top">
<span className="cv-ai-badge"><Boxes size={13} />AI 匹配产品</span>
<span className="cv-ai-meta">{new Date(data.match.at).toLocaleString()} · 产品库 {data.match.total} 个型号{data.match.candidates < data.match.total ? `,初选 ${data.match.candidates} 个对比` : ''}</span>
{stale > 0 && <span className="cv-stale">有 {stale} 条新消息,建议重新匹配</span>}
<button className="btn btn-sm btn-ghost" style={{ marginLeft: 'auto' }} onClick={() => setMOpen(v => !v)}>{mOpen ? '收起' : '展开'}</button>
</div>
{mOpen && (<>
{M.summary && <p className="cv-sum">{M.summary}</p>}
{(M.groups || []).map((g, gi) => (
<div key={gi} className="cv-mg">
<div className="cv-mg-h"><b>{g.need}</b>{g.qty ? <span>× {g.qty}</span> : null}</div>
{(g.matches || []).length === 0 ? <div className="cv-mg-none">产品库里没有合适的型号{g.noMatch ? `:${g.noMatch}` : ''}</div> : (g.matches || []).map((m, mi) => (
<div key={mi} className="cv-mm">
<div className="cv-mm-h">
<span className={`cv-fit ${fitCls(m.fit)}`}>{m.fit || '接近'}</span>
<b>{m.model}</b>
<small>{[m.type || m.category, m.power].filter(Boolean).join(' · ')}</small>
{onPatchCustomer && <button className="btn btn-sm btn-ghost" style={{ marginLeft: 'auto' }} title="填入客户档案的意向型号 / 数量"
onClick={() => { onPatchCustomer({ intendedModel: m.model, ...(g.qty ? { intendedQty: String(g.qty) } : {}) }); onNotify(`已把 ${m.model} 填入意向型号`); }}><Check size={12} />设为意向型号</button>}
</div>
{m.reason && <div className="cv-mm-r">{m.reason}</div>}
{m.config && <div className="cv-mm-c"><b>建议配置:</b>{m.config}</div>}
{Array.isArray(m.gaps) && m.gaps.length > 0 && <ul className="cv-mm-g">{m.gaps.map((x, k) => <li key={k}>{x}</li>)}</ul>}
</div>
))}
{(g.matches || []).length > 0 && g.noMatch && <div className="cv-mg-none">{g.noMatch}</div>}
</div>
))}
{Array.isArray(M.questions) && M.questions.length > 0 && (
<div className="cv-grid" style={{ gridTemplateColumns: '1fr' }}><div className="warn"><h4>还需要跟客户确认</h4><ul>{M.questions.map((x, k) => <li key={k}>{x}</li>)}</ul></div></div>
)}
<div className="cv-ai-meta" style={{ marginTop: 8 }}>匹配结果只根据产品库里录入的参数;没录入的参数会列在"需确认"里,报价前请人工核对。</div>
</>)}
</div>
);
})()}
{/* 问 AI */} {/* 问 AI */}
{items.length > 0 && ( {items.length > 0 && (
<div className="cv-ask"> <div className="cv-ask">