Update App.jsx via upload script - 2026-11-16 22:46:34
This commit is contained in:
parent
c51439b5ee
commit
4fc3350952
432
App.jsx
432
App.jsx
|
|
@ -5,7 +5,7 @@ import {
|
|||
Building2, Globe, Phone, Save, RefreshCw, LayoutDashboard, Users,
|
||||
Package, Layers, Zap, Tag, Inbox, Paperclip,
|
||||
Menu, LogOut, GripVertical, BookOpen, FileText, FolderTree, Lock, Sparkles, Printer, Image as ImageIcon,
|
||||
ShieldCheck, Settings2, Boxes, Download, Wifi, Radio, QrCode, Folder, FolderPlus, Factory, UploadCloud, ClipboardList, MessageCircle, CalendarDays, MapPin, Wrench, Hash
|
||||
ShieldCheck, Settings2, Boxes, Download, Wifi, Radio, QrCode, Folder, FolderPlus, Factory, UploadCloud, ClipboardList, MessageCircle, CalendarDays, MapPin, Wrench, Hash, Send, Languages
|
||||
} from 'lucide-react';
|
||||
import { MicUploadPage } from './mic-upload/MicUploadPage';
|
||||
import { ImageToolPage } from './mic-upload/ImageToolPage';
|
||||
|
|
@ -2278,6 +2278,73 @@ const Styles = () => (
|
|||
.cv-item-f { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
|
||||
.cv-edit { display: grid; gap: 8px; }
|
||||
@media (max-width: 760px) { .cv-grid { grid-template-columns: 1fr; } }
|
||||
/* 沟通记录:聊天样式 */
|
||||
.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 button { border: 0; background: none; cursor: pointer; color: var(--ink-soft); display: inline-flex; padding: 0; }
|
||||
.cv-imp { display: grid; gap: 8px; padding: 12px; border: 1.5px dashed var(--line); border-radius: 10px; background: var(--bg); margin-bottom: 12px; }
|
||||
.cv-imp-h { display: grid; gap: 2px; } .cv-imp-h small { color: var(--ink-soft); font-size: 12px; }
|
||||
.cv-imp-me { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; margin-left: auto; }
|
||||
.cv-imp-me .input { width: 110px; height: 30px; }
|
||||
.cv-chat { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #efeae2; position: relative; }
|
||||
.cv-chat.drag::after { content: '松开鼠标,把文件加到要发送的消息里'; position: absolute; inset: 0; background: rgba(37,99,235,.10); border: 2px dashed #2563eb; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-weight: 700; color: #1d4ed8; pointer-events: none; }
|
||||
.cv-msgs { max-height: 620px; min-height: 180px; overflow-y: auto; padding: 14px 14px 8px; display: flex; flex-direction: column; gap: 6px;
|
||||
background-color: #efeae2; background-image: radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px); background-size: 18px 18px; }
|
||||
.cv-empty { margin: auto; text-align: center; color: #54656f; font-size: 13px; line-height: 1.8; background: rgba(255,255,255,.75); padding: 12px 18px; border-radius: 10px; }
|
||||
.cv-day { display: flex; justify-content: center; margin: 8px 0 4px; }
|
||||
.cv-day span { background: #fff; color: #54656f; font-size: 11.5px; padding: 3px 12px; border-radius: 8px; box-shadow: 0 1px .5px rgba(0,0,0,.13); }
|
||||
.cv-row { display: flex; align-items: flex-start; gap: 4px; }
|
||||
.cv-row.me { flex-direction: row-reverse; }
|
||||
.cv-bub { position: relative; max-width: min(72%, 560px); background: #fff; border-radius: 0 10px 10px 10px; padding: 6px 9px 4px; box-shadow: 0 1px .5px rgba(0,0,0,.13); font-size: 13.5px; line-height: 1.5; color: #111b21; }
|
||||
.cv-row.me .cv-bub { background: #d9fdd3; border-radius: 10px 0 10px 10px; }
|
||||
.cv-bub-edit { max-width: 100%; width: 100%; display: grid; gap: 6px; padding: 10px; }
|
||||
.cv-bub-h { display: flex; align-items: center; gap: 10px; justify-content: space-between; margin-bottom: 2px; }
|
||||
.cv-who { font-size: 12.5px; color: #c2410c; }
|
||||
.cv-row.me .cv-who { color: #047857; }
|
||||
.cv-chtag { font-size: 10.5px; font-weight: 700; border: 1px solid; border-radius: 99px; padding: 0 7px; line-height: 16px; background: rgba(255,255,255,.6); white-space: nowrap; }
|
||||
.cv-txt { white-space: pre-wrap; word-break: break-word; }
|
||||
.cv-zh { white-space: pre-wrap; word-break: break-word; margin-top: 4px; padding-top: 4px; border-top: 1px dashed rgba(0,0,0,.15); color: #3b4a54; font-size: 13px; }
|
||||
.cv-zh.wait { color: #8696a0; font-size: 12px; }
|
||||
.cv-zh.wait button { border: 0; background: none; color: #2563eb; cursor: pointer; padding: 0; font-size: 12px; }
|
||||
.cv-time { text-align: right; font-size: 10.5px; color: #667781; margin-top: 1px; }
|
||||
.cv-tools { display: flex; flex-direction: column; gap: 2px; opacity: 0; transition: opacity .15s; padding-top: 2px; }
|
||||
.cv-row:hover .cv-tools { opacity: 1; }
|
||||
.cv-ico { border: 0; background: rgba(255,255,255,.85); border-radius: 6px; width: 24px; height: 22px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: #54656f; }
|
||||
.cv-ico:hover { background: #fff; color: #111b21; }
|
||||
.cv-imgs { display: grid; gap: 3px; margin: 2px 0 4px; }
|
||||
.cv-imgs.n1 { grid-template-columns: 1fr; } .cv-imgs.n2, .cv-imgs.n4 { grid-template-columns: 1fr 1fr; } .cv-imgs.n3 { grid-template-columns: 1fr 1fr 1fr; }
|
||||
.cv-imgs img { display: block; width: 100%; max-height: 260px; object-fit: cover; border-radius: 6px; background: #f0f2f5; }
|
||||
.cv-imgs.n1 img { width: auto; max-width: min(100%, 300px); max-height: 260px; }
|
||||
.cv-imgs.n2, .cv-imgs.n3, .cv-imgs.n4 { width: min(100%, 320px); }
|
||||
.cv-doc { display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,.05); border-radius: 7px; padding: 7px 9px; margin: 2px 0 4px; text-decoration: none; color: inherit; min-width: 220px; }
|
||||
.cv-doc:hover { background: rgba(0,0,0,.08); }
|
||||
.cv-doc-i { position: relative; width: 30px; height: 34px; border-radius: 4px; background: #64748b; color: #fff; display: inline-flex; align-items: center; justify-content: center; flex: none; }
|
||||
.cv-doc-i.pdf { background: #e5252a; }
|
||||
.cv-doc-i i { position: absolute; bottom: 1px; font-size: 7.5px; font-style: normal; font-weight: 700; }
|
||||
.cv-doc-i svg { margin-top: -6px; }
|
||||
.cv-doc-n { display: grid; min-width: 0; } .cv-doc-n b { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .cv-doc-n small { font-size: 11px; color: #667781; }
|
||||
.cv-note-card { align-self: center; width: min(92%, 680px); background: #fff8e1; border: 1px solid #f5e1a4; border-radius: 10px; padding: 8px 10px; font-size: 12.5px; }
|
||||
.cv-note-h { display: flex; gap: 8px; align-items: center; } .cv-note-h .cv-ico { margin-left: auto; }
|
||||
.cv-note-t { white-space: pre-wrap; word-break: break-word; font-family: inherit; margin: 4px 0; max-height: 360px; overflow: auto; }
|
||||
.cv-more { border: 0; background: none; color: #2563eb; cursor: pointer; padding: 0; font-size: 12px; }
|
||||
.cv-comp { background: #f0f2f5; border-top: 1px solid rgba(0,0,0,.06); padding: 8px 10px 10px; display: grid; gap: 6px; }
|
||||
.cv-comp-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
|
||||
.cv-seg { display: inline-flex; background: #fff; border: 1px solid var(--line); border-radius: 99px; padding: 2px; }
|
||||
.cv-seg button { border: 0; background: none; border-radius: 99px; padding: 3px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer; color: #54656f; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.cv-seg button.on { background: #c2410c; color: #fff; }
|
||||
.cv-seg button.on.me { background: #047857; }
|
||||
.cv-at { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; font-size: 12px; color: #54656f; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 2px 6px; }
|
||||
.cv-at input { border: 0; outline: 0; font-size: 12px; background: transparent; color: var(--ink); width: 168px; }
|
||||
.cv-at button { border: 0; background: none; cursor: pointer; padding: 0; display: inline-flex; color: #54656f; }
|
||||
.cv-comp-row { display: flex; gap: 6px; align-items: flex-end; }
|
||||
.cv-comp-row textarea { flex: 1; resize: none; border: 0; outline: 0; border-radius: 10px; padding: 9px 12px; font-family: inherit; font-size: 13.5px; line-height: 1.45; background: #fff; min-height: 40px; }
|
||||
.cv-clip { border: 0; background: none; width: 36px; height: 40px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: #54656f; border-radius: 50%; flex: none; }
|
||||
.cv-clip:hover { background: rgba(0,0,0,.06); }
|
||||
.cv-send { border: 0; width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: #fff; background: #c2410c; flex: none; }
|
||||
.cv-send.me { background: #00a884; }
|
||||
.cv-send:disabled { opacity: .5; cursor: default; }
|
||||
.cv-sel { width: auto; height: 30px; font-size: 12.5px; }
|
||||
@media (max-width: 760px) { .cv-bub { max-width: 86%; } .cv-at { margin-left: 0; } }
|
||||
.brand-vis { display: inline-flex; border: 1px solid var(--line); border-radius: 99px; overflow: hidden; font-weight: 500; }
|
||||
.brand-vis button { display: inline-flex; align-items: center; gap: 3px; border: 0; background: transparent; font-size: 11px; padding: 1px 8px; cursor: pointer; color: var(--ink-soft); }
|
||||
.brand-vis button.on { background: var(--ink); color: #fff; }
|
||||
|
|
@ -6260,79 +6327,138 @@ function folderPathLabel(folders, folderId) {
|
|||
// 记录和客户的沟通(邮件、WhatsApp、微信、电话、会议……):粘贴文字,或拖入 WhatsApp 导出(.txt / .zip)、邮件(.eml)、截图(自动识别文字)、PDF、Word。
|
||||
// 数据存在服务器的 conversations.json(不放进客户列表);AI 分析读这个客户的全部记录,给出总结、阶段、意向、需求、顾虑、下一步和跟进消息草稿。
|
||||
const CONVO_CH = {
|
||||
email: { label: '邮件', color: '#2563eb' },
|
||||
whatsapp: { label: 'WhatsApp', color: '#16a34a' },
|
||||
wechat: { label: '微信', color: '#15803d' },
|
||||
wechat: { label: '微信', color: '#07c160' },
|
||||
email: { label: '邮件', color: '#2563eb' },
|
||||
phone: { label: '电话', color: '#9333ea' },
|
||||
meeting: { label: '会议 / 面谈', color: '#c2410c' },
|
||||
other: { label: '其他', color: '#64748b' },
|
||||
};
|
||||
const CV_PICK = ['whatsapp', 'wechat', 'email']; // 输入框可选的渠道
|
||||
const CV_ME = 'Mike';
|
||||
const convoApi = async (method, url, body, isForm) => {
|
||||
const r = await fetch(url, { method, credentials: 'same-origin', headers: isForm || !body ? undefined : { 'Content-Type': 'application/json' }, body: isForm ? body : body ? JSON.stringify(body) : undefined });
|
||||
const j = await r.json().catch(() => ({}));
|
||||
if (!r.ok) throw new Error(j.error || `请求失败(${r.status})`);
|
||||
return j;
|
||||
};
|
||||
const cvToday = () => new Date(Date.now() - new Date().getTimezoneOffset() * 60000).toISOString().slice(0, 10);
|
||||
const cvNow = () => new Date(Date.now() - new Date().getTimezoneOffset() * 60000).toISOString().slice(0, 16); // 本地时间 YYYY-MM-DDTHH:mm
|
||||
const cvDayLabel = (d) => {
|
||||
const today = cvNow().slice(0, 10), y = new Date(Date.now() - 86400000 - new Date().getTimezoneOffset() * 60000).toISOString().slice(0, 10);
|
||||
if (d === today) return '今天'; if (d === y) return '昨天';
|
||||
const [Y, M, D] = d.split('-').map(Number);
|
||||
return `${Y} 年 ${M} 月 ${D} 日`;
|
||||
};
|
||||
const cvIsImg = (f) => /^image\//.test(f.mime || '') || /\.(jpe?g|png|webp|gif|bmp)$/i.test(f.stored || f.name || '');
|
||||
const cvSize = (n) => (n > 1048576 ? `${(n / 1048576).toFixed(1)} MB` : `${Math.max(1, Math.round((n || 0) / 1024))} KB`);
|
||||
|
||||
function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
||||
const custName = String(c.contact || '').replace(/\s*[((].*$/, '').trim() || c.company || '客户';
|
||||
const [data, setData] = useState(null);
|
||||
const [adding, setAdding] = useState(false);
|
||||
const [form, setForm] = useState({ channel: '', date: cvToday(), title: '', text: '', files: [] });
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [from, setFrom] = useState('customer');
|
||||
const [channel, setChannel] = useState('whatsapp');
|
||||
const [at, setAt] = useState(''); // 空 = 发送时用当前时间
|
||||
const [text, setText] = useState('');
|
||||
const [files, setFiles] = useState([]);
|
||||
const [sending, setSending] = useState(false);
|
||||
const [drag, setDrag] = useState(false);
|
||||
const [open, setOpen] = useState({});
|
||||
const [showZh, setShowZh] = useState(true);
|
||||
const [editId, setEditId] = useState(null);
|
||||
const [edit, setEdit] = useState(null);
|
||||
const [q, setQ] = useState('');
|
||||
const [chFilter, setChFilter] = useState('all');
|
||||
const [openNote, setOpenNote] = useState({});
|
||||
const [imp, setImp] = useState(null); // 导入面板:{ text, files, me, busy }
|
||||
const [trState, setTrState] = useState(''); // '' | 'busy' | 'error'
|
||||
const [aiBusy, setAiBusy] = useState(false);
|
||||
const [aiSecs, setAiSecs] = useState(0);
|
||||
const [aiOpen, setAiOpen] = useState(true);
|
||||
const [ask, setAsk] = useState('');
|
||||
const [answer, setAnswer] = useState(null);
|
||||
const [asking, setAsking] = useState(false);
|
||||
const fileRef = useRef(null);
|
||||
const fileRef = useRef(null), impRef = useRef(null), boxRef = useRef(null), taRef = useRef(null), trRun = useRef(false), cidRef = useRef(c.id);
|
||||
|
||||
const scrollEnd = () => setTimeout(() => { const b = boxRef.current; if (b) b.scrollTop = b.scrollHeight; }, 30);
|
||||
const load = async () => {
|
||||
try { setData(await convoApi('GET', `/api/convos/${c.id}`)); }
|
||||
try { const d = await convoApi('GET', `/api/convos/${c.id}`); if (cidRef.current !== c.id) return; setData(d); scrollEnd(); }
|
||||
catch (e) { setData({ items: [], analysis: null }); onNotify('读取沟通记录失败:' + e.message); }
|
||||
};
|
||||
useEffect(() => { setData(null); setAnswer(null); setAdding(false); setEditId(null); load(); }, [c.id]);
|
||||
useEffect(() => {
|
||||
cidRef.current = c.id;
|
||||
setData(null); setAnswer(null); setEditId(null); setImp(null); setText(''); setFiles([]); setAt(''); setTrState('');
|
||||
load();
|
||||
}, [c.id]);
|
||||
|
||||
const items = (data && data.items) || [];
|
||||
const an = data && data.analysis;
|
||||
const newer = an ? items.filter(x => (x.createdAt || 0) > an.at || (x.updatedAt || 0) > an.at).length : 0;
|
||||
const untranslated = items.filter(m => m.from !== 'note' && m.zh === undefined).length;
|
||||
|
||||
const addFiles = (list) => setForm(f => ({ ...f, files: [...f.files, ...Array.from(list || [])].slice(0, 10) }));
|
||||
async function submit() {
|
||||
if (!form.text.trim() && !form.files.length) { onNotify('请粘贴沟通内容或添加文件'); return; }
|
||||
// 自动把还没翻译的消息翻成中文(每次 30 条,直到全部完成)
|
||||
async function translateAll() {
|
||||
if (trRun.current) return;
|
||||
trRun.current = true; setTrState('busy');
|
||||
const cid = c.id;
|
||||
try {
|
||||
for (let guard = 0; guard < 200; guard++) {
|
||||
const j = await convoApi('POST', `/api/convos/${cid}/translate`, {});
|
||||
if (cidRef.current !== cid) break;
|
||||
if (j.done && j.done.length) {
|
||||
const map = new Map(j.done.map(x => [x.id, x.zh]));
|
||||
setData(d => (d ? { ...d, items: d.items.map(m => (map.has(m.id) ? { ...m, zh: map.get(m.id) } : m)) } : d));
|
||||
}
|
||||
if (!j.remaining || !(j.done && j.done.length)) break;
|
||||
}
|
||||
setTrState('');
|
||||
} catch (e) { setTrState('error'); }
|
||||
finally { trRun.current = false; }
|
||||
}
|
||||
useEffect(() => { if (untranslated > 0 && !trRun.current && trState !== 'error') translateAll(); }, [untranslated, data && c.id]);
|
||||
|
||||
const addFiles = (list) => { const a = Array.from(list || []); if (a.length) setFiles(f => [...f, ...a].slice(0, 10)); };
|
||||
async function send() {
|
||||
if (!text.trim() && !files.length) { taRef.current && taRef.current.focus(); return; }
|
||||
const fd = new FormData();
|
||||
['channel', 'date', 'title', 'text'].forEach(k => fd.append(k, form[k] || ''));
|
||||
form.files.forEach(f => fd.append('files', f));
|
||||
setSaving(true);
|
||||
fd.append('from', from); fd.append('channel', channel); fd.append('text', text);
|
||||
fd.append('at', (at || cvNow()).replace('T', ' '));
|
||||
files.forEach(f => fd.append('files', f));
|
||||
setSending(true);
|
||||
try {
|
||||
const j = await convoApi('POST', `/api/convos/${c.id}`, fd, true);
|
||||
setData(d => ({ ...(d || {}), items: [...((d && d.items) || []), j.item] }));
|
||||
setForm({ channel: '', date: cvToday(), title: '', text: '', files: [] });
|
||||
setAdding(false);
|
||||
onNotify(`已添加:${CONVO_CH[j.item.channel]?.label || ''}${j.item.stats?.messages ? `,${j.item.stats.messages} 条消息` : ''}`);
|
||||
} catch (e) { onNotify('添加失败:' + e.message); }
|
||||
finally { setSaving(false); }
|
||||
setText(''); setFiles([]); setAt('');
|
||||
setFrom(f => (f === 'customer' ? 'me' : 'customer')); // 一问一答:发完自动切换到另一方
|
||||
scrollEnd();
|
||||
setTimeout(() => taRef.current && taRef.current.focus(), 50);
|
||||
} catch (e) { onNotify('发送失败:' + e.message); }
|
||||
finally { setSending(false); }
|
||||
}
|
||||
async function doImport() {
|
||||
if (!imp.text.trim() && !imp.files.length) { onNotify('请选择导出的聊天文件,或粘贴聊天文字'); return; }
|
||||
const fd = new FormData();
|
||||
fd.append('text', imp.text); fd.append('me', imp.me || CV_ME);
|
||||
imp.files.forEach(f => fd.append('files', f));
|
||||
setImp(x => ({ ...x, busy: true }));
|
||||
try {
|
||||
const j = await convoApi('POST', `/api/convos/${c.id}/import`, fd, true);
|
||||
setData(d => ({ ...(d || {}), items: [...((d && d.items) || []), ...j.items] }));
|
||||
setImp(null); scrollEnd(); setTrState('');
|
||||
onNotify(`已导入 ${j.items.length} 条消息${j.skipped ? `(${j.skipped} 条已存在,跳过)` : ''}${!j.meFound && j.people && j.people.length ? `。注意:聊天里没找到"${imp.me}",发送人有:${j.people.join('、')}` : ''}`);
|
||||
} catch (e) { onNotify('导入失败:' + e.message); setImp(x => x && ({ ...x, busy: false })); }
|
||||
}
|
||||
async function saveEdit() {
|
||||
try {
|
||||
const j = await convoApi('PUT', `/api/convos/${c.id}/${editId}`, edit);
|
||||
const j = await convoApi('PUT', `/api/convos/${c.id}/${editId}`, { ...edit, at: edit.at.replace('T', ' ') });
|
||||
setData(d => ({ ...d, items: d.items.map(x => (x.id === editId ? j.item : x)) }));
|
||||
setEditId(null); onNotify('已保存');
|
||||
setEditId(null);
|
||||
} catch (e) { onNotify('保存失败:' + e.message); }
|
||||
}
|
||||
async function del(it) {
|
||||
if (!window.confirm(`删除这条${CONVO_CH[it.channel]?.label || ''}记录(${it.date}${it.title ? ' · ' + it.title : ''})?附件也会一起删除。`)) return;
|
||||
try { await convoApi('DELETE', `/api/convos/${c.id}/${it.id}`); setData(d => ({ ...d, items: d.items.filter(x => x.id !== it.id) })); onNotify('已删除'); }
|
||||
async function del(m) {
|
||||
if (!window.confirm(`删除这条消息?${(m.files || []).length ? '附件也会一起删除。' : ''}`)) return;
|
||||
try { await convoApi('DELETE', `/api/convos/${c.id}/${m.id}`); setData(d => ({ ...d, items: d.items.filter(x => x.id !== m.id) })); }
|
||||
catch (e) { onNotify('删除失败:' + e.message); }
|
||||
}
|
||||
async function analyze() {
|
||||
setAiBusy(true); setAiSecs(0);
|
||||
setAiBusy(true); setAiSecs(0); setAiOpen(true);
|
||||
const t0 = Date.now(), tick = setInterval(() => setAiSecs(Math.round((Date.now() - t0) / 1000)), 1000);
|
||||
try {
|
||||
const { jobId } = await convoApi('POST', `/api/convos/${c.id}/analyze`);
|
||||
|
|
@ -6357,51 +6483,48 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
|||
const copy = (t) => { navigator.clipboard.writeText(t).then(() => onNotify('已复制'), () => onNotify('复制失败,请手动选择')); };
|
||||
|
||||
const nq = q.trim().toLowerCase();
|
||||
const shown = [...items]
|
||||
.filter(x => chFilter === 'all' || x.channel === chFilter)
|
||||
.filter(x => !nq || [x.title, x.text, ...(x.files || []).map(f => f.name)].some(v => String(v || '').toLowerCase().includes(nq)))
|
||||
.sort((a, b) => String(b.date).localeCompare(String(a.date)) || (b.createdAt || 0) - (a.createdAt || 0));
|
||||
const sorted = [...items].sort((a, b) => String(a.at).localeCompare(String(b.at)) || (a.createdAt || 0) - (b.createdAt || 0));
|
||||
const shown = nq ? sorted.filter(m => [m.text, m.zh, m.title, ...(m.files || []).map(f => f.name)].some(v => String(v || '').toLowerCase().includes(nq))) : sorted;
|
||||
const R = an && an.result;
|
||||
const waDigits = String(c.phone || '').replace(/[^\d]/g, '');
|
||||
const nameOf = (m) => (m.from === 'me' ? CV_ME : (m.who && m.who !== CV_ME ? m.who : custName));
|
||||
const fileUrl = (f) => `/uploads/${c.id}/${encodeURIComponent(f.stored)}`;
|
||||
let lastDay = '';
|
||||
|
||||
return (
|
||||
<div className="field cv-wrap">
|
||||
<div className="cv-head">
|
||||
<span className="field-label" style={{ margin: 0 }}>沟通记录{items.length ? `(${items.length})` : ''}</span>
|
||||
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
|
||||
<button className="btn btn-sm" onClick={() => setAdding(a => !a)}><Plus size={13} />添加沟通记录</button>
|
||||
<button className="btn btn-sm btn-primary" disabled={!items.length || aiBusy} onClick={analyze} title={items.length ? '' : '先添加沟通记录'}>
|
||||
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', alignItems: 'center' }}>
|
||||
{items.length > 0 && (
|
||||
<div className="cv-search">
|
||||
<Search size={12} />
|
||||
<input value={q} onChange={e => setQ(e.target.value)} placeholder="搜索聊天" />
|
||||
{q && <button onClick={() => setQ('')}><X size={11} /></button>}
|
||||
</div>
|
||||
)}
|
||||
<button className={`btn btn-sm${showZh ? '' : ' btn-ghost'}`} onClick={() => setShowZh(v => !v)} title="显示 / 隐藏中文翻译"><Languages size={13} />中文对照{showZh ? ':开' : ':关'}</button>
|
||||
<button className="btn btn-sm" onClick={() => setImp(x => (x ? null : { text: '', files: [], me: CV_ME, busy: false }))}><Upload size={13} />导入聊天记录</button>
|
||||
<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 分析'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{adding && (
|
||||
<div className={`cv-add${drag ? ' drag' : ''}`}
|
||||
onDragOver={e => { e.preventDefault(); setDrag(true); }} onDragLeave={() => setDrag(false)}
|
||||
onDrop={e => { e.preventDefault(); setDrag(false); addFiles(e.dataTransfer.files); }}>
|
||||
{imp && (
|
||||
<div className="cv-imp">
|
||||
<div className="cv-imp-h"><b>导入整段聊天</b><small>WhatsApp:聊天 → ⋮ → 更多 → 导出聊天(选"附带媒体"会连图片一起导入,得到 .zip);邮件:下载原始邮件 .eml。也可以直接把 WhatsApp 聊天文字粘贴进来。</small></div>
|
||||
<div className="cv-add-row">
|
||||
<div className="cv-chips">
|
||||
<button type="button" className={`cv-chip${!form.channel ? ' on' : ''}`} onClick={() => setForm(f => ({ ...f, channel: '' }))}>自动识别</button>
|
||||
{Object.entries(CONVO_CH).map(([k, v]) => (
|
||||
<button type="button" key={k} className={`cv-chip${form.channel === k ? ' on' : ''}`} style={form.channel === k ? { background: v.color, borderColor: v.color } : undefined} onClick={() => setForm(f => ({ ...f, channel: k }))}>{v.label}</button>
|
||||
))}
|
||||
</div>
|
||||
<input type="date" className="input" style={{ width: 150 }} value={form.date} onChange={e => setForm(f => ({ ...f, date: e.target.value }))} title="沟通日期(邮件会自动用邮件日期)" />
|
||||
<button type="button" className="btn btn-sm" onClick={() => impRef.current && impRef.current.click()}><Paperclip size={12} />选择文件(.zip / .txt / .eml)</button>
|
||||
<input ref={impRef} type="file" multiple hidden accept=".txt,.zip,.eml" onChange={e => { const a = Array.from(e.target.files || []); setImp(x => ({ ...x, files: [...x.files, ...a].slice(0, 5) })); e.target.value = ''; }} />
|
||||
{imp.files.map((f, i) => <span key={i} className="cv-file"><Paperclip size={11} />{f.name}<button type="button" onClick={() => setImp(x => ({ ...x, files: x.files.filter((_, k) => k !== i) }))}><X size={11} /></button></span>)}
|
||||
<label className="cv-imp-me">聊天里我的名字 <input className="input" value={imp.me} onChange={e => setImp(x => ({ ...x, me: e.target.value }))} /></label>
|
||||
</div>
|
||||
<input className="input" placeholder="标题(可选,例如:首次询价 / 报价跟进;邮件会自动用主题)" value={form.title} onChange={e => setForm(f => ({ ...f, title: e.target.value }))} />
|
||||
<textarea className="textarea" rows={7} value={form.text} onChange={e => setForm(f => ({ ...f, text: e.target.value }))}
|
||||
placeholder={'把邮件、WhatsApp / 微信聊天、电话或会议记录粘贴到这里…\n\n也可以把文件拖到这个框里:\n· WhatsApp 导出的聊天(.txt 或 .zip):聊天 → ⋮ → 更多 → 导出聊天\n· 邮件文件(.eml):邮箱里"另存为 / 下载原始邮件"\n· 聊天截图(自动识别文字,英文和中文)、PDF、Word(.docx)'} />
|
||||
<div className="cv-files">
|
||||
{form.files.map((f, i) => (
|
||||
<span key={i} className="cv-file"><Paperclip size={11} />{f.name}<button type="button" onClick={() => setForm(x => ({ ...x, files: x.files.filter((_, k) => k !== i) }))}><X size={11} /></button></span>
|
||||
))}
|
||||
<button type="button" className="btn btn-sm btn-ghost" onClick={() => fileRef.current && fileRef.current.click()}><Upload size={12} />选择文件</button>
|
||||
<input ref={fileRef} type="file" multiple hidden accept=".txt,.zip,.eml,.pdf,.docx,.html,.htm,.csv,.md,image/*" onChange={e => { addFiles(e.target.files); e.target.value = ''; }} />
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 8, justifyContent: 'flex-end' }}>
|
||||
<button className="btn btn-sm btn-ghost" onClick={() => setAdding(false)}>取消</button>
|
||||
<button className="btn btn-sm btn-primary" disabled={saving} onClick={submit}>{saving ? '识别中…' : '保存'}</button>
|
||||
<textarea className="textarea" rows={4} value={imp.text} onChange={e => setImp(x => ({ ...x, text: e.target.value }))} placeholder={'或者粘贴 WhatsApp 聊天文字,例如:\n12/11/2026, 14:05 - Anton: Hello, price for 10kVA?\n12/11/2026, 14:30 - Mike: Hi Anton, ...'} />
|
||||
<div style={{ display: 'flex', gap: 8, justifyContent: 'flex-end', alignItems: 'center' }}>
|
||||
<small style={{ color: 'var(--ink-soft)', marginRight: 'auto' }}>名字是"{imp.me || CV_ME}"的算我,其他人都算客户;重复导入同一个聊天会自动跳过已有的消息。</small>
|
||||
<button className="btn btn-sm btn-ghost" onClick={() => setImp(null)}>取消</button>
|
||||
<button className="btn btn-sm btn-primary" disabled={imp.busy} onClick={doImport}>{imp.busy ? '导入中…' : '导入'}</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
|
@ -6413,9 +6536,11 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
|||
<span className="cv-ai-badge"><Sparkles size={12} />AI 分析</span>
|
||||
{R.stage && <span className="cv-stage">{R.stage}</span>}
|
||||
{R.intent && <span className={`cv-intent i-${R.intent === '高' ? 'h' : R.intent === '中' ? 'm' : 'l'}`}>意向:{R.intent}</span>}
|
||||
<span className="cv-ai-meta">{new Date(an.at).toLocaleString('zh-CN', { hour12: false })} · 基于 {an.count} 条记录{an.skipped ? `(最早 ${an.skipped} 条太长未放入)` : ''}</span>
|
||||
{newer > 0 && <span className="cv-stale">有 {newer} 条新记录,建议重新分析</span>}
|
||||
<span className="cv-ai-meta">{new Date(an.at).toLocaleString('zh-CN', { hour12: false })} · 基于 {an.count} 条消息{an.skipped ? `(最早 ${an.skipped} 条太长未放入)` : ''}</span>
|
||||
{newer > 0 && <span className="cv-stale">有 {newer} 条新消息,建议重新分析</span>}
|
||||
<button className="btn btn-sm btn-ghost" style={{ marginLeft: 'auto' }} onClick={() => setAiOpen(v => !v)}>{aiOpen ? '收起' : '展开'}</button>
|
||||
</div>
|
||||
{aiOpen && (<>
|
||||
{R.summary && <p className="cv-sum">{R.summary}</p>}
|
||||
{R.intentReason && <div className="cv-reason">{R.intentReason}</div>}
|
||||
<div className="cv-grid">
|
||||
|
|
@ -6451,81 +6576,146 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
|||
</div>
|
||||
)}
|
||||
{Array.isArray(R.tags) && R.tags.length > 0 && <div className="cv-tags">{R.tags.map((t, i) => <span key={i}>{t}</span>)}</div>}
|
||||
</>)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
{/* 问 AI */}
|
||||
{items.length > 0 && (
|
||||
<div className="cv-ask">
|
||||
<input className="input" value={ask} onChange={e => setAsk(e.target.value)} onKeyDown={e => { if (e.key === 'Enter') doAsk(); }} placeholder="问 AI 关于这个客户的沟通,比如:我们上次报的什么价?他要的后备时间是多少?" />
|
||||
<input className="input" value={ask} onChange={e => setAsk(e.target.value)} onKeyDown={e => { if (e.key === 'Enter') doAsk(); }} placeholder={`问 AI 关于和 ${custName} 的沟通,比如:上次报的什么价?他要的后备时间是多少?`} />
|
||||
<button className="btn btn-sm" disabled={asking || !ask.trim()} onClick={doAsk}><Sparkles size={12} />{asking ? '思考中…' : '提问'}</button>
|
||||
</div>
|
||||
)}
|
||||
{answer && <div className="cv-answer"><b>问:{answer.q}</b><div>{answer.a}</div></div>}
|
||||
|
||||
{/* 记录列表 */}
|
||||
{items.length > 0 && (
|
||||
<div className="cv-filter">
|
||||
<div className="cv-chips">
|
||||
{[['all', '全部'], ...Object.entries(CONVO_CH).filter(([k]) => items.some(x => x.channel === k)).map(([k, v]) => [k, v.label])].map(([k, l]) => (
|
||||
<button type="button" key={k} className={`cv-chip${chFilter === k ? ' on' : ''}`} onClick={() => setChFilter(k)}>{l}{k !== 'all' ? ` ${items.filter(x => x.channel === k).length}` : ''}</button>
|
||||
))}
|
||||
</div>
|
||||
<div style={{ position: 'relative', flex: '0 1 240px' }}>
|
||||
<Search size={13} style={{ position: 'absolute', left: 9, top: '50%', transform: 'translateY(-50%)', color: 'var(--ink-soft)' }} />
|
||||
<input className="input" style={{ paddingLeft: 28 }} value={q} onChange={e => setQ(e.target.value)} placeholder="搜索记录内容" />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{data === null ? <div className="row-sub" style={{ padding: '8px 0' }}>加载中…</div>
|
||||
: items.length === 0 ? <div className="row-sub" style={{ padding: '8px 0' }}>还没有沟通记录。点"添加沟通记录",粘贴邮件或聊天内容,或拖入 WhatsApp 导出文件、邮件、截图。</div>
|
||||
: shown.length === 0 ? <div className="row-sub" style={{ padding: '8px 0' }}>没有匹配的记录</div>
|
||||
: (
|
||||
<div className="cv-list">
|
||||
{shown.map(it => {
|
||||
const ch = CONVO_CH[it.channel] || CONVO_CH.other;
|
||||
const isOpen = !!open[it.id];
|
||||
const lines = String(it.text || '').split('\n');
|
||||
return (
|
||||
<div key={it.id} className="cv-item" style={{ borderLeftColor: ch.color }}>
|
||||
{editId === it.id ? (
|
||||
<div className="cv-edit">
|
||||
<div className="cv-add-row">
|
||||
<select className="input" style={{ width: 'auto' }} value={edit.channel} onChange={e => setEdit(x => ({ ...x, channel: e.target.value }))}>{Object.entries(CONVO_CH).map(([k, v]) => <option key={k} value={k}>{v.label}</option>)}</select>
|
||||
<input type="date" className="input" style={{ width: 150 }} value={edit.date} onChange={e => setEdit(x => ({ ...x, date: e.target.value }))} />
|
||||
<input className="input" style={{ flex: 1 }} value={edit.title} placeholder="标题" onChange={e => setEdit(x => ({ ...x, title: e.target.value }))} />
|
||||
</div>
|
||||
<textarea className="textarea" rows={8} value={edit.text} onChange={e => setEdit(x => ({ ...x, text: e.target.value }))} />
|
||||
<div style={{ display: 'flex', gap: 8, justifyContent: 'flex-end' }}>
|
||||
<button className="btn btn-sm btn-ghost" onClick={() => setEditId(null)}>取消</button>
|
||||
<button className="btn btn-sm btn-primary" onClick={saveEdit}>保存</button>
|
||||
</div>
|
||||
{/* 聊天窗口 */}
|
||||
<div className={`cv-chat${drag ? ' drag' : ''}`}
|
||||
onDragOver={e => { if (e.dataTransfer.types.includes('Files')) { e.preventDefault(); setDrag(true); } }}
|
||||
onDragLeave={e => { if (!e.currentTarget.contains(e.relatedTarget)) setDrag(false); }}
|
||||
onDrop={e => { e.preventDefault(); setDrag(false); addFiles(e.dataTransfer.files); }}>
|
||||
<div className="cv-msgs" ref={boxRef}>
|
||||
{data === null ? <div className="cv-empty">加载中…</div>
|
||||
: items.length === 0 ? <div className="cv-empty">还没有沟通记录。<br />在下面选择是 <b>{custName}</b> 说的还是 <b>{CV_ME}</b> 回复的,输入内容发送;<br />也可以附图片、PDF,或者用右上角"导入聊天记录"一次导入 WhatsApp 导出 / 邮件。</div>
|
||||
: shown.length === 0 ? <div className="cv-empty">没有匹配"{q}"的消息</div>
|
||||
: shown.map(m => {
|
||||
const day = String(m.at || '').slice(0, 10);
|
||||
const sep = day !== lastDay ? <div className="cv-day"><span>{cvDayLabel(day)}</span></div> : null;
|
||||
lastDay = day;
|
||||
const ch = CONVO_CH[m.channel] || CONVO_CH.other;
|
||||
if (m.from === 'note') {
|
||||
const open = !!openNote[m.id], lines = String(m.text || '').split('\n');
|
||||
return (
|
||||
<React.Fragment key={m.id}>{sep}
|
||||
<div className="cv-note-card">
|
||||
<div className="cv-note-h"><span style={{ color: ch.color, fontWeight: 700 }}>{ch.label}</span><b>{m.title || '导入的记录'}</b>
|
||||
<button className="cv-ico" title="删除" onClick={() => del(m)}><Trash2 size={12} /></button></div>
|
||||
<pre className="cv-note-t">{open ? m.text : lines.slice(0, 6).join('\n')}</pre>
|
||||
{lines.length > 6 && <button className="cv-more" onClick={() => setOpenNote(o => ({ ...o, [m.id]: !open }))}>{open ? '收起' : `展开全部(${lines.length} 行)`}</button>}
|
||||
{(m.files || []).map(f => <a key={f.stored} className="cv-file" href={fileUrl(f)} target="_blank" rel="noreferrer"><Paperclip size={11} />{f.name}</a>)}
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="cv-item-h">
|
||||
<span className="cv-ch" style={{ background: ch.color }}>{ch.label}</span>
|
||||
<b>{it.date}</b>
|
||||
{it.title && <span className="cv-title">{it.title}</span>}
|
||||
{it.stats && it.stats.messages ? <small>{it.stats.messages} 条消息{it.stats.people ? ` · ${it.stats.people.map(p => p.n).slice(0, 3).join('、')}` : ''}{it.stats.media ? ` · ${it.stats.media} 个图片/附件未导入` : ''}</small> : null}
|
||||
<span style={{ marginLeft: 'auto', display: 'flex', gap: 4 }}>
|
||||
<button className="btn btn-sm btn-ghost" title="编辑" onClick={() => { setEditId(it.id); setEdit({ channel: it.channel, date: it.date, title: it.title || '', text: it.text || '' }); }}><Edit2 size={12} /></button>
|
||||
<button className="btn btn-sm btn-ghost btn-danger" title="删除" onClick={() => del(it)}><Trash2 size={12} /></button>
|
||||
</span>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
const mine = m.from === 'me';
|
||||
const imgs = (m.files || []).filter(cvIsImg), docs = (m.files || []).filter(f => !cvIsImg(f));
|
||||
return (
|
||||
<React.Fragment key={m.id}>{sep}
|
||||
<div className={`cv-row ${mine ? 'me' : 'cu'}`}>
|
||||
{editId === m.id ? (
|
||||
<div className="cv-bub cv-bub-edit">
|
||||
<div className="cv-add-row">
|
||||
<div className="cv-seg">
|
||||
<button className={edit.from === 'customer' ? 'on' : ''} onClick={() => setEdit(x => ({ ...x, from: 'customer' }))}>{custName}</button>
|
||||
<button className={edit.from === 'me' ? 'on' : ''} onClick={() => setEdit(x => ({ ...x, from: 'me' }))}>{CV_ME}</button>
|
||||
</div>
|
||||
<select className="input cv-sel" value={edit.channel} onChange={e => setEdit(x => ({ ...x, channel: e.target.value }))}>{Object.entries(CONVO_CH).map(([k, v]) => <option key={k} value={k}>{v.label}</option>)}</select>
|
||||
<input type="datetime-local" className="input cv-sel" value={edit.at} onChange={e => setEdit(x => ({ ...x, at: e.target.value }))} />
|
||||
</div>
|
||||
<textarea className="textarea" rows={4} value={edit.text} onChange={e => setEdit(x => ({ ...x, text: e.target.value }))} />
|
||||
<textarea className="textarea" rows={2} value={edit.zh} placeholder="中文翻译(改了原文会自动重新翻译)" onChange={e => setEdit(x => ({ ...x, zh: e.target.value }))} />
|
||||
<div style={{ display: 'flex', gap: 6, justifyContent: 'flex-end' }}>
|
||||
<button className="btn btn-sm btn-ghost" onClick={() => setEditId(null)}>取消</button>
|
||||
<button className="btn btn-sm btn-primary" onClick={saveEdit}>保存</button>
|
||||
</div>
|
||||
</div>
|
||||
{(it.notes || []).map((n, i) => <div key={i} className="cv-note">{n}</div>)}
|
||||
{it.text && <pre className={`cv-text${isOpen ? ' open' : ''}`}>{isOpen ? it.text : lines.slice(0, 5).join('\n')}</pre>}
|
||||
<div className="cv-item-f">
|
||||
{lines.length > 5 && <button className="btn btn-sm btn-ghost" onClick={() => setOpen(o => ({ ...o, [it.id]: !isOpen }))}>{isOpen ? '收起' : `展开全部(${lines.length} 行)`}</button>}
|
||||
{(it.files || []).map(f => <a key={f.stored} className="cv-file" href={`/uploads/${c.id}/${encodeURIComponent(f.stored)}`} target="_blank" rel="noreferrer"><Paperclip size={11} />{f.name}</a>)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="cv-bub">
|
||||
<div className="cv-bub-h">
|
||||
<b className="cv-who">{nameOf(m)}</b>
|
||||
<span className="cv-chtag" style={{ color: ch.color, borderColor: ch.color + '55' }}>{ch.label}</span>
|
||||
</div>
|
||||
{imgs.length > 0 && (
|
||||
<div className={`cv-imgs n${Math.min(imgs.length, 4)}`}>
|
||||
{imgs.map(f => <a key={f.stored} href={fileUrl(f)} target="_blank" rel="noreferrer"><img src={fileUrl(f)} alt={f.name} loading="lazy" /></a>)}
|
||||
</div>
|
||||
)}
|
||||
{docs.map(f => {
|
||||
const ext = (String(f.name).split('.').pop() || '').toUpperCase().slice(0, 4);
|
||||
return (
|
||||
<a key={f.stored} className="cv-doc" href={fileUrl(f)} target="_blank" rel="noreferrer">
|
||||
<span className={`cv-doc-i${ext === 'PDF' ? ' pdf' : ''}`}><FileText size={16} /><i>{ext}</i></span>
|
||||
<span className="cv-doc-n"><b>{f.name}</b><small>{cvSize(f.size)}</small></span>
|
||||
</a>
|
||||
);
|
||||
})}
|
||||
{m.text && <div className="cv-txt" dir="auto">{m.text}</div>}
|
||||
{showZh && m.text && (m.zh ? <div className="cv-zh">{m.zh}</div>
|
||||
: m.zh === undefined ? <div className="cv-zh wait">{trState === 'error' ? <>翻译失败 <button onClick={() => { setTrState(''); translateAll(); }}>重试</button></> : '翻译中…'}</div> : null)}
|
||||
<div className="cv-time">{String(m.at || '').slice(11, 16)}{m.updatedAt ? ' · 已编辑' : ''}</div>
|
||||
</div>
|
||||
<div className="cv-tools">
|
||||
<button className="cv-ico" title="编辑" onClick={() => { setEditId(m.id); setEdit({ from: m.from, channel: m.channel, at: String(m.at || '').replace(' ', 'T'), text: m.text || '', zh: m.zh || '' }); }}><Edit2 size={12} /></button>
|
||||
<button className="cv-ico" title="复制" onClick={() => copy(m.text || '')}><Copy size={12} /></button>
|
||||
<button className="cv-ico" title="删除" onClick={() => del(m)}><Trash2 size={12} /></button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</React.Fragment>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* 输入框 */}
|
||||
<div className="cv-comp">
|
||||
<div className="cv-comp-top">
|
||||
<div className="cv-seg" title="这句话是谁说的">
|
||||
<button className={from === 'customer' ? 'on cu' : ''} onClick={() => setFrom('customer')}>{custName}</button>
|
||||
<button className={from === 'me' ? 'on me' : ''} onClick={() => setFrom('me')}>{CV_ME}</button>
|
||||
</div>
|
||||
<div className="cv-chips">
|
||||
{CV_PICK.map(k => (
|
||||
<button type="button" key={k} className={`cv-chip${channel === k ? ' on' : ''}`} style={channel === k ? { background: CONVO_CH[k].color, borderColor: CONVO_CH[k].color } : undefined} onClick={() => setChannel(k)}>{CONVO_CH[k].label}</button>
|
||||
))}
|
||||
</div>
|
||||
<label className="cv-at" title="消息时间(不填就是现在)">
|
||||
<Clock size={12} />
|
||||
<input type="datetime-local" value={at} onChange={e => setAt(e.target.value)} />
|
||||
{at ? <button onClick={() => setAt('')} title="改回现在"><X size={11} /></button> : <span>现在</span>}
|
||||
</label>
|
||||
</div>
|
||||
)}
|
||||
{files.length > 0 && (
|
||||
<div className="cv-files">
|
||||
{files.map((f, i) => (
|
||||
<span key={i} className="cv-file"><Paperclip size={11} />{f.name}<button type="button" onClick={() => setFiles(x => x.filter((_, k) => k !== i))}><X size={11} /></button></span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div className="cv-comp-row">
|
||||
<button className="cv-clip" title="附件(图片、PDF、Word 等,也可以直接拖进来或粘贴截图)" onClick={() => fileRef.current && fileRef.current.click()}><Paperclip size={17} /></button>
|
||||
<input ref={fileRef} type="file" multiple hidden onChange={e => { addFiles(e.target.files); e.target.value = ''; }} />
|
||||
<textarea ref={taRef} rows={Math.min(8, Math.max(1, text.split('\n').length))} value={text}
|
||||
onChange={e => setText(e.target.value)}
|
||||
onPaste={e => { const fs = Array.from(e.clipboardData.files || []); if (fs.length) { e.preventDefault(); addFiles(fs); } }}
|
||||
onKeyDown={e => { if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) { e.preventDefault(); send(); } }}
|
||||
placeholder={from === 'me' ? `输入 ${CV_ME} 的回复…(Ctrl+Enter 发送)` : `输入 ${custName} 说的话…(Ctrl+Enter 发送)`} />
|
||||
<button className={`cv-send ${from === 'me' ? 'me' : 'cu'}`} disabled={sending} onClick={send} title="发送"><Send size={16} /></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue