Update App.jsx via upload script - 2026-11-16 23:44:39
This commit is contained in:
parent
685da99380
commit
339ee41154
142
App.jsx
142
App.jsx
|
|
@ -2286,6 +2286,13 @@ const Styles = () => (
|
||||||
.cv-imp-h { display: grid; gap: 2px; } .cv-imp-h small { color: var(--ink-soft); font-size: 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 { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; margin-left: auto; }
|
||||||
.cv-imp-me .input { width: 110px; height: 30px; }
|
.cv-imp-me .input { width: 110px; height: 30px; }
|
||||||
|
.cv-bub.wide { max-width: min(96%, 980px); }
|
||||||
|
.cv-xt-wrap { overflow-x: auto; margin: 3px 0 5px; max-width: 100%; }
|
||||||
|
.cv-xt { border-collapse: collapse; table-layout: fixed; background: #fff; font-size: 12.5px; line-height: 1.35; color: #111; }
|
||||||
|
.cv-xt td { border: 1px solid #b7bcc2; padding: 3px 6px; white-space: pre-wrap; word-break: break-word; vertical-align: middle; }
|
||||||
|
.cv-rich-pend { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; }
|
||||||
|
.cv-rich-h { display: flex; justify-content: space-between; align-items: center; font-size: 11.5px; color: var(--ink-soft); margin-bottom: 4px; }
|
||||||
|
.cv-rich-body { max-height: 260px; overflow: auto; }
|
||||||
.cv-imp-lbl { font-size: 12px; color: var(--ink-soft); margin-left: 6px; }
|
.cv-imp-lbl { font-size: 12px; color: var(--ink-soft); margin-left: 6px; }
|
||||||
.cv-prev { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); max-height: 300px; overflow: auto; }
|
.cv-prev { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); max-height: 300px; overflow: auto; }
|
||||||
.cv-prev-h { position: sticky; top: 0; background: var(--panel); font-size: 12.5px; font-weight: 700; padding: 6px 10px; border-bottom: 1px solid var(--line); }
|
.cv-prev-h { position: sticky; top: 0; background: var(--panel); font-size: 12.5px; font-weight: 700; padding: 6px 10px; border-bottom: 1px solid var(--line); }
|
||||||
|
|
@ -6436,6 +6443,92 @@ function cvParsePaste(raw, names) {
|
||||||
return [{ who: '', at: null, text: t }];
|
return [{ who: '', at: null, text: t }];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- 从 Excel / 邮件复制的表格:把剪贴板里的 HTML 放进隐藏 iframe 里渲染,读出每个格子的显示文字和样式 ----
|
||||||
|
const cvHex = (c) => {
|
||||||
|
const m = String(c || '').match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);
|
||||||
|
if (!m || (m[4] !== undefined && +m[4] < 0.05)) return '';
|
||||||
|
return '#' + [m[1], m[2], m[3]].map(n => (+n).toString(16).padStart(2, '0')).join('');
|
||||||
|
};
|
||||||
|
function cvHtmlToBlocks(html) {
|
||||||
|
if (!/<table[\s>]/i.test(html || '')) return null;
|
||||||
|
const ifr = document.createElement('iframe');
|
||||||
|
ifr.setAttribute('sandbox', 'allow-same-origin');
|
||||||
|
ifr.style.cssText = 'position:fixed;left:-12000px;top:0;width:1400px;height:900px;border:0;';
|
||||||
|
document.body.appendChild(ifr);
|
||||||
|
try {
|
||||||
|
const doc = ifr.contentDocument;
|
||||||
|
doc.open(); doc.write(String(html).replace(/<script[\s\S]*?<\/script>/gi, '')); doc.close();
|
||||||
|
const win = ifr.contentWindow;
|
||||||
|
const blocks = []; let buf = '';
|
||||||
|
const flush = () => { const v = buf.replace(/[ \t ]+\n/g, '\n').replace(/\n{3,}/g, '\n\n').trim(); if (v) blocks.push({ t: 'text', v }); buf = ''; };
|
||||||
|
const tableOf = (tbl) => {
|
||||||
|
const rows = [], colW = [];
|
||||||
|
for (const tr of Array.from(tbl.rows).slice(0, 300)) {
|
||||||
|
const trBg = cvHex(win.getComputedStyle(tr).backgroundColor);
|
||||||
|
let ci = 0;
|
||||||
|
const row = Array.from(tr.cells).slice(0, 40).map(td => {
|
||||||
|
const st = win.getComputedStyle(td);
|
||||||
|
const cell = { v: String(td.innerText || '').replace(/ /g, ' ').replace(/\n+$/, '').trim() };
|
||||||
|
const bg = cvHex(st.backgroundColor) || trBg; if (bg && bg !== '#ffffff') cell.bg = bg;
|
||||||
|
const col = cvHex(st.color); if (col && col !== '#000000') cell.color = col;
|
||||||
|
if (parseInt(st.fontWeight, 10) >= 600) cell.b = 1;
|
||||||
|
if (st.fontStyle === 'italic') cell.i = 1;
|
||||||
|
const al = st.textAlign; if (['center', 'right', 'end', '-webkit-center', '-webkit-right'].includes(al)) cell.align = /center/.test(al) ? 'center' : 'right';
|
||||||
|
if (td.colSpan > 1) cell.cs = td.colSpan; if (td.rowSpan > 1) cell.rs = td.rowSpan;
|
||||||
|
if (td.colSpan === 1) colW[ci] = Math.max(colW[ci] || 0, Math.round(td.getBoundingClientRect().width));
|
||||||
|
ci += td.colSpan || 1;
|
||||||
|
return cell;
|
||||||
|
});
|
||||||
|
rows.push(row);
|
||||||
|
}
|
||||||
|
if (!rows.some(r => r.some(c => c.v))) return null;
|
||||||
|
const t = { t: 'table', rows };
|
||||||
|
if (colW.length && colW.every(Boolean)) t.widths = colW;
|
||||||
|
return t;
|
||||||
|
};
|
||||||
|
const walk = (node) => {
|
||||||
|
for (const ch of Array.from(node.childNodes)) {
|
||||||
|
if (ch.nodeType === 3) { buf += ch.textContent.replace(/\s+/g, ' '); continue; }
|
||||||
|
if (ch.nodeType !== 1 || /^(STYLE|SCRIPT|HEAD|META|TITLE|LINK|XML)$/i.test(ch.tagName)) continue;
|
||||||
|
if (ch.tagName === 'TABLE') { flush(); const t = tableOf(ch); if (t) blocks.push(t); continue; }
|
||||||
|
if (ch.tagName === 'BR') { buf += '\n'; continue; }
|
||||||
|
if (ch.querySelector('table')) { walk(ch); continue; }
|
||||||
|
const disp = win.getComputedStyle(ch).display;
|
||||||
|
const tx = ch.innerText || '';
|
||||||
|
if (disp === 'inline' || disp === 'inline-block') buf += tx; else buf += (buf && !buf.endsWith('\n') ? '\n' : '') + tx + '\n';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
walk(doc.body);
|
||||||
|
flush();
|
||||||
|
return blocks.some(b => b.t === 'table') ? blocks : null;
|
||||||
|
} catch (e) { return null; }
|
||||||
|
finally { ifr.remove(); }
|
||||||
|
}
|
||||||
|
// 只有纯文字、但是用 Tab 分隔的多行(比如某些表格软件复制出来的)→ 也当表格
|
||||||
|
function cvTsvBlocks(text) {
|
||||||
|
const lines = String(text || '').replace(/\r\n?/g, '\n').replace(/\n+$/, '').split('\n');
|
||||||
|
if (lines.length < 2 || lines.filter(l => l.includes('\t')).length < Math.max(2, lines.length * 0.6)) return null;
|
||||||
|
return [{ t: 'table', rows: lines.slice(0, 300).map(l => l.split('\t').slice(0, 40).map(v => ({ v: v.trim() }))) }];
|
||||||
|
}
|
||||||
|
// 剪贴板里有表格就返回内容块,否则 null(让默认的粘贴文字 / 图片处理接手)
|
||||||
|
const cvClipBlocks = (cd) => cvHtmlToBlocks(cd.getData('text/html')) || cvTsvBlocks(cd.getData('text/plain'));
|
||||||
|
function CvBlocks({ blocks }) {
|
||||||
|
return (blocks || []).map((b, i) => (b.t === 'text'
|
||||||
|
? <div key={i} className="cv-txt" dir="auto">{b.v}</div>
|
||||||
|
: (
|
||||||
|
<div key={i} className="cv-xt-wrap">
|
||||||
|
<table className="cv-xt" style={b.widths ? { width: b.widths.reduce((a, w) => a + w, 0) } : undefined}>
|
||||||
|
{b.widths && <colgroup>{b.widths.map((w, k) => <col key={k} style={{ width: w }} />)}</colgroup>}
|
||||||
|
<tbody>{b.rows.map((r, ri) => <tr key={ri}>{r.map((c, ci) => (
|
||||||
|
<td key={ci} colSpan={c.cs || undefined} rowSpan={c.rs || undefined}
|
||||||
|
style={{ background: c.bg, color: c.color, fontWeight: c.b ? 700 : undefined, fontStyle: c.i ? 'italic' : undefined, textAlign: c.align }}>{c.v}</td>
|
||||||
|
))}</tr>)}</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
const cvBlocksSummary = (bl) => { const t = (bl || []).find(b => b.t === 'table'); return t ? `表格 ${t.rows.length} 行 × ${Math.max(...t.rows.map(r => r.reduce((a, c) => a + (c.cs || 1), 0)))} 列` : ''; };
|
||||||
|
|
||||||
function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
||||||
const custName = String(c.contact || '').replace(/\s*[((].*$/, '').trim() || c.company || '客户';
|
const custName = String(c.contact || '').replace(/\s*[((].*$/, '').trim() || c.company || '客户';
|
||||||
const [data, setData] = useState(null);
|
const [data, setData] = useState(null);
|
||||||
|
|
@ -6444,6 +6537,7 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
||||||
const [at, setAt] = useState(''); // 空 = 发送时用当前时间
|
const [at, setAt] = useState(''); // 空 = 发送时用当前时间
|
||||||
const [text, setText] = useState('');
|
const [text, setText] = useState('');
|
||||||
const [files, setFiles] = useState([]);
|
const [files, setFiles] = useState([]);
|
||||||
|
const [rich, setRich] = useState([]); // 粘贴进来的表格等富内容
|
||||||
const [sending, setSending] = useState(false);
|
const [sending, setSending] = useState(false);
|
||||||
const [drag, setDrag] = useState(false);
|
const [drag, setDrag] = useState(false);
|
||||||
const [showZh, setShowZh] = useState(true);
|
const [showZh, setShowZh] = useState(true);
|
||||||
|
|
@ -6468,7 +6562,7 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
||||||
};
|
};
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
cidRef.current = c.id;
|
cidRef.current = c.id;
|
||||||
setData(null); setAnswer(null); setEditId(null); setImp(null); setText(''); setFiles([]); setAt(''); setTrState('');
|
setData(null); setAnswer(null); setEditId(null); setImp(null); setText(''); setFiles([]); setRich([]); setAt(''); setTrState('');
|
||||||
load();
|
load();
|
||||||
}, [c.id]);
|
}, [c.id]);
|
||||||
|
|
||||||
|
|
@ -6500,23 +6594,24 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
||||||
|
|
||||||
const addFiles = (list) => { const a = Array.from(list || []); if (a.length) setFiles(f => [...f, ...a].slice(0, 10)); };
|
const addFiles = (list) => { const a = Array.from(list || []); if (a.length) setFiles(f => [...f, ...a].slice(0, 10)); };
|
||||||
async function send() {
|
async function send() {
|
||||||
if (!text.trim() && !files.length) { taRef.current && taRef.current.focus(); return; }
|
if (!text.trim() && !files.length && !rich.length) { taRef.current && taRef.current.focus(); return; }
|
||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
fd.append('from', from); fd.append('channel', channel); fd.append('text', text);
|
fd.append('from', from); fd.append('channel', channel); fd.append('text', text);
|
||||||
|
if (rich.length) fd.append('blocks', JSON.stringify([...(text.trim() ? [{ t: 'text', v: text }] : []), ...rich]));
|
||||||
fd.append('at', (at || cvNow()).replace('T', ' '));
|
fd.append('at', (at || cvNow()).replace('T', ' '));
|
||||||
files.forEach(f => fd.append('files', f));
|
files.forEach(f => fd.append('files', f));
|
||||||
setSending(true);
|
setSending(true);
|
||||||
try {
|
try {
|
||||||
const j = await convoApi('POST', `/api/convos/${c.id}`, fd, true);
|
const j = await convoApi('POST', `/api/convos/${c.id}`, fd, true);
|
||||||
setData(d => ({ ...(d || {}), items: [...((d && d.items) || []), j.item] }));
|
setData(d => ({ ...(d || {}), items: [...((d && d.items) || []), j.item] }));
|
||||||
setText(''); setFiles([]); setAt('');
|
setText(''); setFiles([]); setRich([]); setAt('');
|
||||||
setFrom(f => (f === 'customer' ? 'me' : 'customer')); // 一问一答:发完自动切换到另一方
|
setFrom(f => (f === 'customer' ? 'me' : 'customer')); // 一问一答:发完自动切换到另一方
|
||||||
scrollEnd();
|
scrollEnd();
|
||||||
setTimeout(() => taRef.current && taRef.current.focus(), 50);
|
setTimeout(() => taRef.current && taRef.current.focus(), 50);
|
||||||
} catch (e) { onNotify('发送失败:' + e.message); }
|
} catch (e) { onNotify('发送失败:' + e.message); }
|
||||||
finally { setSending(false); }
|
finally { setSending(false); }
|
||||||
}
|
}
|
||||||
const newImp = () => ({ text: '', files: [], defFrom: 'customer', channel: 'whatsapp', at: '', over: {}, removed: {}, busy: false });
|
const newImp = () => ({ text: '', files: [], rich: [], defFrom: 'customer', channel: 'whatsapp', at: '', over: {}, removed: {}, busy: false });
|
||||||
const impAddFiles = (list) => {
|
const impAddFiles = (list) => {
|
||||||
const a = Array.from(list || []).map(f => ({ file: f, url: /^image\//.test(f.type) ? URL.createObjectURL(f) : '' }));
|
const a = Array.from(list || []).map(f => ({ file: f, url: /^image\//.test(f.type) ? URL.createObjectURL(f) : '' }));
|
||||||
if (a.length) setImp(x => ({ ...x, files: [...x.files, ...a].slice(0, 30) }));
|
if (a.length) setImp(x => ({ ...x, files: [...x.files, ...a].slice(0, 30) }));
|
||||||
|
|
@ -6531,6 +6626,7 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
||||||
at: r.at || (r.time ? `${base.slice(0, 10)} ${r.time.padStart(5, '0')}` : null),
|
at: r.at || (r.time ? `${base.slice(0, 10)} ${r.time.padStart(5, '0')}` : null),
|
||||||
from: imp.over['t' + i] || (r.who ? (cvSameName(r.who, CV_ME) ? 'me' : 'customer') : imp.defFrom),
|
from: imp.over['t' + i] || (r.who ? (cvSameName(r.who, CV_ME) ? 'me' : 'customer') : imp.defFrom),
|
||||||
}));
|
}));
|
||||||
|
imp.rich.forEach((bl, i) => rows.push({ key: 'r' + i, blocks: bl, text: '', at: null, from: imp.over['r' + i] || imp.defFrom }));
|
||||||
imp.files.forEach((f, i) => rows.push({ key: 'f' + i, file: i, f, text: '', at: null, from: imp.over['f' + i] || imp.defFrom }));
|
imp.files.forEach((f, i) => rows.push({ key: 'f' + i, file: i, f, text: '', at: null, from: imp.over['f' + i] || imp.defFrom }));
|
||||||
return rows.filter(r => !imp.removed[r.key]);
|
return rows.filter(r => !imp.removed[r.key]);
|
||||||
})();
|
})();
|
||||||
|
|
@ -6541,6 +6637,7 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
||||||
const messages = impRows.map(r => {
|
const messages = impRows.map(r => {
|
||||||
const m = { from: r.from, channel: imp.channel, at: r.at || '', text: r.text, who: r.who || '' };
|
const m = { from: r.from, channel: imp.channel, at: r.at || '', text: r.text, who: r.who || '' };
|
||||||
if (r.file !== undefined) { m.files = [used.length]; used.push(imp.files[r.file].file); }
|
if (r.file !== undefined) { m.files = [used.length]; used.push(imp.files[r.file].file); }
|
||||||
|
if (r.blocks) m.blocks = r.blocks;
|
||||||
return m;
|
return m;
|
||||||
});
|
});
|
||||||
fd.append('messages', JSON.stringify(messages));
|
fd.append('messages', JSON.stringify(messages));
|
||||||
|
|
@ -6556,7 +6653,8 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
||||||
}
|
}
|
||||||
async function saveEdit() {
|
async function saveEdit() {
|
||||||
try {
|
try {
|
||||||
const j = await convoApi('PUT', `/api/convos/${c.id}/${editId}`, { ...edit, at: edit.at.replace('T', ' ') });
|
const { blocks: _b, ...ed } = edit; if (_b) delete ed.text;
|
||||||
|
const j = await convoApi('PUT', `/api/convos/${c.id}/${editId}`, { ...ed, at: ed.at.replace('T', ' ') });
|
||||||
setData(d => ({ ...d, items: d.items.map(x => (x.id === editId ? j.item : x)) }));
|
setData(d => ({ ...d, items: d.items.map(x => (x.id === editId ? j.item : x)) }));
|
||||||
setEditId(null);
|
setEditId(null);
|
||||||
} catch (e) { onNotify('保存失败:' + e.message); }
|
} catch (e) { onNotify('保存失败:' + e.message); }
|
||||||
|
|
@ -6593,7 +6691,7 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
||||||
|
|
||||||
const nq = q.trim().toLowerCase();
|
const nq = q.trim().toLowerCase();
|
||||||
const sorted = [...items].sort((a, b) => String(a.at).localeCompare(String(b.at)) || (a.createdAt || 0) - (b.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 shown = nq ? sorted.filter(m => [m.text, m.zh, m.title, m.tableText, ...(m.files || []).map(f => f.name)].some(v => String(v || '').toLowerCase().includes(nq))) : sorted;
|
||||||
const R = an && an.result;
|
const R = an && an.result;
|
||||||
const waDigits = String(c.phone || '').replace(/[^\d]/g, '');
|
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 nameOf = (m) => (m.from === 'me' ? CV_ME : (m.who && m.who !== CV_ME ? m.who : custName));
|
||||||
|
|
@ -6622,10 +6720,14 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
||||||
|
|
||||||
{imp && (
|
{imp && (
|
||||||
<div className={`cv-imp${drag ? ' drag' : ''}`}
|
<div className={`cv-imp${drag ? ' drag' : ''}`}
|
||||||
onPaste={e => { const fs = Array.from(e.clipboardData.files || []); if (fs.length) { e.preventDefault(); impAddFiles(fs); } }}
|
onPaste={e => {
|
||||||
|
const bl = cvClipBlocks(e.clipboardData);
|
||||||
|
if (bl) { e.preventDefault(); setImp(x => ({ ...x, rich: [...x.rich, bl].slice(0, 30) })); return; } // Excel / 邮件表格 → 一条消息
|
||||||
|
const fs = Array.from(e.clipboardData.files || []); if (fs.length) { e.preventDefault(); impAddFiles(fs); }
|
||||||
|
}}
|
||||||
onDragOver={e => { e.preventDefault(); }}
|
onDragOver={e => { e.preventDefault(); }}
|
||||||
onDrop={e => { e.preventDefault(); e.stopPropagation(); impAddFiles(e.dataTransfer.files); }}>
|
onDrop={e => { e.preventDefault(); e.stopPropagation(); impAddFiles(e.dataTransfer.files); }}>
|
||||||
<div className="cv-imp-h"><b>粘贴导入聊天记录</b><small>在 WhatsApp / 微信 / 邮件里选中聊天内容 → 复制 → 在下面 Ctrl+V 粘贴。图片、文件也可以直接 Ctrl+V 粘贴(或拖进来),每个是一条消息。下面会先预览,确认谁说的再导入。</small></div>
|
<div className="cv-imp-h"><b>粘贴导入聊天记录</b><small>在 WhatsApp / 微信 / 邮件里选中聊天内容 → 复制 → 在下面 Ctrl+V 粘贴。Excel 表格、图片、文件也可以直接 Ctrl+V 粘贴(或拖进来),每个是一条消息。下面会先预览,确认谁说的再导入。</small></div>
|
||||||
<div className="cv-add-row">
|
<div className="cv-add-row">
|
||||||
<div className="cv-chips">
|
<div className="cv-chips">
|
||||||
{CV_PICK.map(k => (
|
{CV_PICK.map(k => (
|
||||||
|
|
@ -6652,7 +6754,7 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
||||||
<div key={r.key} className={`cv-prev-r ${r.from === 'me' ? 'me' : 'cu'}`}>
|
<div key={r.key} className={`cv-prev-r ${r.from === 'me' ? 'me' : 'cu'}`}>
|
||||||
<button className="cv-prev-who" onClick={() => setImp(x => ({ ...x, over: { ...x.over, [r.key]: r.from === 'me' ? 'customer' : 'me' } }))} title="点击切换">{r.from === 'me' ? CV_ME : (r.who && !cvSameName(r.who, CV_ME) ? r.who : custName)}</button>
|
<button className="cv-prev-who" onClick={() => setImp(x => ({ ...x, over: { ...x.over, [r.key]: r.from === 'me' ? 'customer' : 'me' } }))} title="点击切换">{r.from === 'me' ? CV_ME : (r.who && !cvSameName(r.who, CV_ME) ? r.who : custName)}</button>
|
||||||
<span className="cv-prev-at">{r.at ? r.at.slice(5).replace('-', '/') : (imp.at ? imp.at.slice(5).replace('-', '/').replace('T', ' ') : '现在')}</span>
|
<span className="cv-prev-at">{r.at ? r.at.slice(5).replace('-', '/') : (imp.at ? imp.at.slice(5).replace('-', '/').replace('T', ' ') : '现在')}</span>
|
||||||
{r.f ? (r.f.url ? <img className="cv-prev-img" src={r.f.url} alt="" /> : <span className="cv-file"><Paperclip size={11} />{r.f.file.name}</span>) : <span className="cv-prev-t">{r.text}</span>}
|
{r.blocks ? <span className="cv-prev-t"><b>{cvBlocksSummary(r.blocks)}</b>{(() => { const tx = r.blocks.filter(b => b.t === 'text').map(b => b.v).join(' '); const t0 = r.blocks.find(b => b.t === 'table'); return ' ' + (tx || (t0 ? t0.rows[0].map(c => c.v).filter(Boolean).join(' | ') : '')).slice(0, 120); })()}</span> : r.f ? (r.f.url ? <img className="cv-prev-img" src={r.f.url} alt="" /> : <span className="cv-file"><Paperclip size={11} />{r.f.file.name}</span>) : <span className="cv-prev-t">{r.text}</span>}
|
||||||
<button className="cv-ico" title="不导入这条" onClick={() => setImp(x => ({ ...x, removed: { ...x.removed, [r.key]: true } }))}><X size={12} /></button>
|
<button className="cv-ico" title="不导入这条" onClick={() => setImp(x => ({ ...x, removed: { ...x.removed, [r.key]: true } }))}><X size={12} /></button>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|
@ -6770,7 +6872,7 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
||||||
<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>
|
<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 }))} />
|
<input type="datetime-local" className="input cv-sel" value={edit.at} onChange={e => setEdit(x => ({ ...x, at: e.target.value }))} />
|
||||||
</div>
|
</div>
|
||||||
<textarea className="textarea" rows={4} value={edit.text} onChange={e => setEdit(x => ({ ...x, text: e.target.value }))} />
|
{edit.blocks ? <div className="cv-rich-body"><CvBlocks blocks={edit.blocks} /></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 }))} />
|
<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' }}>
|
<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-ghost" onClick={() => setEditId(null)}>取消</button>
|
||||||
|
|
@ -6779,7 +6881,7 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<div className="cv-bub">
|
<div className={`cv-bub${m.blocks && m.blocks.some(b => b.t === 'table') ? ' wide' : ''}`}>
|
||||||
<div className="cv-bub-h">
|
<div className="cv-bub-h">
|
||||||
<b className="cv-who">{nameOf(m)}</b>
|
<b className="cv-who">{nameOf(m)}</b>
|
||||||
<span className="cv-chtag" style={{ color: ch.color, borderColor: ch.color + '55' }}>{ch.label}</span>
|
<span className="cv-chtag" style={{ color: ch.color, borderColor: ch.color + '55' }}>{ch.label}</span>
|
||||||
|
|
@ -6798,14 +6900,14 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
{m.text && <div className="cv-txt" dir="auto">{m.text}</div>}
|
{m.blocks ? <CvBlocks blocks={m.blocks} /> : m.text && <div className="cv-txt" dir="auto">{m.text}</div>}
|
||||||
{showZh && m.text && (m.zh ? <div className="cv-zh">{m.zh}</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)}
|
: 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 className="cv-time">{String(m.at || '').slice(11, 16)}{m.updatedAt ? ' · 已编辑' : ''}</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="cv-tools">
|
<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={() => { setEditId(m.id); setEdit({ from: m.from, channel: m.channel, at: String(m.at || '').replace(' ', 'T'), text: m.text || '', zh: m.zh || '', blocks: m.blocks || null }); }}><Edit2 size={12} /></button>
|
||||||
<button className="cv-ico" title="复制" onClick={() => copy(m.text || '')}><Copy size={12} /></button>
|
<button className="cv-ico" title="复制" onClick={() => copy([m.text, m.tableText].filter(Boolean).join('\n\n'))}><Copy size={12} /></button>
|
||||||
<button className="cv-ico" title="删除" onClick={() => del(m)}><Trash2 size={12} /></button>
|
<button className="cv-ico" title="删除" onClick={() => del(m)}><Trash2 size={12} /></button>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|
@ -6834,6 +6936,12 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
||||||
{at ? <button onClick={() => setAt('')} title="改回现在"><X size={11} /></button> : <span>现在</span>}
|
{at ? <button onClick={() => setAt('')} title="改回现在"><X size={11} /></button> : <span>现在</span>}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
{rich.length > 0 && (
|
||||||
|
<div className="cv-rich-pend">
|
||||||
|
<div className="cv-rich-h"><span>粘贴的表格 / 内容(发送时附在文字后面)</span><button className="cv-ico" title="去掉" onClick={() => setRich([])}><X size={12} /></button></div>
|
||||||
|
<div className="cv-rich-body"><CvBlocks blocks={rich} /></div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{files.length > 0 && (
|
{files.length > 0 && (
|
||||||
<div className="cv-files">
|
<div className="cv-files">
|
||||||
{files.map((f, i) => (
|
{files.map((f, i) => (
|
||||||
|
|
@ -6846,7 +6954,11 @@ function ConversationPanel({ customer: c, onNotify, onPatchCustomer }) {
|
||||||
<input ref={fileRef} type="file" multiple hidden onChange={e => { addFiles(e.target.files); e.target.value = ''; }} />
|
<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}
|
<textarea ref={taRef} rows={Math.min(8, Math.max(1, text.split('\n').length))} value={text}
|
||||||
onChange={e => setText(e.target.value)}
|
onChange={e => setText(e.target.value)}
|
||||||
onPaste={e => { const fs = Array.from(e.clipboardData.files || []); if (fs.length) { e.preventDefault(); addFiles(fs); } }}
|
onPaste={e => {
|
||||||
|
const bl = cvClipBlocks(e.clipboardData);
|
||||||
|
if (bl) { e.preventDefault(); setRich(r => [...r, ...bl].slice(0, 20)); return; } // Excel / 邮件里的表格
|
||||||
|
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(); } }}
|
onKeyDown={e => { if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) { e.preventDefault(); send(); } }}
|
||||||
placeholder={from === 'me' ? `输入 ${CV_ME} 的回复…(Ctrl+Enter 发送)` : `输入 ${custName} 说的话…(Ctrl+Enter 发送)`} />
|
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>
|
<button className={`cv-send ${from === 'me' ? 'me' : 'cu'}`} disabled={sending} onClick={send} title="发送"><Send size={16} /></button>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue