Update App.jsx via upload script - 2026-11-14 12:53:30

This commit is contained in:
mike 2026-11-14 12:53:49 +08:00
parent 55ccbf85bd
commit 608085bc3e
1 changed files with 113 additions and 2 deletions

115
App.jsx
View File

@ -5,7 +5,7 @@ import {
Building2, Globe, Phone, Save, RefreshCw, LayoutDashboard, Users, Building2, Globe, Phone, Save, RefreshCw, LayoutDashboard, Users,
Package, Layers, Zap, Tag, Inbox, Paperclip, Package, Layers, Zap, Tag, Inbox, Paperclip,
Menu, LogOut, GripVertical, BookOpen, FileText, FolderTree, Lock, Sparkles, Printer, Image as ImageIcon, 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 ShieldCheck, Settings2, Boxes, Download, Wifi, Radio, QrCode, Folder, FolderPlus, Factory, UploadCloud, ClipboardList, MessageCircle, CalendarDays, MapPin, Wrench, Hash
} from 'lucide-react'; } from 'lucide-react';
import { MicUploadPage } from './mic-upload/MicUploadPage'; import { MicUploadPage } from './mic-upload/MicUploadPage';
import { ImageToolPage } from './mic-upload/ImageToolPage'; import { ImageToolPage } from './mic-upload/ImageToolPage';
@ -2186,6 +2186,18 @@ const Styles = () => (
.web-badge { display: inline-flex; align-items: center; gap: 3px; margin-left: 8px; font-size: 11px; font-weight: 500; color: #1d7a3e; background: #dcf1e2; padding: 2px 8px; border-radius: 99px; } .web-badge { display: inline-flex; align-items: center; gap: 3px; margin-left: 8px; font-size: 11px; font-weight: 500; color: #1d7a3e; background: #dcf1e2; padding: 2px 8px; border-radius: 99px; }
.visit-card { display: grid; grid-template-columns: 120px 1fr 150px; gap: 16px; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; background: var(--panel); } .visit-card { display: grid; grid-template-columns: 120px 1fr 150px; gap: 16px; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; background: var(--panel); }
.visit-card.no-lic { grid-template-columns: 120px 1fr; } .visit-card.no-lic { grid-template-columns: 120px 1fr; }
.svc-card { grid-template-columns: 150px 1fr 150px; }
.svc-card.no-lic { grid-template-columns: 150px 1fr; }
.svc-ref { font: 700 13px 'IBM Plex Mono', monospace; letter-spacing: .02em; }
.visit-st.svc-st-new { background: #fee2e2; color: #991b1b; }
.visit-st.svc-st-processing { background: #dbeafe; color: #1e40af; }
.visit-st.svc-st-waiting { background: #fef3c7; color: #92400e; }
.visit-st.svc-st-resolved { background: #dcfce7; color: #166534; }
.svc-run { font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 99px; margin-top: 4px; }
.svc-run.run-no { background: #fee2e2; color: #991b1b; } .svc-run.run-partial { background: #fef3c7; color: #92400e; } .svc-run.run-yes { background: #eef2f7; color: #475467; }
.svc-code { font: 600 12px 'IBM Plex Mono', monospace; background: #fef1ef; color: #b42318; padding: 1px 7px; border-radius: 5px; }
.svc-sn { font: 12px 'IBM Plex Mono', monospace; background: var(--bg); border: 1px solid var(--line); padding: 1px 6px; border-radius: 5px; }
.visit-card.st-resolved, .visit-card.st-closed { opacity: .7; }
.visit-card.focus { box-shadow: 0 0 0 2px #2563eb; } .visit-card.focus { box-shadow: 0 0 0 2px #2563eb; }
.visit-card.st-done, .visit-card.st-cancelled { opacity: .7; } .visit-card.st-done, .visit-card.st-cancelled { opacity: .7; }
.visit-when { text-align: center; border-right: 1px dashed var(--line); padding-right: 14px; display: flex; flex-direction: column; align-items: center; gap: 2px; } .visit-when { text-align: center; border-right: 1px dashed var(--line); padding-right: 14px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
@ -2479,6 +2491,7 @@ const NAV_GROUPS = [
{ id: 'website', label: '网站管理', icon: Globe, children: [ { id: 'website', label: '网站管理', icon: Globe, children: [
{ id: 'webnews', label: '新闻 / 动态', icon: FileText }, { id: 'webnews', label: '新闻 / 动态', icon: FileText },
{ id: 'webvisits', label: '预约拜访', icon: CalendarDays }, { id: 'webvisits', label: '预约拜访', icon: CalendarDays },
{ id: 'webservice', label: '售后服务', icon: Wrench },
] }, ] },
{ id: 'backpanel', label: '后板图模板', icon: Settings2 }, { id: 'backpanel', label: '后板图模板', icon: Settings2 },
{ id: 'mic-upload', label: 'MIC产品上传', icon: UploadCloud }, { id: 'mic-upload', label: 'MIC产品上传', icon: UploadCloud },
@ -2605,7 +2618,8 @@ function MainApp({ username, onLogout }) {
const chatLinkSid = useMemo(() => { try { return new URLSearchParams(window.location.search).get('chat') || null; } catch (e) { return null; } }, []); const chatLinkSid = useMemo(() => { try { return new URLSearchParams(window.location.search).get('chat') || null; } catch (e) { return null; } }, []);
// 推送消息里的链接 /?visit=预约id → 打开"网站管理 → 预约拜访"并定位到这条 // 推送消息里的链接 /?visit=预约id → 打开"网站管理 → 预约拜访"并定位到这条
const visitLinkId = useMemo(() => { try { return new URLSearchParams(window.location.search).get('visit') || null; } catch (e) { return null; } }, []); const visitLinkId = useMemo(() => { try { return new URLSearchParams(window.location.search).get('visit') || null; } catch (e) { return null; } }, []);
const [view, setView] = useState(chatLinkSid ? 'chat' : visitLinkId ? 'webvisits' : 'monitor'); const serviceLinkId = useMemo(() => { try { return new URLSearchParams(window.location.search).get('service') || null; } catch (e) { return null; } }, []);
const [view, setView] = useState(chatLinkSid ? 'chat' : visitLinkId ? 'webvisits' : serviceLinkId ? 'webservice' : 'monitor');
const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
const [selectedId, setSelectedId] = useState(null); const [selectedId, setSelectedId] = useState(null);
@ -4362,6 +4376,10 @@ function MainApp({ username, onLogout }) {
}} /> }} />
)} )}
{view === 'webservice' && (
<ServiceManager onNotify={notify} focusId={serviceLinkId} />
)}
{view === 'webvisits' && ( {view === 'webvisits' && (
<VisitManager onNotify={notify} focusId={visitLinkId} <VisitManager onNotify={notify} focusId={visitLinkId}
onSaveCustomer={(v) => { onSaveCustomer={(v) => {
@ -10644,6 +10662,99 @@ function VisitManager({ onNotify, onSaveCustomer, focusId }) {
); );
} }
/* ------------------------------ 售后服务申请(网站 /service/ 页面提交) ------------------------------ */
const SVC_STATUS_ZH = { new: '新申请', processing: '处理中', waiting: '等客户回复', resolved: '已解决', closed: '已关闭' };
const SVC_ISSUE_ZH = { no_power: '无法开机 / 无输出', alarm: '报警 / 故障代码', battery: '电池问题', no_backup: '断电不切换 / 后备时间短', noise: '异响 / 发热 / 异味', install: '安装 / 调试 / 设置', parts: '需要备件', warranty: '保修咨询', other: '其他' };
const SVC_RUNNING_ZH = { yes: '还在运行', partial: '部分功能可用', no: '已停机' };
const SVC_CHANNEL_ZH = { direct: '直接从 SKE 购买', distributor: '经销商', other: '其他渠道' };
function ServiceManager({ onNotify, focusId }) {
const [list, setList] = useState(null);
const [filter, setFilter] = useState('open');
const [q, setQ] = useState('');
const [memo, setMemo] = useState({});
const load = async () => { try { const j = await chApi('GET', '/api/chat/admin/services'); setList(j.list || []); } catch (e) { setList([]); onNotify('读取售后申请失败:' + e.message); } };
useEffect(() => { load(); const t = setInterval(load, 60000); return () => clearInterval(t); }, []);
useEffect(() => { if (focusId && list) { const el = document.getElementById('svc-' + focusId); if (el) el.scrollIntoView({ block: 'center' }); } }, [focusId, list && list.length]);
const patch = async (v, body, msg) => {
try { const j = await chApi('POST', `/api/chat/admin/services/${v.id}`, body); setList(l => l.map(x => (x.id === v.id ? j.item : x))); if (msg) onNotify(msg); }
catch (e) { onNotify('保存失败:' + e.message); }
};
const del = async (v) => {
if (!window.confirm(`删除工单 ${v.ref}?附件也会一起删除。`)) return;
try { await chApi('POST', `/api/chat/admin/services/${v.id}/delete`); setList(l => l.filter(x => x.id !== v.id)); onNotify('已删除'); }
catch (e) { onNotify('删除失败:' + e.message); }
};
if (!list) return <div className="panel" style={{ padding: 24 }}>加载中…</div>;
const isOpen = (v) => ['new', 'processing', 'waiting'].includes(v.status);
const nq = q.trim().toLowerCase();
const hit = (v) => !nq || [v.ref, v.model, v.category, v.company, v.name, v.email, v.phone, v.country, v.city, v.errorCode, ...(v.sns || [])].some(x => String(x || '').toLowerCase().includes(nq));
const shown = list.filter(v => (filter === 'open' ? isOpen(v) : filter === 'all' ? true : v.status === filter) && hit(v)).sort((a, b) => b.at - a.at);
const count = (k) => list.filter(v => (k === 'open' ? isOpen(v) : k === 'all' || v.status === k)).length;
const waOf = (ph) => String(ph || '').replace(/[^\d]/g, '');
return (
<div className="panel" style={{ padding: 0 }}>
<div className="panel-header" style={{ display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap' }}>
<div style={{ fontWeight: 600 }}>售后服务</div>
<span style={{ fontSize: 12.5, color: 'var(--ink-soft)' }}>客户在网站 Support → After-sale service 提交</span>
<div style={{ marginLeft: 'auto', display: 'flex', gap: 6, flexWrap: 'wrap', alignItems: 'center' }}>
<input className="input" style={{ width: 220 }} value={q} onChange={e => setQ(e.target.value)} placeholder="搜单号 / 型号 / SN / 公司 / 电话" />
{[['open', '未完成'], ['new', '新申请'], ['processing', '处理中'], ['waiting', '等客户回复'], ['resolved', '已解决'], ['closed', '已关闭'], ['all', '全部']].map(([k, l]) => (
<button key={k} className={`btn btn-sm${filter === k ? ' btn-primary' : ''}`} onClick={() => setFilter(k)}>{l} {count(k)}</button>
))}
<button className="btn btn-sm btn-ghost" onClick={load} title="刷新"><RefreshCw size={13} /></button>
</div>
</div>
<div style={{ padding: 16, display: 'grid', gap: 12 }}>
{shown.length === 0 && <div style={{ color: 'var(--ink-soft)', padding: 20, textAlign: 'center' }}>没有{nq ? '匹配的' : filter === 'all' ? '' : '这类'}售后申请</div>}
{shown.map(v => (
<div key={v.id} id={'svc-' + v.id} className={`visit-card svc-card st-${v.status}${focusId === v.id ? ' focus' : ''}${(v.files || []).length ? '' : ' no-lic'}`}>
<div className="visit-when">
<div className="svc-ref">{v.ref}</div>
<div className="visit-wk">{new Date(v.at).toLocaleString('zh-CN', { hour12: false, month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' })}</div>
<span className={`visit-st svc-st-${v.status}`}>{SVC_STATUS_ZH[v.status] || v.status}</span>
{v.running && <span className={`svc-run run-${v.running}`}>{SVC_RUNNING_ZH[v.running]}</span>}
</div>
<div className="visit-body">
<div className="visit-co">{v.model}{v.qty > 1 ? ` × ${v.qty}` : ''}{v.category && <span className="visit-cc">{v.category}</span>}</div>
<div className="visit-line"><Wrench size={13} /><b>{(v.issues || []).map(k => SVC_ISSUE_ZH[k] || k).join('、')}</b>{v.errorCode && <span className="svc-code">代码 {v.errorCode}</span>}</div>
{v.desc && <div className="visit-notes">{v.desc}</div>}
{(v.sns || []).length > 0 && <div className="visit-line"><Hash size={13} />SN:{v.sns.map(x => <code key={x} className="svc-sn">{x}</code>)}</div>}
<div className="visit-line"><Package size={13} />{[v.purchase && `购买于 ${v.purchase}`, v.channel && SVC_CHANNEL_ZH[v.channel], v.seller, v.order && `订单/发票 ${v.order}`].filter(Boolean).join(' · ') || '购买信息未填'}</div>
<div className="visit-line"><MapPin size={13} />{[v.site, v.city, v.country].filter(Boolean).join(', ')}{v.ipCountry && <span className="visit-cc">(IP {chFlag(v.ipCountry)} {v.ipCountry})</span>}</div>
<div className="visit-line"><Users size={13} />{v.name}{v.company ? ` · ${v.company}` : ''}
<Phone size={13} style={{ marginLeft: 14 }} />{v.phone}{waOf(v.phone).length >= 7 && <a href={`https://wa.me/${waOf(v.phone)}`} target="_blank" rel="noreferrer" style={{ marginLeft: 8 }}>WhatsApp</a>}
<Mail size={13} style={{ marginLeft: 14 }} /><a href={`mailto:${v.email}?subject=${encodeURIComponent(`[${v.ref}] ${v.model}`)}`}>{v.email}</a>
</div>
<div className="visit-meta">提交于 {new Date(v.at).toLocaleString('zh-CN', { hour12: false })}{v.lang ? ` · 网站语言 ${v.lang}` : ''}{v.updated ? ` · 更新于 ${new Date(v.updated).toLocaleString('zh-CN', { hour12: false })}` : ''}</div>
<div className="visit-actions">
<select className="input" style={{ width: 'auto' }} value={v.status} onChange={e => patch(v, { status: e.target.value }, `已改为"${SVC_STATUS_ZH[e.target.value]}"`)}>
{Object.entries(SVC_STATUS_ZH).map(([k, l]) => <option key={k} value={k}>{l}</option>)}
</select>
<button className="btn btn-sm btn-ghost btn-danger" onClick={() => del(v)}><Trash2 size={13} />删除</button>
</div>
<textarea className="textarea" rows={2} style={{ marginTop: 8, fontSize: 13 }} placeholder="处理记录(内部,客户看不到):判断、寄件、更换的备件、快递单号…"
value={memo[v.id] !== undefined ? memo[v.id] : (v.memo || '')}
onChange={e => setMemo(m => ({ ...m, [v.id]: e.target.value }))}
onBlur={() => { if (memo[v.id] !== undefined && memo[v.id] !== (v.memo || '')) patch(v, { memo: memo[v.id] }, '处理记录已保存'); }} />
</div>
{(v.files || []).length > 0 && (
<div className="visit-lic">
<div className="visit-lic-h">照片 / 附件</div>
{v.files.map((f, i) => {
const url = `/api/chat/admin/services/${v.id}/file/${i}`;
return /^image\//.test(f.mime) && f.mime !== 'image/heic'
? <a key={i} href={url} target="_blank" rel="noreferrer"><img src={url} alt={f.name} /></a>
: <a key={i} className="visit-pdf" style={{ height: 70 }} href={url} target="_blank" rel="noreferrer"><FileText size={22} /><small>{f.mime === 'application/pdf' ? 'PDF' : 'HEIC'} · 点击查看</small></a>;
})}
</div>
)}
</div>
))}
</div>
</div>
);
}
const chApi = async (method, url, body) => { const chApi = async (method, url, body) => {
const r = await fetch(url, { method, headers: body ? { 'Content-Type': 'application/json' } : undefined, body: body ? JSON.stringify(body) : undefined, credentials: 'same-origin' }); const r = await fetch(url, { method, headers: body ? { 'Content-Type': 'application/json' } : undefined, body: body ? JSON.stringify(body) : undefined, credentials: 'same-origin' });
const j = await r.json().catch(() => ({})); const j = await r.json().catch(() => ({}));