2 lines
26 KiB
JavaScript
Vendored
2 lines
26 KiB
JavaScript
Vendored
import{r as l,j as t,bc as E,e as ee,L as te,aE as ot,C as ct,X as Se,o as dt,bm as mt,bn as xt,bo as pt,n as o,bp as ut,bq as ht,br as _e,v as se,bs as yt,bt as Re,bu as bt,bv as gt,bw as ft,bx as jt,by as Nt}from"./index-IP-mmLlr.js";import{a as vt,b as wt,S as $,E as L}from"./ui-Fi8l9rTp.js";import{L as ae}from"./link-2-xKkzn7ZQ.js";import{S as le}from"./shield-alert-B8_J0uYT.js";import{A as ne}from"./activity-Dmn-a3S9.js";import{P as Ee}from"./plus-BbnHS2Zx.js";import{P as $e}from"./pen-line-D5rb4QS3.js";import{T as ie}from"./trash-2-BNPsgs2t.js";import{S as kt}from"./send-CwI5w629.js";import{C as Ct,a as St}from"./chevron-right-CbwGgzS_.js";import{S as Le}from"./save-CNiIU-3u.js";import{C as _t}from"./check-D50E5xnW.js";const y={dingtalk:{label:"钉钉",fields:[{key:"webhook_url",label:"Webhook 地址",placeholder:"https://oapi.dingtalk.com/robot/send?..."},{key:"secret",label:"加签密钥",type:"password",optional:!0}],defaults:{}},feishu:{label:"飞书",fields:[{key:"webhook_url",label:"Webhook 地址",placeholder:"https://open.feishu.cn/open-apis/bot/v2/hook/..."},{key:"secret",label:"签名密钥",type:"password",optional:!0}],defaults:{}},bark:{label:"Bark",fields:[{key:"device_key",label:"Device Key",type:"password"},{key:"server_url",label:"服务器地址",placeholder:"https://api.day.app",optional:!0}],defaults:{server_url:"https://api.day.app"}},email:{label:"邮件",fields:[{key:"smtp_server",label:"SMTP 服务器",placeholder:"留空则使用「系统设置 → 邮件服务」",optional:!0},{key:"smtp_port",label:"SMTP 端口",type:"number",placeholder:"留空则使用系统设置(如 465)",optional:!0},{key:"email_user",label:"发件邮箱",placeholder:"留空则使用系统设置的发件邮箱",optional:!0},{key:"email_password",label:"邮箱密码或授权码",type:"password",placeholder:"留空则使用系统设置的授权码",optional:!0},{key:"recipient_email",label:"接收邮箱",placeholder:"必填,通知发到这个邮箱"}],defaults:{}},webhook:{label:"Webhook",fields:[{key:"webhook_url",label:"Webhook 地址"},{key:"http_method",label:"请求方法",type:"select",options:["POST","PUT"]},{key:"headers",label:"请求头 JSON",type:"textarea",placeholder:'{"Authorization":"Bearer ..."}',optional:!0}],defaults:{http_method:"POST",headers:"{}"}},wechat:{label:"企业微信",fields:[{key:"webhook_url",label:"机器人 Webhook 地址"}],defaults:{}},telegram:{label:"Telegram",fields:[{key:"bot_token",label:"Bot Token",type:"password"},{key:"chat_id",label:"Chat ID"}],defaults:{}}},re=20,Rt=i=>{var k,x;const r=(x=(k=i==null?void 0:i.response)==null?void 0:k.data)==null?void 0:x.detail;if(r&&typeof r=="object"&&"message"in r){const b=r.message;if(typeof b=="string"&&b.trim())return b.trim()}return typeof r=="string"&&r.trim()?r.trim():i instanceof Error&&i.message?i.message:"测试发送失败,请稍后重试"},oe=i=>i.nickname||i.remark||i.id,T=i=>{if(!i)return"-";const r=new Date(i.includes("T")?i:`${i.replace(" ","T")}Z`);return Number.isNaN(r.getTime())?i:r.toLocaleString("zh-CN")},Wt=({isAdmin:i})=>{const[r,k]=l.useState("channels"),[x,b]=l.useState([]),[A,ce]=l.useState([]),[de,D]=l.useState([]),[Te,g]=l.useState({}),[f,Ae]=l.useState([]),[me,De]=l.useState([]),[C,xe]=l.useState(!0),[Pe,j]=l.useState(!1),[N,pe]=l.useState(null),[P,B]=l.useState("dingtalk"),[O,I]=l.useState(""),[d,p]=l.useState({}),[ue,he]=l.useState(!1),[Be,u]=l.useState(!1),[v,ye]=l.useState(null),[M,q]=l.useState(""),[W,G]=l.useState(""),[z,F]=l.useState(""),[H,h]=l.useState([]),[be,S]=l.useState(!1),[ge,Oe]=l.useState([]),[fe,Ie]=l.useState(0),[U,Me]=l.useState(""),[Z,qe]=l.useState(""),[w,_]=l.useState(0),[J,je]=l.useState(!1),[Ne,We]=l.useState([]),[ve,Ge]=l.useState(""),[R,we]=l.useState(""),[K,ke]=l.useState(!1),m=async()=>{xe(!0);try{const[e,s,a,n]=await Promise.all([dt(),mt(),xt(),pt()]);b(e),ce(s.data),D(a.data),g(c=>{const rt=new Set(a.data.map(Y=>String(Y.id)));return Object.fromEntries(Object.entries(c).filter(([Y])=>rt.has(Y)))}),Ae(n.events),De(n.priorities)}catch(e){o(`加载通知配置失败:${e.message}`)}finally{xe(!1)}};l.useEffect(()=>{m()},[]);const ze=()=>{const e="dingtalk";pe(null),B(e),I(""),p({...y[e].defaults}),j(!0)},Fe=e=>{pe(e),B(e.type),I(e.name),p({...y[e.type].defaults,...e.config}),j(!0)},He=e=>{B(e),p({...y[e].defaults})},Ue=async()=>{he(!0);try{N?await _e(N.id,{name:O,config:d,enabled:N.enabled}):await jt({name:O,type:P,config:d}),j(!1),await m()}catch(e){o(`保存通知渠道失败:${e.message}`)}finally{he(!1)}},Ze=async e=>{try{await _e(e.id,{enabled:!e.enabled}),ce(s=>s.map(a=>a.id===e.id?{...a,enabled:!a.enabled}:a)),e.enabled?D(s=>s.filter(a=>a.channel_id!==Number(e.id))):await m()}catch(s){o(`更新渠道状态失败:${s.message}`)}},Je=async e=>{if(await se(`确认删除通知渠道“${e.name}”?相关账号绑定也会被删除。`))try{await yt(e.id),await m()}catch(s){o(`删除通知渠道失败:${s.message}`)}},Ke=e=>{var s;return((s=f.find(a=>a.id===e))==null?void 0:s.label)||e},Xe=e=>!e.event_types||e.event_types.length===0?"全部事件":e.event_types.map(Ke).join("、"),Qe=me.length>0?me:Array.from(new Set(f.map(e=>e.priority))).map(e=>({id:e,label:e==="critical"?"关键":e==="warning"?"重要":"一般"})),Ve=()=>{var e;ye(null),q(((e=x[0])==null?void 0:e.id)||""),G(""),F(""),h([]),u(!0)},Ye=e=>{ye(e),q(e.cookie_id),G(String(e.channel_id)),F(e.name||""),h(e.event_types||[]),u(!0)},et=e=>{h(s=>s.includes(e)?s.filter(a=>a!==e):[...s,e])},X=e=>{if(e==="all"){h(f.map(s=>s.id));return}if(e==="none"){h([]);return}h(f.filter(s=>s.priority===e).map(s=>s.id))},tt=async()=>{if(v){S(!0);try{await Re(v.id,{name:z.trim(),eventTypes:H}),u(!1),await m()}catch(e){o(`保存通知规则失败:${e.message}`)}finally{S(!1)}return}if(!M||!W){o("请选择账号和通知渠道");return}S(!0);try{await Nt(M,Number(W),!0,{name:z.trim(),eventTypes:H}),u(!1),await m()}catch(e){o(`创建通知规则失败:${e.message}`)}finally{S(!1)}},st=async e=>{try{await Re(e.id,{enabled:!e.enabled}),await m()}catch(s){o(`更新通知规则失败:${s.message}`)}},at=async e=>{const s=String(e.id);g(a=>({...a,[s]:{status:"sending",message:"发送中"}}));try{const a=await bt(e.id),n=`${a.message} · ${a.channel.name}`;g(c=>({...c,[s]:{status:"success",message:n,requestId:a.request_id,sentAt:a.sent_at}})),o(`${n}(请求 ID:${a.request_id})`,"success")}catch(a){const n=Rt(a);g(c=>({...c,[s]:{status:"error",message:n}})),o(`测试发送失败:${n}`,"error")}},lt=async e=>{const s=e.name||e.channel_name;if(await se(`确认删除通知规则“${s}”?`))try{await gt(e.id),D(a=>a.filter(n=>n.id!==e.id)),g(a=>{const n={...a};return delete n[String(e.id)],n})}catch(a){o(`删除通知规则失败:${a.message}`)}},Q=async(e=w)=>{je(!0);try{const s=await ut({cookie_id:U||void 0,processing_status:Z||void 0,limit:re,offset:e*re});Oe(s.data||[]),Ie(s.total||0)}catch(s){o(`加载风控日志失败:${s.message}`)}finally{je(!1)}};l.useEffect(()=>{r==="risk"&&Q()},[r,U,Z,w]);const nt=async e=>{if(await se("确认删除这条风控日志?"))try{const s=await ft(e.id);if(s.success===!1)throw new Error(s.message||"删除失败");await Q()}catch(s){o(`删除风控日志失败:${s.message}`)}},Ce=async()=>{if(i){ke(!0);try{const e=await ht({lines:300,level:ve||void 0,source:R.trim()||void 0});if(!e.success)throw new Error(e.message||"加载失败");We(e.logs||[])}catch(e){o(`加载系统日志失败:${e.message}`)}finally{ke(!1)}}};l.useEffect(()=>{r==="system"&&i&&Ce()},[r]);const V=Math.max(1,Math.ceil(fe/re)),it=[{id:"channels",label:"通知渠道",icon:E},{id:"bindings",label:"账号通知",icon:ae},{id:"risk",label:"风控日志",icon:le},...i?[{id:"system",label:"系统日志",icon:ne}]:[]];return t.jsxs("div",{className:"page-stack animate-fade-in",children:[t.jsx(vt,{title:"通知与日志",description:"统一管理外部通知渠道、账号绑定、风控事件和系统运行日志。",icon:E,actions:t.jsxs("button",{type:"button",onClick:()=>void m(),disabled:C,className:"ios-btn-secondary flex items-center justify-center gap-2 rounded-md px-4 py-2.5 text-sm disabled:opacity-50",children:[t.jsx(ee,{className:`h-4 w-4 ${C?"animate-spin":""}`}),"刷新配置"]})}),t.jsx(wt,{value:r,onChange:k,items:it,ariaLabel:"通知与日志功能"}),r==="channels"&&t.jsxs("section",{className:"section-panel",children:[t.jsx($,{title:"通知渠道",description:"密钥仅用于服务端发送通知,请避免在日志或截图中公开。",icon:E,actions:t.jsxs("button",{type:"button",onClick:ze,className:"ios-btn-primary flex items-center gap-2 rounded-md px-4 py-2.5 text-sm",children:[t.jsx(Ee,{className:"h-4 w-4"}),"新建渠道"]})}),t.jsxs("div",{className:"divide-y divide-gray-100 px-4",children:[A.map(e=>{var s;return t.jsxs("div",{className:"flex flex-col gap-3 py-4 sm:flex-row sm:items-center",children:[t.jsx("button",{type:"button",role:"switch","aria-checked":e.enabled,onClick:()=>void Ze(e),className:`relative h-6 w-11 shrink-0 rounded-full transition-colors ${e.enabled?"bg-[#ffe100]":"bg-gray-300"}`,title:e.enabled?"停用渠道":"启用渠道",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",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("span",{className:"font-bold text-gray-900",children:e.name}),t.jsx("span",{className:"rounded bg-gray-100 px-2 py-0.5 text-xs font-bold text-gray-600",children:((s=y[e.type])==null?void 0:s.label)||e.type})]}),t.jsxs("p",{className:"mt-1 text-xs text-gray-500",children:[e.enabled?"可用于账号通知":"已停用",e.updated_at?` · 更新于 ${T(e.updated_at)}`:""]})]}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("button",{type:"button",onClick:()=>Fe(e),title:"编辑渠道",className:"flex h-9 w-9 items-center justify-center rounded-md bg-gray-100 text-gray-700 hover:bg-gray-200",children:t.jsx($e,{className:"h-4 w-4"})}),t.jsx("button",{type:"button",onClick:()=>void Je(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(ie,{className:"h-4 w-4"})})]})]},e.id)}),!C&&A.length===0&&t.jsx(L,{compact:!0,title:"暂无通知渠道",description:"新建渠道后可绑定到指定闲鱼账号。",icon:E})]})]}),r==="bindings"&&t.jsxs("section",{className:"section-panel",children:[t.jsx($,{title:"账号通知规则",description:"同一账号可配置多条规则,按事件类型选择要通知的内容;测试发送会真实触达当前渠道。",icon:ae,actions:t.jsxs("button",{type:"button",onClick:Ve,className:"ios-btn-primary flex items-center gap-2 rounded-md px-4 py-2.5 text-sm",children:[t.jsx(Ee,{className:"h-4 w-4"}),"新建规则"]})}),t.jsxs("div",{className:"divide-y divide-gray-100 px-4",children:[de.map(e=>{const s=x.find(c=>c.id===e.cookie_id),a=Te[String(e.id)],n=(a==null?void 0:a.status)==="sending";return t.jsxs("div",{className:"flex flex-col gap-3 py-4 sm:flex-row sm:items-center","aria-busy":n||void 0,children:[t.jsx("button",{type:"button",role:"switch","aria-checked":e.enabled,"aria-label":`${e.name||e.channel_name}通知规则开关`,onClick:()=>void st(e),className:`relative h-6 w-11 shrink-0 rounded-full transition-colors ${e.enabled?"bg-[#ffe100]":"bg-gray-300"}`,title:e.enabled?"暂停规则":"启用规则",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",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("p",{className:"font-bold text-gray-900",children:e.name||"默认规则"}),t.jsx("span",{className:"rounded bg-gray-100 px-2 py-0.5 text-xs font-bold text-gray-600",children:e.channel_name})]}),t.jsxs("p",{className:"mt-1 text-xs text-gray-500",children:[s?oe(s):e.cookie_id," · ",e.channel_enabled===!1?"渠道已停用":e.enabled?"接收通知":"已暂停"]}),t.jsxs("p",{className:"mt-1 break-words text-xs text-gray-500",children:["通知内容:",Xe(e)]})]}),t.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[t.jsxs("button",{type:"button",onClick:()=>void at(e),disabled:n,"aria-label":`测试发送规则${e.name||e.channel_name}`,title:e.enabled?"向该渠道真实发送一条测试消息":"规则已暂停,仅验证渠道配置",className:"ios-btn-secondary flex min-h-11 items-center gap-1.5 rounded-md px-3 text-xs disabled:cursor-wait disabled:opacity-60",children:[n?t.jsx(te,{className:"h-3.5 w-3.5 animate-spin"}):t.jsx(kt,{className:"h-3.5 w-3.5"}),n?"发送中":"测试发送"]}),t.jsx("button",{type:"button",onClick:()=>Ye(e),title:"编辑规则",className:"flex h-9 w-9 items-center justify-center rounded-md bg-gray-100 text-gray-700 hover:bg-gray-200",children:t.jsx($e,{className:"h-4 w-4"})}),t.jsx("button",{type:"button",onClick:()=>void lt(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(ie,{className:"h-4 w-4"})}),a&&a.status!=="sending"&&t.jsxs("span",{role:"status",className:`flex max-w-full items-center gap-1 text-xs ${a.status==="success"?"text-emerald-700":"text-red-700"}`,title:a.requestId?`请求 ID:${a.requestId}`:void 0,children:[a.status==="success"?t.jsx(ot,{className:"h-3.5 w-3.5 shrink-0"}):t.jsx(ct,{className:"h-3.5 w-3.5 shrink-0"}),t.jsxs("span",{className:"break-words",children:[a.message,a.sentAt?` · ${T(a.sentAt)}`:""]})]})]})]},e.id)}),!C&&de.length===0&&t.jsx(L,{compact:!0,title:"暂无账号通知规则",description:"先创建并启用通知渠道,再为账号添加通知规则。",icon:ae})]})]}),r==="risk"&&t.jsxs("section",{className:"section-panel",children:[t.jsx($,{title:"发货风控日志",description:"查看发货前拦截、关单、补偿和异常处理结果。",icon:le}),t.jsx("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:U,onChange:e=>{Me(e.target.value),_(0)},className:"ios-input rounded-md px-3 py-2.5 text-sm sm:min-w-56",children:[t.jsx("option",{value:"",children:"全部账号"}),x.map(e=>t.jsx("option",{value:e.id,children:oe(e)},e.id))]}),t.jsxs("select",{value:Z,onChange:e=>{qe(e.target.value),_(0)},className:"ios-input rounded-md px-3 py-2.5 text-sm sm:min-w-40",children:[t.jsx("option",{value:"",children:"全部状态"}),t.jsx("option",{value:"processing",children:"处理中"}),t.jsx("option",{value:"success",children:"成功"}),t.jsx("option",{value:"failed",children:"失败"})]}),t.jsxs("button",{type:"button",onClick:()=>void Q(),disabled:J,className:"ios-btn-secondary flex items-center justify-center gap-2 rounded-md px-4 py-2.5 text-sm",children:[t.jsx(ee,{className:`h-4 w-4 ${J?"animate-spin":""}`}),"刷新"]})]})}),t.jsxs("div",{className:"divide-y divide-gray-100 px-4",children:[ge.map(e=>t.jsxs("div",{className:"grid gap-3 py-4 lg:grid-cols-[180px_120px_minmax(0,1fr)_44px] lg:items-start",children:[t.jsxs("div",{children:[t.jsx("p",{className:"break-all text-sm font-bold text-gray-900",children:e.cookie_id}),t.jsx("p",{className:"mt-1 text-xs text-gray-500",children:T(e.created_at)})]}),t.jsxs("div",{children:[t.jsx("span",{className:`inline-flex rounded px-2 py-1 text-xs font-bold ${e.processing_status==="success"?"bg-emerald-50 text-emerald-700":e.processing_status==="failed"?"bg-red-50 text-red-700":"bg-amber-50 text-amber-700"}`,children:e.processing_status==="success"?"成功":e.processing_status==="failed"?"失败":"处理中"}),t.jsx("p",{className:"mt-2 text-xs text-gray-500",children:e.event_type})]}),t.jsxs("div",{className:"min-w-0 text-sm leading-6 text-gray-700",children:[t.jsx("p",{children:e.event_description||e.processing_result||"无详细描述"}),e.processing_result&&e.event_description&&t.jsx("p",{className:"mt-1 text-xs text-gray-500",children:e.processing_result}),e.error_message&&t.jsx("p",{className:"mt-1 break-words text-xs text-red-600",children:e.error_message})]}),t.jsx("button",{type:"button",onClick:()=>void nt(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(ie,{className:"h-4 w-4"})})]},e.id)),!J&&ge.length===0&&t.jsx(L,{compact:!0,title:"没有符合条件的风控日志",description:"调整账号或状态筛选条件后重新查询。",icon:le})]}),t.jsxs("div",{className:"flex items-center justify-between border-t border-gray-200 px-4 py-3",children:[t.jsxs("p",{className:"text-xs text-gray-500",children:["共 ",fe," 条"]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{type:"button",onClick:()=>_(e=>Math.max(0,e-1)),disabled:w===0,title:"上一页",className:"flex h-9 w-9 items-center justify-center rounded-md bg-gray-100 disabled:opacity-40",children:t.jsx(Ct,{className:"h-4 w-4"})}),t.jsxs("span",{className:"min-w-20 text-center text-sm font-bold",children:[w+1," / ",V]}),t.jsx("button",{type:"button",onClick:()=>_(e=>Math.min(V-1,e+1)),disabled:w+1>=V,title:"下一页",className:"flex h-9 w-9 items-center justify-center rounded-md bg-gray-100 disabled:opacity-40",children:t.jsx(St,{className:"h-4 w-4"})})]})]})]}),r==="system"&&i&&t.jsxs("section",{className:"section-panel",children:[t.jsx($,{title:"系统运行日志",description:"最多读取最近 300 行,可按级别和来源快速定位运行异常。",icon:ne}),t.jsxs("div",{className:"grid gap-3 border-b border-gray-200 bg-gray-50/60 p-4 sm:grid-cols-[160px_minmax(0,1fr)_auto_auto]",children:[t.jsxs("select",{value:ve,onChange:e=>Ge(e.target.value),className:"ios-input rounded-md px-3 py-2.5 text-sm",children:[t.jsx("option",{value:"",children:"全部级别"}),t.jsx("option",{value:"DEBUG",children:"DEBUG"}),t.jsx("option",{value:"INFO",children:"INFO"}),t.jsx("option",{value:"WARNING",children:"WARNING"}),t.jsx("option",{value:"ERROR",children:"ERROR"})]}),t.jsx("input",{value:R,onChange:e=>we(e.target.value),placeholder:"按日志来源筛选",className:"ios-input rounded-md px-3 py-2.5 text-sm"}),t.jsx("button",{type:"button","aria-pressed":R==="logistics_quote",onClick:()=>we(e=>e==="logistics_quote"?"":"logistics_quote"),className:`rounded-md px-3 py-2.5 text-sm font-bold ${R==="logistics_quote"?"bg-[#ffe100] text-gray-900":"bg-white text-gray-700 ring-1 ring-gray-200 hover:bg-gray-100"}`,children:"物流报价"}),t.jsxs("button",{type:"button",onClick:()=>void Ce(),disabled:K,className:"ios-btn-secondary flex items-center justify-center gap-2 rounded-md px-4 py-2.5 text-sm",children:[t.jsx(ee,{className:`h-4 w-4 ${K?"animate-spin":""}`}),"查询"]})]}),t.jsxs("div",{className:"max-h-[620px] divide-y divide-gray-100 overflow-y-auto px-4 font-mono text-xs",children:[[...Ne].reverse().map((e,s)=>t.jsxs("div",{className:"grid gap-2 py-3 lg:grid-cols-[165px_80px_180px_minmax(0,1fr)]",children:[t.jsx("span",{className:"text-gray-500",children:T(e.timestamp)}),t.jsx("span",{className:`font-bold ${e.level==="ERROR"?"text-red-600":e.level==="WARNING"?"text-amber-700":"text-gray-700"}`,children:e.level}),t.jsx("span",{className:"truncate text-gray-500",title:e.source,children:e.source}),t.jsx("span",{className:"break-words text-gray-800",children:e.message})]},`${e.timestamp}-${s}`)),!K&&Ne.length===0&&t.jsx(L,{compact:!0,title:"暂无系统日志",description:"当前筛选条件没有返回运行记录。",icon:ne})]})]}),Pe&&t.jsx("div",{className:"modal-overlay",children:t.jsxs("div",{className:"modal-container max-w-xl",children:[t.jsxs("div",{className:"modal-header flex items-start justify-between gap-4",children:[t.jsxs("div",{children:[t.jsx("h3",{className:"text-lg font-bold text-gray-900",children:N?"编辑通知渠道":"新建通知渠道"}),t.jsx("p",{className:"mt-1 text-sm text-gray-500",children:"配置服务端发送通知所需的连接信息。"})]}),t.jsx("button",{type:"button",onClick:()=>j(!1),title:"关闭",className:"flex h-9 w-9 items-center justify-center rounded-md hover:bg-gray-100",children:t.jsx(Se,{className:"h-5 w-5"})})]}),t.jsxs("div",{className:"modal-body space-y-4",children:[t.jsxs("label",{className:"block text-sm font-bold text-gray-700",children:["渠道名称",t.jsx("input",{value:O,onChange:e=>I(e.target.value),placeholder:"例如:订单告警群",className:"ios-input mt-2 w-full rounded-md px-3 py-2.5 font-normal"})]}),t.jsxs("label",{className:"block text-sm font-bold text-gray-700",children:["渠道类型",t.jsx("select",{value:P,disabled:!!N,onChange:e=>He(e.target.value),className:"ios-input mt-2 w-full rounded-md px-3 py-2.5 font-normal disabled:bg-gray-100",children:Object.entries(y).map(([e,s])=>t.jsx("option",{value:e,children:s.label},e))})]}),y[P].fields.map(e=>{var s;return t.jsxs("label",{className:"block text-sm font-bold text-gray-700",children:[e.label,e.optional?"(可选)":"",e.type==="textarea"?t.jsx("textarea",{value:String(d[e.key]??""),onChange:a=>p({...d,[e.key]:a.target.value}),placeholder:e.placeholder,rows:4,className:"ios-input mt-2 w-full resize-y rounded-md px-3 py-2.5 font-mono text-sm font-normal"}):e.type==="select"?t.jsx("select",{value:String(d[e.key]??""),onChange:a=>p({...d,[e.key]:a.target.value}),className:"ios-input mt-2 w-full rounded-md px-3 py-2.5 font-normal",children:(s=e.options)==null?void 0:s.map(a=>t.jsx("option",{children:a},a))}):t.jsx("input",{type:e.type||"text",value:String(d[e.key]??""),onChange:a=>p({...d,[e.key]:e.type==="number"?Number(a.target.value):a.target.value}),placeholder:e.placeholder,className:"ios-input mt-2 w-full rounded-md px-3 py-2.5 font-normal"})]},e.key)})]}),t.jsxs("div",{className:"modal-footer flex justify-end gap-3",children:[t.jsx("button",{type:"button",onClick:()=>j(!1),className:"ios-btn-secondary rounded-md px-4 py-2.5 text-sm",children:"取消"}),t.jsxs("button",{type:"button",onClick:()=>void Ue(),disabled:ue,className:"ios-btn-primary flex items-center gap-2 rounded-md px-4 py-2.5 text-sm disabled:opacity-50",children:[ue?t.jsx(te,{className:"h-4 w-4 animate-spin"}):t.jsx(Le,{className:"h-4 w-4"}),"保存"]})]})]})}),Be&&t.jsx("div",{className:"modal-overlay",children:t.jsxs("div",{className:"modal-container max-w-2xl",children:[t.jsxs("div",{className:"modal-header flex items-start justify-between gap-4",children:[t.jsxs("div",{children:[t.jsx("h3",{className:"text-lg font-bold text-gray-900",children:v?"编辑通知规则":"新建通知规则"}),t.jsx("p",{className:"mt-1 text-sm text-gray-500",children:"选择这条规则要通知的内容,未勾选任何类型表示订阅全部事件。"})]}),t.jsx("button",{type:"button",onClick:()=>u(!1),title:"关闭",className:"flex h-9 w-9 items-center justify-center rounded-md hover:bg-gray-100",children:t.jsx(Se,{className:"h-5 w-5"})})]}),t.jsxs("div",{className:"modal-body space-y-4",children:[t.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[t.jsxs("label",{className:"block text-sm font-bold text-gray-700",children:["账号",t.jsxs("select",{value:M,disabled:!!v,onChange:e=>q(e.target.value),className:"ios-input mt-2 w-full rounded-md px-3 py-2.5 font-normal disabled:bg-gray-100",children:[t.jsx("option",{value:"",children:"选择账号"}),x.map(e=>t.jsx("option",{value:e.id,children:oe(e)},e.id))]})]}),t.jsxs("label",{className:"block text-sm font-bold text-gray-700",children:["通知渠道",t.jsxs("select",{value:W,disabled:!!v,onChange:e=>G(e.target.value),className:"ios-input mt-2 w-full rounded-md px-3 py-2.5 font-normal disabled:bg-gray-100",children:[t.jsx("option",{value:"",children:"选择已启用渠道"}),A.filter(e=>e.enabled).map(e=>t.jsx("option",{value:e.id,children:e.name},e.id))]})]})]}),t.jsxs("label",{className:"block text-sm font-bold text-gray-700",children:["规则名称(可选)",t.jsx("input",{value:z,onChange:e=>F(e.target.value),placeholder:"例如:仅关键提醒",className:"ios-input mt-2 w-full rounded-md px-3 py-2.5 font-normal"})]}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[t.jsx("span",{className:"text-sm font-bold text-gray-700",children:"通知内容"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("button",{type:"button",onClick:()=>X("all"),className:"rounded-md bg-gray-100 px-3 py-1.5 text-xs font-bold text-gray-700 hover:bg-gray-200",children:"全选"}),t.jsx("button",{type:"button",onClick:()=>X("critical"),className:"rounded-md bg-red-50 px-3 py-1.5 text-xs font-bold text-red-700 hover:bg-red-100",children:"仅关键"}),t.jsx("button",{type:"button",onClick:()=>X("none"),className:"rounded-md bg-gray-100 px-3 py-1.5 text-xs font-bold text-gray-700 hover:bg-gray-200",children:"清空"})]})]}),t.jsx("div",{className:"mt-3 space-y-3",children:Qe.map(e=>{const s=f.filter(n=>n.priority===e.id);if(s.length===0)return null;const a=e.id==="critical"?"text-red-700":e.id==="warning"?"text-amber-700":"text-gray-600";return t.jsxs("div",{children:[t.jsx("p",{className:`text-xs font-bold ${a}`,children:e.label}),t.jsx("div",{className:"mt-2 grid gap-2 sm:grid-cols-2",children:s.map(n=>{const c=H.includes(n.id);return t.jsxs("button",{type:"button",onClick:()=>et(n.id),className:`flex items-start gap-2 rounded-md border p-3 text-left transition-colors ${c?"border-[#ffe100] bg-[#fffbe6]":"border-gray-200 bg-white hover:bg-gray-50"}`,children:[t.jsx("span",{className:`mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded border ${c?"border-[#ffe100] bg-[#ffe100]":"border-gray-300 bg-white"}`,children:c&&t.jsx(_t,{className:"h-3 w-3 text-gray-900"})}),t.jsxs("span",{className:"min-w-0",children:[t.jsx("span",{className:"block text-sm font-bold text-gray-900",children:n.label}),t.jsx("span",{className:"mt-0.5 block text-xs text-gray-500",children:n.description})]})]},n.id)})})]},e.id)})}),t.jsx("p",{className:"mt-3 text-xs text-gray-500",children:"未勾选任何类型时接收全部事件;只想收关键提醒可点“仅关键”。"})]})]}),t.jsxs("div",{className:"modal-footer flex justify-end gap-3",children:[t.jsx("button",{type:"button",onClick:()=>u(!1),className:"ios-btn-secondary rounded-md px-4 py-2.5 text-sm",children:"取消"}),t.jsxs("button",{type:"button",onClick:()=>void tt(),disabled:be,className:"ios-btn-primary flex items-center gap-2 rounded-md px-4 py-2.5 text-sm disabled:opacity-50",children:[be?t.jsx(te,{className:"h-4 w-4 animate-spin"}):t.jsx(Le,{className:"h-4 w-4"}),"保存"]})]})]})})]})};export{Wt as default};
|