PageSourceSearch

https://pdaus.org/assets/DepartmentEmailConfigurator-cyDyop9D.js

js pdaus.org collected 2026-09-24 14:27:14 UTC 12,932 bytes, 1 lines download raw bytes

1import{r as i,a as m,S as f,T as j,U as N,p as E,s as v,j as e,d as D,f as Z}from"./index-Cy0mEndq.js";import{P as $}from"./plus-DH8-9wis.js";import{S as ee}from"./save-DeThRMia.js";import{R as ae}from"./rotate-ccw-BVx15U7N.js";import{C as se}from"./circle-alert-CVSuIxwP.js";import{C as re}from"./circle-check-big-D6PvPBn2.js";import{E as R}from"./eye-DUPav99f.js";import{T as le}from"./trash-2-qpUYEtGq.js";function ge(){const[P,A]=i.useState([]),[t,I]=i.useState("legal"),[n,c]=i.useState([]),[te,T]=i.useState([]),[L,w]=i.useState(!0),[_,k]=i.useState(!1),[d,C]=i.useState(null),[x,M]=i.useState(""),[p,q]=i.useState(null),g={legal:{label:"法律服务 Legal",icon:f,color:"blue"},healthcare:{label:"医疗健康 Healthcare",icon:N,color:"green"},education:{label:"教育培训 Education",icon:E,color:"purple"},employment:{label:"就业服务 Employment",icon:N,color:"orange"},technology:{label:"技术服务 Technology",icon:j,color:"pink"},donation:{label:"捐款服务 Donation",icon:m,color:"yellow"},privacy:{label:"隐私咨询 Privacy",icon:f,color:"red"},general:{label:"综合服务 General",icon:m,color:"indigo"}},u=[{email:"[email protected]",label:"综合咨询邮箱"},{email:"[email protected]",label:"技术支持邮箱"},{email:"[email protected]",label:"法律援助邮箱"},{email:"[email protected]",label:"捐款专用邮箱"},{email:"[email protected]",label:"隐私政策邮箱"},{email:"[email protected]",label:"团队协作邮箱"},{email:"[email protected]",label:"J&S驾校培训邮箱"}],S=[{value:"single",label:"单一路由",description:"只发送到优先级最高的邮箱",icon:m},{value:"multiple",label:"多重路由",description:"同时发送到所有选中的邮箱",icon:N},{value:"load_balance",label:"负载均衡",description:"根据邮箱负载自动选择",icon:j},{value:"fallback",label:"备用路由",description:"主邮箱无响应时转发备用",icon:f}];i.useEffect(()=>{z()},[]),i.useEffect(()=>{t&&b(t)},[t]);const z=async()=>{w(!0);try{A(Object.keys(g)),T(u),await b("legal")}catch{o("加载数据失败","error")}finally{w(!1)}},b=async a=>{try{const{data:s,error:r}=await v.from("department_email_config").select("*").eq("department",a).order("priority",{ascending:!1});if(r)throw r;!s||s.length===0?c(h(a)):c(s)}catch{c(h(a))}},h=a=>({legal:[{email:"[email protected]",priority:10,is_enabled:!0,role:"primary"},{email:"[email protected]",priority:5,is_enabled:!0,role:"backup"}],healthcare:[{email:"[email protected]",priority:10,is_enabled:!0,role:"primary"},{email:"[email protected]",priority:8,is_enabled:!1,role:"backup"}],education:[{email:"[email protected]",priority:10,is_enabled:!0,role:"primary"},{email:"[email protected]",priority:7,is_enabled:!0,role:"backup"}],technology:[{email:"[email protected]",priority:10,is_enabled:!0,role:"primary"},{email:"[email protected]",priority:7,is_enabled:!1,role:"backup"}],donation:[{email:"[email protected]",priority:10,is_enabled:!0,role:"primary"},{email:"[email protected]",priority:5,is_enabled:!1,role:"backup"}],privacy:[{email:"[email protected]",priority:10,is_enabled:!0,role:"primary"},{email:"[email protected]",priority:7,is_enabled:!1,role:"backup"}],general:[{email:"[email protected]",priority:10,is_enabled:!0,role:"primary"},{email:"[email protected]",priority:5,is_enabled:!1,role:"backup"}]})[a]||[{email:"[email protected]",priority:10,is_enabled:!0,role:"primary"}],F=a=>{c(s=>s.map(r=>r.email===a?{...r,is_enabled:!r.is_enabled}:r))},G=(a,s)=>{c(r=>r.map(l=>l.email===a?{...l,priority:parseInt(s)}:l))},O=a=>{if(n.some(r=>r.email===a)){o("该邮箱已在配置中","warning");return}const s={department:t,email:a,is_enabled:!1,priority:5,role:"backup",routing_strategy:"single"};c(r=>[...r,s])},U=a=>{if(n.filter(s=>s.is_enabled).length<=1){o("至少需要保留一个启用的邮箱","error");return}c(s=>s.filter(r=>r.email!==a))},B=a=>{c(s=>s.map(r=>({...r,routing_strategy:a})))},H=async()=>{k(!0);try{await v.from("department_email_config").delete().eq("department",t);const{error:a}=await v.from("department_email_config").insert(n.map(s=>({...s,department:t,updated_at:new Date().toISOString()})));if(a)throw a;o("配置保存成功","success"),await b(t)}catch(a){o("保存失败: "+a.message,"error")}finally{k(!1)}},J=()=>{confirm("确定要重置为默认配置吗?")&&(c(h(t)),o("已重置为默认配置","info"))},K=async()=>
1{if(!x.trim()){o("请输入测试消息","warning");return}try{const a=n.filter(l=>l.is_enabled).sort((l,Y)=>Y.priority-l.priority);if(a.length===0){o("没有启用的邮箱","error");return}const s=n[0]?.routing_strategy||"single";let r=[];switch(s){case"single":r=[a[0]];break;case"multiple":r=a;break;case"load_balance":r=[a[0]];break;case"fallback":r=[a[0]];break}q({department:t,strategy:s,emails:r.map(l=>l.email),message:x}),o("路由预览成功","success")}catch{o("预览失败","error")}},o=(a,s="info")=>{C({message:a,type:s}),setTimeout(()=>C(null),3e3)},Q=a=>{const s=u.find(r=>r.email===a);return s?s.label:a};if(L)return e.jsxs("div",{className:"flex items-center justify-center h-screen",children:[e.jsx(D,{className:"w-8 h-8 animate-spin text-blue-600"}),e.jsx("span",{className:"ml-2 text-gray-600",children:"加载配置中..."})]});const y=g[t],V=y.icon,W=n[0]?.routing_strategy||"single",X=n.filter(a=>a.is_enabled).length;return e.jsxs("div",{className:"min-h-screen bg-gray-50 p-6",children:[d&&e.jsxs("div",{className:`fixed top-4 right-4 z-50 flex items-center gap-2 px-4 py-3 rounded-lg shadow-lg ${d.type==="success"?"bg-green-500":d.type==="error"?"bg-red-500":d.type==="warning"?"bg-yellow-500":"bg-blue-500"} text-white`,children:[d.type==="success"&&e.jsx(re,{className:"w-5 h-5"}),d.type==="error"&&e.jsx(se,{className:"w-5 h-5"}),d.message]}),e.jsx("div",{className:"max-w-7xl mx-auto mb-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold text-gray-900 flex items-center gap-3",children:[e.jsx(j,{className:"w-8 h-8 text-blue-600"}),"部门邮箱配置器"]}),e.jsx("p",{className:"text-gray-600 mt-1",children:"为每个部门灵活配置多个功能邮箱和路由策略"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:J,className:"flex items-center gap-2 px-4 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition-colors",children:[e.jsx(ae,{className:"w-4 h-4"}),"重置"]}),e.jsx("button",{onClick:H,disabled:_,className:"flex items-center gap-2 px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors disabled:opacity-50",children:_?e.jsxs(e.Fragment,{children:[e.jsx(D,{className:"w-4 h-4 animate-spin"}),"保存中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"w-4 h-4"}),"保存配置"]})})]})]})}),e.jsxs("div",{className:"max-w-7xl mx-auto grid grid-cols-4 gap-6",children:[e.jsxs("div",{className:"col-span-1 bg-white rounded-lg shadow-md p-4",children:[e.jsxs("h3",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[e.jsx(E,{className:"w-5 h-5 text-blue-600"}),"选择部门"]}),e.jsx("div",{className:"space-y-2",children:P.map(a=>{const s=g[a],r=s.icon,l=a===t;return e.jsxs("button",{onClick:()=>I(a),className:`w-full flex items-center gap-3 px-3 py-2 rounded-lg transition-colors ${l?"bg-blue-50 border-2 border-blue-500 text-blue-700":"hover:bg-gray-50 border-2 border-transparent text-gray-700"}`,children:[e.jsx(r,{className:`w-5 h-5 ${l?"text-blue-600":"text-gray-400"}`}),e.jsx("span",{className:"text-sm font-medium",children:s.label})]},a)})})]}),e.jsx("div",{className:"col-span-2 space-y-6",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-md p-6",children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(V,{className:`w-8 h-8 text-${y.color}-600`}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-gray-900",children:y.label}),e.jsxs("p",{className:"text-sm text-gray-600",children:[X," 个启用的邮箱 · ",n.length," 个配置项"]})]})]})}),e.jsxs("div",{className:"mb-6",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"路由策略"}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:S.map(a=>{const s=a.icon,r=W===a.value;return e.jsxs("button",{onClick:()=>B(a.value),className:`flex items-start gap-3 p-3 rounded-lg border-2 transition-colors ${r?"border-blue-500 bg-blue-50":"border-gray-200 hover:border-gray-300"}`,children:[e.jsx(s,{className:`w-5 h-5 mt-0.5 ${r?"text-blue-600":"text-gray-400"}`}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:`font-medium text-sm ${r?"text-blue-900":"text-gray-900"}`,children:a.label}),e.jsx("div",{className:"text-xs text-gray-600 mt-1",children:a.description})]})]},a.value)})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-3",children:"邮箱配置列表"}),e.jsx("div",{className:"space-y-3",children:n.map((a,s)=>e.jsxs("div",{className:`flex items-center gap-3 p-4 rounded-lg border-2 transition-all ${a.is_enabled?"border-green-500 bg-green-50":"border-gray-200 bg-gray-50"}`,children:[e.jsx("button",{onClick:()=>F(a.email),className:`flex-shrink-0 w-6 h-6 rounded border-2 flex items-center justify-center transition-colors ${a.is_enabled?"bg-green-600 border-green-600":"bg-white border-gray-300"}`,children:a.is_enabled&&e.jsx(Z,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-medium text-gray-900",children:a.email}),e.jsx("div",{className:"text-xs text-gray-600",children:Q(a.email)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"优先级:"}),e.jsx("input",{type:"number",min:"1",max:"10",value:a.priority,onChange:r=>G(a.email,r.target.value),className:"w-16 px-2 py-1 border border-gray-300 rounded text-center text-sm"})]}),e.jsx("span",{className:`px-2 py-1 text-xs font-medium rounded ${a.role==="primary"?"bg-blue-100 text-blue-800":"bg-gray-100 text-gray-800"}`,children:a.role==="primary"?"主要":"备用"}),e.jsx("button",{onClick:()=>U(a.email),className:"p-1 text-red-600 hover:bg-red-50 rounded transition-colors",title:"删除",children:e.jsx(le,{className:"w-4 h-4"})})]},a.email))}),e.jsx("div",{className:"mt-4",children:e.jsxs("details",{className:"group",children:[e.jsxs("summary",{className:"flex items-center gap-2 px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-lg cursor-pointer transition-colors",children:[e.jsx($,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm font-medium",children:"添加新邮箱"})]}),e.jsx("div",{className:"mt-3 p-4 bg-gray-50 rounded-lg border-2 border-dashed border-gray-300",children:e.jsx("div",{className:"grid grid-cols-2 gap-2",children:u.filter(a=>!n.some(s=>s.email===a.email)).map(a=>e.jsxs("button",{onClick:()=>O(a.email),className:"flex items-center gap-2 px-3 py-2 bg-white border border-gray-300 rounded-lg hover:border-blue-500 hover:bg-blue-50 transition-colors text-left",children:[e.jsx($,{className:"w-4 h-4 text-blue-600"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-gray-900",children:a.email}),e.jsx("div",{className:"text-xs text-gray-600",children:a.label})]})]},a.email))})})]})})]})]})}),e.jsx("div",{className:"col-span-1 space-y-4",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-md p-4 sticky top-6",children:[e.jsxs("h3",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[e.jsx(R,{className:"w-5 h-5 text-blue-600"}),"路由预览"]}),e.jsx("textarea",{value:x,onChange:a=>M(a.target.value),placeholder:"输入测试消息...",className:"w-full h-32 px-3 py-2 border border-gray-300 rounded-lg resize-none focus:outline-none focus:ring-2 focus:ring-blue-500 text-sm"}),e.jsxs("button",{onClick:K,className:"w-full mt-3 flex items-center justify-center gap-2 px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors",children:[e.jsx(R,{className:"w-4 h-4"}),"预览路由"]}),p&&e.jsxs("div",{className:"mt-4 p-3 bg-blue-50 border-2 border-blue-200 rounded-lg",children:[e.jsx("div",{className:"text-sm font-medium text-blue-900 mb-2",children:"路由结果:"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-xs text-gray-600",children:[e.jsx("span",{className:"font-medium",children:"策略:"}
1)," ",S.find(a=>a.value===p.strategy)?.label]}),e.jsx("div",{className:"text-xs text-gray-600",children:e.jsx("span",{className:"font-medium",children:"目标邮箱:"})}),p.emails.map((a,s)=>e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 bg-white rounded text-xs",children:[e.jsx(m,{className:"w-3 h-3 text-blue-600"}),e.jsx("span",{className:"font-mono",children:a})]},s))]})]})]})})]})]})}export{ge as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.