Files
tangzhuan-yu/static/assets/MessageManagement-NPF-d8RM.js
T

13 lines
29 KiB
JavaScript
Vendored
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{c as We,r as n,aW as mt,o as xt,n as u,h as ut,ba as ht,bb as ft,j as t,e as $e,L as U,bc as pt,X as gt,bd as bt,be as jt,bf as yt,aT as vt,bg as wt,bh as Nt,bi as kt,bj as St,v as Te,bk as Ct,bl as Mt}from"./index-IP-mmLlr.js";import{I as Re,c as _t,S as Ee,E as It}from"./ui-Fi8l9rTp.js";import{S as Z}from"./settings-2-DVRotgka.js";import{S as $t}from"./search-TGrYyOkD.js";import{P as Tt}from"./package-C7ydMeAZ.js";import{I as Rt}from"./image-hfWSlf8S.js";import{Z as Et}from"./zap-DljT2UQs.js";import{S as Lt}from"./send-CwI5w629.js";import{P as Le}from"./plus-BbnHS2Zx.js";import{T as Ue}from"./trash-2-BNPsgs2t.js";/**
* @license lucide-react v0.562.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Ut=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],Fe=We("arrow-left",Ut);/**
* @license lucide-react v0.562.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Ft=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 14s1.5 2 4 2 4-2 4-2",key:"1y1vjs"}],["line",{x1:"9",x2:"9.01",y1:"9",y2:"9",key:"yxxnd0"}],["line",{x1:"15",x2:"15.01",y1:"9",y2:"9",key:"1p4y9e"}]],Pt=We("smile",Ft),At={微笑:"🙂",呲牙:"😁",咧嘴:"😁",大笑:"😄",笑哭:"😂",憨笑:"😊",微尬:"😅",尴尬:"😅",流汗:"😓",冷汗:"😰",流泪:"😭",大哭:"😭",快哭了:"😭",委屈:"🥺",可怜:"🥺",难过:"😢",失落:"😞",衰:"😞",捂脸:"🤦",掩面:"🤦",偷笑:"🤭",坏笑:"😏",阴险:"😈",淘气:"😜",调皮:"😜",吐舌:"😜",色色:"😍",色:"😍",爱慕:"😍",发呆:"😳",害羞:"😊",脸红:"😊",闭嘴:"🤐",睡觉:"😴",睡:"😴",困:"😪",打哈欠:"🥱",哈欠:"🥱",惊讶:"😲",吃惊:"😲",惊恐:"😱",吓:"😱",发怒:"😡",生气:"😡",怒:"😡",抓狂:"😫",疯狂:"😫",疑问:"❓",疑惑:"🤔",想想:"🤔",晕:"😵",晕倒:"😵",骷髅:"💀",敲打:"🔨",再见:"👋",拜拜:"👋",擦汗:"😅",抠鼻:"👃",鄙视:"🙄",白眼:"🙄",傲慢:"😏",得意:"😎",酷:"😎",饥饿:"🤤",馋嘴:"🤤",吐:"🤮",呕吐:"🤮",奋斗:"💪",加油:"💪",鼓掌:"👏",喝彩:"👏",调停:"🙏",抱拳:"🙏",作揖:"🙏",祈祷:"🙏",感谢:"🙏",亲亲:"😘",亲吻:"😘",飞吻:"😘",拥抱:"🤗",抱抱:"🤗",强:"👍",赞:"👍",点赞:"👍",弱:"👎",差评:"👎",握手:"🤝",胜利:"✌️",OK:"👌",剪刀:"✌️",手枪:"🔫",计算:"🧮",卡住:"😵",爱心:"❤️",红心:"❤️",心碎:"💔",玫瑰:"🌹",花朵:"🌸",凋谢:"🥀",樱花:"🌸",太阳:"☀️",月亮:"🌙",星星:"⭐",闪电:"⚡",彩虹:"🌈",咖啡:"☕",蛋糕:"🎂",生日快乐:"🎂",啤酒:"🍺",干杯:"🍻",西瓜:"🍉",苹果:"🍎",礼物:"🎁",红包:"🧧",恭喜发财:"🧧",灯笼:"🏮",爆竹:"🧨",庆祝:"🎉",撒花:"🎉",烟花:"🎆",足球:"⚽",篮球:"🏀",排球:"🏐",乒乓:"🏓",网球:"🎾",炸弹:"💣",刀:"🔪",猪头:"🐷",狗:"🐶",猫:"🐱",熊:"🐻",兔:"🐰",鸡:"🐔",公鸡:"🐔",蚂蚁:"🐜",蜗牛:"🐌",瓢虫:"🐞",蝴蝶:"🦋",蛇:"🐍",恐龙:"🦖",鲨鱼:"🦈"};function Pe(r){return r.replace(/\[([^\[\]]{1,8})\]/g,(o,d)=>At[d]??o)}const Dt=1e4,Ot=1e4,Ke="xianyu-message-read-watermarks-v2",zt=500,Ae=9,Wt=10*1024*1024,De=(r,o)=>`${r}\0${o}`,Kt=()=>{if(typeof window>"u")return{};try{const r=JSON.parse(window.localStorage.getItem(Ke)||"{}");return!r||typeof r!="object"||Array.isArray(r)?{}:Object.fromEntries(Object.entries(r).filter(([,o])=>{if(!o||typeof o!="object"||Array.isArray(o))return!1;const d=o;return Number.isFinite(d.lastMessageTime)&&typeof d.lastMessageSummary=="string"&&Number.isFinite(d.unreadCount)}))}catch{return{}}},Bt=r=>{if(!(typeof window>"u"))try{const o=Object.entries(r).sort(([,d],[,g])=>g.lastMessageTime-d.lastMessageTime).slice(0,zt);window.localStorage.setItem(Ke,JSON.stringify(Object.fromEntries(o)))}catch{}},qt=(r,o)=>{if(!r)return!1;const d=Number(o.lastMessageTime)||0,g=String(o.lastMessageSummary||""),k=Number(o.unreadCount)||0;return d<r.lastMessageTime||d===r.lastMessageTime&&g===r.lastMessageSummary&&k<=r.unreadCount},F=r=>r?r.startsWith("//")?`https:${r}`:r:"",Oe=r=>{if(!r)return"";const o=r<1e12?r*1e3:r,d=new Date(o);if(Number.isNaN(d.getTime()))return"";const g=new Date;return d.toDateString()===g.toDateString()?d.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}):d.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit"})},Gt=r=>{if(!r)return"-";const o=new Date(r.includes("T")?r:`${r.replace(" ","T")}Z`);return Number.isNaN(o.getTime())?r:o.toLocaleString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})},Y=r=>(r==null?void 0:r.displayName)||(r==null?void 0:r.accountId)||"未选择账号",ze=["#8c7900","#0f704b","#2a5f92","#945800","#6b5a8a","#b45309","#3f7a5c","#7c4d5e"],Ht=r=>{let o=0;for(let d=0;d<r.length;d+=1)o=o*31+r.charCodeAt(d)|0;return ze[Math.abs(o)%ze.length]},Qt={skip_reply:"跳过自动回复",skip_notify:"跳过外部通知"},ls=({isActive:r=!0})=>{const[o,d]=n.useState("messages"),[g,k]=n.useState("list"),[P,Be]=n.useState([]),[ee,qe]=n.useState([]),[te,Ge]=n.useState([]),[x,se]=n.useState(""),[S,A]=n.useState([]),[He,Qe]=n.useState(new Set),[j,D]=n.useState(""),[C,O]=n.useState([]),[z,W]=n.useState(""),[Ve,ae]=n.useState(!1),[Xe]=n.useState(()=>`conversation-filter-${Date.now()}-${Math.random().toString(36).slice(2)}`),[Je,re]=n.useState(!0),[K,ne]=n.useState(!1),[ie,le]=n.useState(!1),[B,q]=n.useState(""),[oe,ce]=n.useState([]),[de,G]=n.useState(!1),[H,me]=n.useState(!1),[b,Q]=n.useState([]),xe=n.useRef(null),V=n.useRef(null),ue=n.useRef(null),I=n.useRef(!1),$=n.useRef(""),T=n.useRef(Kt()),he=n.useRef(b);he.current=b,n.useEffect(()=>()=>{he.current.forEach(e=>URL.revokeObjectURL(e.url))},[]);const[y,Ze]=n.useState([]),[fe,pe]=n.useState(!0),[ge,Ye]=n.useState(""),[be,et]=n.useState(""),[X,je]=n.useState(""),[ye,tt]=n.useState("skip_reply"),[ve,we]=n.useState(""),[w,R]=n.useState([]),[Ne,ke]=n.useState(!1),l=P.find(e=>e.accountId===x),m=S.find(e=>e.cid===j),st=n.useMemo(()=>new Map(te.map(e=>[`${e.cookie_id}:${e.item_id}`,e])),[te]),h=m!=null&&m.itemId?st.get(`${x}:${m.itemId}`):void 0,Se=n.useMemo(()=>{const e=z.trim().toLocaleLowerCase();return e?S.filter(s=>[s.otherUserName,s.otherUserId,s.itemTitle,s.itemId,s.lastMessageSummary].some(a=>String(a||"").toLocaleLowerCase().includes(e))):S},[S,z]),at=y.length>0&&y.every(e=>w.includes(e.id)),Ce=e=>{if(!x||!e.cid)return;const s=De(x,e.cid),a={lastMessageTime:Number(e.lastMessageTime)||0,lastMessageSummary:String(e.lastMessageSummary||""),unreadCount:Number(e.unreadCount)||0},i=T.current[s];i&&(i.lastMessageTime>a.lastMessageTime||i.lastMessageTime===a.lastMessageTime&&i.lastMessageSummary===a.lastMessageSummary&&i.unreadCount>=a.unreadCount)||(T.current[s]=a,Bt(T.current))},rt=e=>{Ce(e),$.current=e.cid,A(s=>s.map(a=>a.cid===e.cid?{...a,unreadCount:0}:a)),D(e.cid),k("chat")},Me=async()=>{re(!0);try{const e=await jt();Be(e),se(s=>{var a,i;return s&&e.some(c=>c.accountId===s)?s:((a=e.find(c=>c.connected))==null?void 0:a.accountId)||((i=e[0])==null?void 0:i.accountId)||""})}catch(e){u(`加载消息账号失败:${e.message}`,"error")}finally{re(!1)}},M=async(e=!1)=>{var s;if(!x){A([]);return}e||ne(!0);try{const i=(await ht(x)).conversations||[],c=$.current,f=i.some(p=>p.cid===c)?c:((s=i[0])==null?void 0:s.cid)||"",v=i.map(p=>{const _=r&&p.cid===f&&(g==="chat"||window.matchMedia("(min-width: 1024px)").matches),L=T.current[De(x,p.cid)];return _&&Ce(p),_||qt(L,p)?{...p,unreadCount:0}:p});A(v),D(p=>{var L;const _=p&&i.some(dt=>dt.cid===p)?p:((L=i[0])==null?void 0:L.cid)||"";return $.current=_,_})}catch(a){e||u(`加载会话失败:${a.message}`,"error")}finally{e||ne(!1)}},E=async(e=!1)=>{if(!x||!j){O([]);return}e||le(!0);try{const s=await ft(x,j);O(s.messages||[])}catch(s){e||u(`加载聊天记录失败:${s.message}`,"error")}finally{e||le(!1)}},N=async()=>{pe(!0);try{const e=await yt({cookie_id:ge||void 0,filter_type:be||void 0});Ze(e),R(s=>s.filter(a=>e.some(i=>i.id===a)))}catch(e){u(`加载过滤规则失败:${e.message}`,"error")}finally{pe(!1)}};n.useEffect(()=>{(async()=>{const s=xt().then(i=>{var c;qe(i),je(((c=i[0])==null?void 0:c.id)||"")}).catch(i=>u(`加载账号资料失败:${i.message}`,"error")),a=ut().then(Ge).catch(i=>u(`加载商品资料失败:${i.message}`,"error"));await Promise.all([Me(),s,a,N()])})()},[]),n.useEffect(()=>{$.current="",D(""),O([]),k("list"),r&&M()},[r,x]),n.useEffect(()=>{r&&E()},[r,x,j]),n.useEffect(()=>{if(!r||o!=="messages"||!x)return;M(!0);const e=window.setInterval(()=>void M(!0),Dt);return()=>window.clearInterval(e)},[r,o,x,g]),n.useEffect(()=>{if(!r||o!=="messages"||!x||!j)return;E(!0);const e=window.setInterval(()=>void E(!0),Ot);return()=>window.clearInterval(e)},[r,o,x,j]),n.useEffect(()=>{var e;(e=xe.current)==null||e.scrollIntoView({behavior:"smooth"})},[C]),n.useEffect(()=>{const e=()=>{I.current||!V.current||(V.current.value="",W(""))};e();const s=[100,500,1500].map(a=>window.setTimeout(e,a));return()=>s.forEach(a=>window.clearTimeout(a))},[]),n.useEffect(()=>{mt().then(ce).catch(()=>ce([]))},[]);const nt=e=>{q(s=>s?`${s}${e.content}`:e.content),G(!1),wt(e.id).catch(()=>{})},_e=e=>{const s=[];for(const a of e){const i=a.name||"未命名文件";if(!a.type.startsWith("image/")){u(`${i} 不是图片,已跳过`,"warning");continue}if(a.size>Wt){u(`${i} 超过 10MB,已跳过`,"warning");continue}if(b.length+s.length>=Ae){u(`一次最多发送 ${Ae} 张图片`,"warning");break}s.push({file:a,url:URL.createObjectURL(a)})}s.length>0&&Q(a=>[...a,...s])},it=e=>{Q(s=>{const a=s[e];return a&&URL.revokeObjectURL(a.url),s.filter((i,c)=>c!==e)})},Ie=async()=>{const e=B.trim();if(!e&&b.length===0||!m||!x||H)return;me(!0);const s=b;let a=0,i="";try{for(e&&await Nt(x,{cid:m.cid,to_user_id:m.otherUserId,text:e});a<s.length;){try{await kt(x,{cid:m.cid,to_user_id:m.otherUserId,file:s[a].file})}catch(f){i=`${s[a].file.name||`第 ${a+1} 张`}:${f.message}`;break}a+=1}s.slice(0,a).forEach(f=>URL.revokeObjectURL(f.url)),Q(s.slice(a)),q(""),await Promise.all([E(!0),M(!0)]),i?u(`文字已发送、图片已发 ${a} 张,失败:${i}`,"error"):u("消息已发送","success")}catch(c){u(`发送失败:${c.message}`,"error")}finally{me(!1)}},lt=async()=>{const e=ve.split(/\r?\n/).map(s=>s.trim()).filter(Boolean);if(!X||e.length===0){u("请选择账号并填写至少一个关键词","warning");return}ke(!0);try{const s=await St({cookie_id:X,filter_type:ye,keywords:e});we(""),await N(),u(`新增 ${s.created} 条,跳过重复 ${s.skipped} 条`,"success")}catch(s){u(`新增规则失败:${s.message}`,"error")}finally{ke(!1)}},ot=async e=>{if(await Te(`删除过滤关键词“${e.keyword}”?`))try{await Mt(e.id),await N(),u("规则已删除","success")}catch(s){u(`删除失败:${s.message}`,"error")}},ct=async()=>{if(!(w.length===0||!await Te(`删除选中的 ${w.length} 条规则?`)))try{await Ct(w),R([]),await N(),u("所选规则已删除","success")}catch(e){u(`批量删除失败:${e.message}`,"error")}},J=(e,s,a,i)=>{const c=F(e),f=t.jsx("div",{className:`${a} flex items-center justify-center text-sm font-bold text-white`,style:{backgroundColor:Ht(String(i||s||"").trim())},children:s.trim().slice(0,1)||t.jsx(vt,{className:"h-4 w-4"})});return c&&!He.has(c)?t.jsx("img",{src:c,alt:"",className:`${a} object-cover`,loading:"lazy",referrerPolicy:"no-referrer",onError:()=>Qe(v=>new Set(v).add(c))}):f};return o==="messages"?t.jsxs("div",{className:"grid h-full min-h-0 overflow-hidden bg-[var(--surface)] lg:grid-cols-[356px_minmax(0,1fr)]",children:[t.jsxs("aside",{className:`${g==="chat"?"hidden lg:flex":"flex"} min-h-0 flex-col border-b border-[var(--border)] lg:border-b-0 lg:border-r`,children:[t.jsxs("div",{className:"flex h-[68px] shrink-0 items-center gap-3 border-b border-[var(--border)] px-4",children:[t.jsxs("select",{value:x,onChange:e=>se(e.target.value),"aria-label":"消息账号",className:"h-10 min-w-0 flex-1 rounded-md border border-[var(--border-strong)] bg-[var(--surface)] px-3 text-sm font-bold text-[var(--text)] outline-none focus:border-[var(--brand)]",children:[P.length===0&&t.jsx("option",{value:"",children:"暂无账号"}),P.map(e=>t.jsxs("option",{value:e.accountId,children:[e.connected?"在线":"离线"," · ",Y(e)]},e.accountId))]}),t.jsx("button",{type:"button",onClick:()=>void Promise.all([Me(),M()]),title:"刷新账号和会话",className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-full hover:bg-[var(--surface-hover)]",children:t.jsx($e,{className:`h-4 w-4 ${Je||K?"animate-spin":""}`})}),t.jsx("button",{type:"button",onClick:()=>d("filters"),title:"消息过滤规则",className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-full hover:bg-[var(--surface-hover)]",children:t.jsx(Z,{className:"h-4 w-4"})})]}),t.jsx("div",{className:"border-b border-[var(--border)] p-3",children:t.jsxs("div",{className:"relative",children:[t.jsx($t,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-[var(--text-soft)]"}),t.jsx("input",{ref:V,type:"search",name:Xe,autoComplete:"new-password",autoCorrect:"off",spellCheck:!1,"aria-label":"搜索联系人、商品或消息","data-lpignore":"true","data-1p-ignore":"true","data-bwignore":"true",readOnly:!Ve,value:z,onFocus:()=>{I.current=!0,ae(!0)},onBlur:()=>{I.current=!1,ae(!1)},onChange:e=>{if(!I.current){e.currentTarget.value="",W("");return}W(e.target.value)},placeholder:"搜索联系人、商品或消息",className:"h-9 w-full rounded-md bg-[var(--surface-subtle)] pl-9 pr-3 text-sm text-[var(--text)] outline-none placeholder:text-[var(--text-soft)] focus:ring-2 focus:ring-[var(--brand)]"})]})}),t.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[K&&S.length===0&&t.jsx("div",{className:"flex justify-center py-16",children:t.jsx(U,{className:"h-6 w-6 animate-spin text-[#d6b600]"})}),Se.map(e=>{const s=e.cid===j,a=e.otherUserName||`闲鱼用户 ${e.otherUserId}`;return t.jsxs("button",{type:"button",onClick:()=>rt(e),className:`grid w-full grid-cols-[48px_minmax(0,1fr)_auto] gap-3 px-4 py-3 text-left ${s?"bg-[var(--surface-strong)]":"hover:bg-[var(--surface-hover)]"}`,children:[J(e.otherUserAvatar,a,"h-12 w-12 rounded-full",e.otherUserId),t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("p",{className:"truncate text-sm font-bold text-[var(--text)]",children:a}),e.unreadCount>0&&t.jsx("span",{className:"min-w-5 rounded-full bg-[var(--unread-badge)] px-1.5 text-center text-[10px] leading-5 text-white",children:e.unreadCount>99?"99+":e.unreadCount})]}),t.jsx("p",{className:"mt-1 truncate text-xs text-[var(--text-muted)]",children:e.lastMessageSummary?Pe(e.lastMessageSummary):"暂无消息"}),t.jsx("p",{className:"mt-1 truncate text-[10px] text-[var(--text-soft)]",children:e.itemTitle||(e.itemId?`商品 ${e.itemId}`:"普通会话")})]}),t.jsx("span",{className:"pt-0.5 text-[10px] text-[var(--text-soft)]",children:Oe(e.lastMessageTime)})]},e.cid)}),!K&&Se.length===0&&t.jsxs("div",{className:"px-6 py-20 text-center",children:[t.jsx(Re,{className:"mx-auto h-9 w-9 text-[var(--text-soft)]"}),t.jsx("p",{className:"mt-3 text-sm text-[var(--text-muted)]",children:l!=null&&l.connected?"暂无会话":"账号离线,无法读取会话"})]})]})]}),t.jsx("section",{className:`${g==="list"?"hidden lg:flex":"flex"} min-h-0 min-w-0 flex-col`,children:m?t.jsxs(t.Fragment,{children:[t.jsxs("header",{className:"flex h-[68px] shrink-0 items-center justify-between border-b border-[var(--border)] px-5",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("button",{type:"button",onClick:()=>k("list"),className:"-ml-2 flex h-9 w-9 shrink-0 items-center justify-center rounded-md hover:bg-[var(--surface-hover)] lg:hidden",title:"返回会话列表","aria-label":"返回会话列表",children:t.jsx(Fe,{className:"h-5 w-5"})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("h3",{className:"truncate text-base font-bold text-[var(--text)]",children:m.otherUserName||`闲鱼用户 ${m.otherUserId}`}),t.jsx("p",{className:"mt-0.5 truncate text-xs text-[var(--text-soft)]",children:m.otherUserId})]})]}),t.jsxs("span",{className:`inline-flex items-center gap-1.5 text-xs font-bold ${l!=null&&l.connected?"text-emerald-600":"text-[#999]"}`,children:[t.jsx("span",{className:`h-2 w-2 rounded-full ${l!=null&&l.connected?"bg-emerald-500":"bg-[#b8ac8e]"}`}),l!=null&&l.connected?"账号在线":"账号离线"]})]}),t.jsxs("div",{className:"flex min-h-[84px] shrink-0 items-center gap-3 border-b border-[var(--border)] px-4 py-3 sm:min-h-[92px] sm:gap-4 sm:px-5",children:[F(m.itemImage||(h==null?void 0:h.item_image))?t.jsx("img",{src:F(m.itemImage||(h==null?void 0:h.item_image)),alt:"",className:"h-14 w-14 shrink-0 rounded-md object-cover sm:h-16 sm:w-16"}):t.jsx("div",{className:"flex h-14 w-14 shrink-0 items-center justify-center rounded-md bg-[var(--surface-strong)] text-[var(--text-soft)] sm:h-16 sm:w-16",children:t.jsx(Tt,{className:"h-5 w-5"})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("p",{className:"truncate text-sm font-bold text-[var(--text)]",children:m.itemTitle||(h==null?void 0:h.item_title)||"未关联商品"}),(h==null?void 0:h.item_price)&&t.jsxs("p",{className:"mt-1 text-base font-extrabold text-[#ff3b30]",children:[t.jsx("span",{className:"text-xs",children:"¥"}),String(h.item_price).replace(/^[¥¥]\s*/,"")]}),t.jsx("p",{className:"mt-1 truncate text-xs text-[var(--text-soft)]",children:m.itemId?`商品 ID ${m.itemId}`:"普通会话"})]}),t.jsx("span",{className:"hidden rounded-md bg-[var(--brand)] px-4 py-2 text-xs font-bold text-[var(--brand-ink)] sm:inline-flex",children:Y(l)})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto bg-[var(--app-bg)] px-4 py-6 sm:px-8",children:ie&&C.length===0?t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsx(U,{className:"h-6 w-6 animate-spin text-[#d6b600]"})}):t.jsxs("div",{className:"mx-auto max-w-4xl space-y-4",children:[C.map((e,s)=>{const a=C[s-1],i=!a||Math.abs(e.time-a.time)>3e5,c=e.isSelf?Y(l):m.otherUserName||m.otherUserId,f=e.type==="system";return t.jsxs("div",{children:[i&&t.jsx("p",{className:"mb-3 text-center text-[11px] text-[var(--text-soft)]",children:Oe(e.time)}),f?t.jsx("div",{className:"flex justify-center",children:t.jsxs("div",{className:"inline-flex max-w-[86%] items-start gap-2 rounded-lg border border-[var(--border)] bg-[var(--surface)] px-3.5 py-2 text-xs leading-5 text-[var(--text-muted)] shadow-sm",children:[t.jsx(pt,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-[var(--text-soft)]"}),t.jsx("span",{className:"whitespace-pre-wrap break-words",children:e.text})]})}):e.type==="card"?t.jsx("div",{className:"flex justify-center",children:t.jsxs("div",{className:"max-w-[76%] rounded-md border border-[var(--border)] bg-[var(--surface)] px-4 py-3 text-center shadow-[var(--shadow-sm)]",children:[t.jsx("p",{className:"text-[10px] font-bold tracking-[0.15em] text-[var(--text-soft)]",children:"官方卡片"}),t.jsx("p",{className:"mt-1 whitespace-pre-wrap break-words text-sm leading-6 text-[var(--text)]",children:e.text})]})}):t.jsxs("div",{className:`flex items-start gap-2.5 ${e.isSelf?"justify-end":""}`,children:[!e.isSelf&&J(m.otherUserAvatar,c,"h-9 w-9 shrink-0 rounded-full",m.otherUserId),t.jsxs("div",{className:`max-w-[76%] rounded-md px-3.5 py-2.5 text-sm leading-6 ${e.isSelf?"bg-[var(--brand)] text-[var(--brand-ink)] chat-self-bubble":"bg-[var(--surface-strong)] text-[var(--text)]"}`,children:[e.images.map(v=>t.jsx("img",{src:F(v),alt:"聊天图片",className:"mb-2 max-h-80 max-w-full rounded object-contain last:mb-0"},v)),e.text&&t.jsx("p",{className:"whitespace-pre-wrap break-words",children:Pe(e.text)})]}),e.isSelf&&J(l==null?void 0:l.avatarUrl,c,"h-9 w-9 shrink-0 rounded-full",l==null?void 0:l.accountId)]})]},e.messageId||`${e.time}-${s}`)}),C.length===0&&!ie&&t.jsx("p",{className:"py-16 text-center text-sm text-[var(--text-soft)]",children:"暂无聊天记录"}),t.jsx("div",{ref:xe})]})}),t.jsxs("footer",{className:"shrink-0 border-t border-[var(--border)] bg-[var(--surface)] px-4 py-3 sm:px-5",children:[t.jsxs("div",{className:"mb-2 flex items-center gap-4 text-[var(--text-muted)]",children:[t.jsx("button",{type:"button",title:"表情(暂未开放)",className:"hover:text-[var(--text)]",children:t.jsx(Pt,{className:"h-5 w-5"})}),t.jsx("button",{type:"button",title:"发送图片","aria-label":"发送图片",onClick:()=>{var e;return(e=ue.current)==null?void 0:e.click()},disabled:!(l!=null&&l.connected),className:"hover:text-[var(--text)] disabled:cursor-not-allowed disabled:text-[var(--text-soft)]",children:t.jsx(Rt,{className:"h-5 w-5"})}),t.jsx("input",{ref:ue,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:e=>{_e(Array.from(e.target.files||[])),e.target.value=""}}),t.jsx(_t,{open:de,onClose:()=>G(!1),placement:"top",trigger:t.jsx("button",{type:"button",title:"快捷短语",onClick:()=>G(e=>!e),className:`hover:text-[var(--text)] ${de?"text-[var(--text)]":""}`,children:t.jsx(Et,{className:"h-5 w-5"})}),children:oe.length===0?t.jsx("p",{className:"px-2 py-3 text-xs text-gray-500",children:"还没有快捷短语,可在「设置」中添加。"}):oe.map(e=>t.jsxs("button",{type:"button",onClick:()=>nt(e),className:"block w-full rounded-md px-2 py-2 text-left hover:bg-[var(--surface-hover)]",children:[t.jsxs("span",{className:"block text-xs font-semibold text-[var(--text)]",children:["[",e.category,"] ",e.title]}),t.jsx("span",{className:"mt-0.5 block truncate text-xs text-gray-500",children:e.content})]},e.id))})]}),b.length>0&&t.jsxs("div",{className:"mb-2 rounded-md border border-[var(--border)] bg-[var(--surface-strong)] p-2",children:[t.jsx("div",{className:"flex flex-wrap gap-2",children:b.map((e,s)=>t.jsxs("div",{className:"relative h-16 w-16 shrink-0 overflow-hidden rounded-md border border-[var(--border)] bg-[var(--surface)]",children:[t.jsx("img",{src:e.url,alt:e.file.name||"待发送图片",className:"h-full w-full object-cover"}),t.jsx("button",{type:"button",title:"移除这张图片","aria-label":`移除${e.file.name||"图片"}`,onClick:()=>it(s),className:"absolute right-0.5 top-0.5 rounded-full bg-black/60 p-0.5 text-white hover:bg-black/80",children:t.jsx(gt,{className:"h-3 w-3"})})]},e.url))}),t.jsxs("p",{className:"mt-1.5 text-[11px] leading-4 text-[var(--text-soft)]",children:[b.length," 张图片待发送,会跟在文字后面逐张发出"]})]}),t.jsxs("div",{className:"flex items-end gap-2 sm:gap-3",children:[t.jsx("textarea",{value:B,onChange:e=>q(e.target.value),onPaste:e=>{var i;const s=(i=e.clipboardData)==null?void 0:i.files;if(!s||s.length===0)return;const a=[];for(let c=0;c<s.length;c+=1){const f=s[c];f&&f.type.startsWith("image/")&&a.push(f)}a.length!==0&&(e.preventDefault(),_e(a))},onKeyDown:e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),Ie())},rows:2,placeholder:l!=null&&l.connected?"输入消息,可直接粘贴图片":"账号离线,暂时无法发送",disabled:!(l!=null&&l.connected),className:"min-h-[56px] min-w-0 flex-1 resize-none border-0 bg-[var(--surface)] px-0 py-1 text-sm leading-6 text-[var(--text)] outline-none placeholder:text-[var(--text-soft)] disabled:bg-[var(--surface)] sm:min-h-[72px]"}),t.jsxs("button",{type:"button",onClick:()=>void Ie(),disabled:!B.trim()&&b.length===0||H||!(l!=null&&l.connected),className:"flex h-9 shrink-0 items-center gap-2 rounded-md bg-[var(--brand)] px-4 text-sm font-bold text-[var(--brand-ink)] hover:bg-[var(--brand-hover)] disabled:cursor-not-allowed disabled:bg-[var(--surface-strong)] disabled:text-[var(--text-soft)] sm:px-5",children:[H?t.jsx(U,{className:"h-4 w-4 animate-spin"}):t.jsx(Lt,{className:"h-4 w-4"}),"发送"]})]})]})]}):t.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center px-6 text-center",children:[t.jsx(Re,{className:"h-12 w-12 text-[var(--text-soft)]"}),t.jsx("p",{className:"mt-4 text-sm font-bold text-[var(--text-muted)]",children:"选择一条会话查看消息"}),t.jsx("p",{className:"mt-1 text-xs text-[var(--text-soft)]",children:"会话和聊天记录直接来自当前闲鱼账号"})]})})]}):t.jsx("div",{className:"h-full overflow-y-auto bg-[var(--app-bg)] p-4 sm:p-6 lg:p-8",children:t.jsxs("div",{className:"page-stack mx-auto max-w-[1320px]",children:[t.jsxs("header",{className:"page-header",children:[t.jsxs("div",{children:[t.jsx("h1",{className:"page-title",children:"消息过滤规则"}),t.jsx("p",{className:"page-description",children:"集中管理无需自动回复或无需外部通知的消息关键词。"})]}),t.jsxs("button",{type:"button",onClick:()=>d("messages"),className:"ios-btn-secondary flex items-center gap-2 rounded-md px-4 py-2.5 text-sm",children:[t.jsx(Fe,{className:"h-4 w-4"}),"返回消息"]})]}),t.jsxs("section",{className:"section-panel",children:[t.jsx(Ee,{title:"批量添加规则",description:"每行填写一个关键词,重复内容会自动跳过。",icon:Le}),t.jsxs("div",{className:"grid gap-3 p-4 lg:grid-cols-[220px_180px_minmax(240px,1fr)_auto]",children:[t.jsxs("select",{value:X,onChange:e=>je(e.target.value),className:"ios-input rounded-md px-3 py-2.5 text-sm",children:[t.jsx("option",{value:"",children:"选择账号"}),ee.map(e=>t.jsx("option",{value:e.id,children:e.nickname||e.remark||e.id},e.id))]}),t.jsxs("select",{value:ye,onChange:e=>tt(e.target.value),className:"ios-input rounded-md px-3 py-2.5 text-sm",children:[t.jsx("option",{value:"skip_reply",children:"跳过自动回复"}),t.jsx("option",{value:"skip_notify",children:"跳过外部通知"})]}),t.jsx("textarea",{value:ve,onChange:e=>we(e.target.value),rows:2,placeholder:`每行一个关键词,例如:
系统通知`,className:"ios-input min-h-20 resize-y rounded-md px-3 py-2.5 text-sm"}),t.jsxs("button",{type:"button",onClick:()=>void lt(),disabled:Ne,className:"ios-btn-primary flex min-h-11 items-center justify-center gap-2 rounded-md px-4 py-2.5 text-sm disabled:opacity-50",children:[Ne?t.jsx(U,{className:"h-4 w-4 animate-spin"}):t.jsx(Le,{className:"h-4 w-4"}),"批量添加"]})]})]}),t.jsxs("section",{className:"section-panel",children:[t.jsx(Ee,{title:"现有规则",description:`当前筛选共 ${y.length} 条`,icon:Z}),t.jsxs("div",{className:"toolbar rounded-none border-x-0 border-t-0 shadow-none",children:[t.jsxs("div",{className:"toolbar__group",children:[t.jsxs("select",{value:ge,onChange:e=>Ye(e.target.value),className:"ios-input rounded-md px-3 py-2.5 text-sm sm:min-w-52",children:[t.jsx("option",{value:"",children:"全部账号"}),ee.map(e=>t.jsx("option",{value:e.id,children:e.nickname||e.remark||e.id},e.id))]}),t.jsxs("select",{value:be,onChange:e=>et(e.target.value),className:"ios-input rounded-md px-3 py-2.5 text-sm sm:min-w-44",children:[t.jsx("option",{value:"",children:"全部用途"}),t.jsx("option",{value:"skip_reply",children:"跳过自动回复"}),t.jsx("option",{value:"skip_notify",children:"跳过外部通知"})]}),t.jsxs("button",{type:"button",onClick:()=>void N(),className:"ios-btn-secondary flex items-center justify-center gap-2 rounded-md px-4 py-2.5 text-sm",children:[t.jsx($e,{className:`h-4 w-4 ${fe?"animate-spin":""}`}),"查询"]})]}),w.length>0&&t.jsxs("button",{type:"button",onClick:()=>void ct(),className:"ios-btn-danger flex items-center justify-center gap-2 rounded-md px-4 py-2.5 text-sm",children:[t.jsx(Ue,{className:"h-4 w-4"}),"删除所选"]})]}),t.jsxs("div",{className:"divide-y divide-[#eeeeee] px-4",children:[y.length>0&&t.jsxs("label",{className:"flex items-center gap-3 py-3 text-xs font-bold text-[var(--text-muted)]",children:[t.jsx("input",{type:"checkbox",checked:at,onChange:e=>R(e.target.checked?y.map(s=>s.id):[]),className:"h-4 w-4 accent-[#f5c400]"}),"全选当前列表"]}),y.map(e=>t.jsxs("div",{className:"grid gap-3 py-4 sm:grid-cols-[24px_52px_180px_minmax(0,1fr)_44px] sm:items-center",children:[t.jsx("input",{type:"checkbox",checked:w.includes(e.id),onChange:s=>R(a=>s.target.checked?[...a,e.id]:a.filter(i=>i!==e.id)),className:"h-4 w-4 accent-[#f5c400]"}),t.jsx("button",{type:"button",role:"switch","aria-checked":e.enabled,onClick:()=>void bt(e.id).then(N),title:e.enabled?"停用规则":"启用规则",className:`relative h-6 w-11 rounded-full transition-colors ${e.enabled?"bg-[#f5c800]":"bg-gray-300"}`,children:t.jsx("span",{className:`absolute left-1 top-1 h-4 w-4 rounded-full bg-white transition-transform ${e.enabled?"translate-x-5":""}`})}),t.jsxs("div",{children:[t.jsx("p",{className:"break-all text-sm font-bold text-[var(--text)]",children:e.cookie_id}),t.jsx("p",{className:"mt-1 text-xs text-[var(--text-muted)]",children:Qt[e.filter_type]})]}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"break-words text-sm font-medium text-[var(--text)]",children:e.keyword}),t.jsx("p",{className:"mt-1 text-xs text-[var(--text-soft)]",children:Gt(e.updated_at||e.created_at)})]}),t.jsx("button",{type:"button",onClick:()=>void ot(e),title:"删除规则",className:"flex h-9 w-9 items-center justify-center rounded-md bg-red-50 text-red-600 hover:bg-red-100",children:t.jsx(Ue,{className:"h-4 w-4"})})]},e.id)),!fe&&y.length===0&&t.jsx(It,{compact:!0,title:"暂无消息过滤规则",description:"添加规则后可跳过指定消息的自动回复或外部通知。",icon:Z})]})]})]})})};export{ls as default};