refactor(frontend): P1-P2 架构统一 — utils/hooks/api 模块化
P1: - utils/storage.ts、theme.ts、validate.ts + index 统一出口 - request/store/useTheme 接入 storage;清零 confirm/alert - PipelineManager、TerminalAuditTab 拆分子模块(<700行红线) P2: - api/monitor、api/deploy 子目录化 - hooks/api 扩展:servers/pipelines/alerts/audit/sessionCommands - PipelineManager、AuditOperationsTab 接入 TanStack Query
This commit is contained in:
1 parent
d19a03d427
commit
f45e203e21
196 files changed
+3228
-2018
No files matched your search
@@ -0,0 +1,3 @@
|
||||
import{i as V,r as a,a3 as ve,j as e,D as ae,a as re,a0 as ie,c as ne,d as oe,aW as Q,L as ce,X as Y,ac as fe,f as le,B as N,A as de,P as pe,b as ye,be as Ne,G as Se,y as Ae}from"./index-HuRw9UhJ.js";import{C as $,a as B}from"./card-B2Wqa0sK.js";import{I as F}from"./input-C9Xfv8um.js";import{T as E,a as q,b as _,c as d,d as K,e as p}from"./table-Du1vU-OM.js";import{x as xe,a as me}from"./xterm-DSqgeKvr.js";import{B as w}from"./badge-CeS-g-Od.js";import{m as Te,a as Le}from"./xterm-utils-slbfdUHf.js";import{M as we,a as Pe}from"./minimize-2-UErWMOt6.js";import{u as Z,q as ee,a as se,b as Oe}from"./unwrap-s5xDIyKq.js";import{u as X}from"./useMutation-ChnF9A9K.js";import{t as I,a as J,s as Ce,l as ke}from"./terminal-DvxWm4UP.js";import{S as z}from"./search-CcKEpJIn.js";import{R as W}from"./refresh-cw-CSycAyA2.js";import{P as _e}from"./play-BXdOitsb.js";import{D as he}from"./download-CjFatm64.js";const De=[["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"M2.586 16.726A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2h6.624a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586z",key:"2d38gg"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],He=V("octagon-x",De);const Me=[["path",{d:"M10 2h4",key:"n1abiw"}],["path",{d:"M4.6 11a8 8 0 0 0 1.7 8.7 8 8 0 0 0 8.7 1.7",key:"10he05"}],["path",{d:"M7.4 7.4a8 8 0 0 1 10.3 1 8 8 0 0 1 .9 10.2",key:"15f7sh"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M12 12v-2",key:"fwoke6"}]],Re=V("timer-off",Me);const ze=[["line",{x1:"10",x2:"14",y1:"2",y2:"2",key:"14vaq8"}],["line",{x1:"12",x2:"15",y1:"14",y2:"11",key:"17fdiu"}],["circle",{cx:"12",cy:"14",r:"8",key:"1e1u0o"}]],Ie=V("timer",ze);function Fe({open:s,onOpenChange:r,sessionId:i,sessionInfo:c}){const n=a.useRef(null),x=a.useRef(null),g=a.useRef(null),j=a.useRef(null),[v,l]=a.useState(!1),[u,f]=a.useState(""),[t,h]=a.useState(c||null),[y,T]=a.useState(!1);a.useEffect(()=>{s||(l(!1),f(""),T(!1))},[s]),a.useEffect(()=>{if(!s||!i)return;l(!1),f("");const b=new xe.Terminal({cursorBlink:!1,fontSize:13,fontFamily:'Menlo, Monaco, "Courier New", monospace',disableStdin:!0,allowProposedApi:!0,scrollback:5e3,theme:{background:"#0a0e14",foreground:"#d6d6d6",cursor:"#d6d6d6",selectionBackground:"rgba(255,255,255,0.2)"}}),m=new me.FitAddon;b.loadAddon(m),x.current=b,g.current=m;const S=ve.getState().token||localStorage.getItem("token")||(()=>{try{return JSON.parse(localStorage.getItem("user-storage")||"{}")?.state?.token||""}catch{return""}})(),H=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws/audit/${i}?token=${encodeURIComponent(S)}`,L=new WebSocket(H);j.current=L;let A=!1;L.onopen=()=>{A=!0,l(!0),f(""),Te(b,m,()=>n.current),b.writeln("\x1B[36m[审计监控] 已连接到会话...\x1B[0m")},L.onmessage=M=>{try{const C=JSON.parse(M.data);switch(C.type){case"session_info":h(C.payload),b.writeln(`\x1B[36m用户: ${C.payload.username} 服务器: ${C.payload.server_name} (${C.payload.server_ip})\x1B[0m`);break;case"history":C.data&&b.write(C.data);break;case"output":C.data&&b.write(C.data);break}}catch{}},L.onerror=()=>f("WebSocket 连接失败"),L.onclose=M=>{A||f(`连接失败 (code=${M.code}): ${M.reason||"认证失败或网络问题"}`),l(!1),b.writeln(`\r
|
||||
\x1B[33m[审计监控] 连接已断开\x1B[0m`)};const P=setTimeout(()=>{A||(f("连接超时 — 请确认已登录且有活跃会话"),L.close())},5e3);return()=>{clearTimeout(P),L.close(),b.dispose(),x.current=null,g.current=null,j.current=null,l(!1)}},[s,i]),a.useEffect(()=>{if(!s)return;let b,m=0;const S=()=>{const D=n.current,H=g.current,L=x.current;if(!D||!H||!L){m++<30&&requestAnimationFrame(S);return}b=Le(D,H,L)};return S(),()=>b?.()},[s,i,y]);const O=b=>b?new Date(b).toLocaleString():"--";return e.jsx(ae,{"code-path":"src/components/system/LiveMonitorDialog.tsx:180:5",open:s,onOpenChange:r,children:e.jsxs(re,{"code-path":"src/components/system/LiveMonitorDialog.tsx:181:7",showCloseButton:!1,showOverlay:!1,className:ie("bg-[var(--dg-bg-secondary)] border-[var(--dg-border)] p-0 gap-0","!duration-0 !transition-none",y?"!max-w-none !w-screen !h-screen !rounded-none !translate-x-0 !translate-y-0 !left-0 !top-0":""),style:y?{maxWidth:"100vw",width:"100vw",height:"100vh"}:{maxWidth:"960px",width:"92vw"},children:[e.jsx(ne,{"code-path":"src/components/system/LiveMonitorDialog.tsx:197:9",className:"sr-only",children:"终端实时监控"}),e.jsx(oe,{"code-path":"src/components/system/LiveMonitorDialog.tsx:198:9",className:"sr-only",children:"审计在线 WebSSH 会话"}),e.jsxs("div",{"code-path":"src/components/system/LiveMonitorDialog.tsx:201:9",className:"flex items-center justify-between px-4 py-2 border-b border-[var(--dg-border)]",children:[e.jsxs("div",{"code-path":"src/components/system/LiveMonitorDialog.tsx:202:11",className:"flex items-center gap-2 text-sm min-w-0 flex-wrap",children:[e.jsx(Q,{"code-path":"src/components/system/LiveMonitorDialog.tsx:203:13",className:"h-4 w-4 text-emerald-400 shrink-0"}),e.jsx("span",{"code-path":"src/components/system/LiveMonitorDialog.tsx:204:13",className:"text-[var(--dg-text-primary)] font-medium",children:"终端实时监控"}),t&&e.jsxs("span",{"code-path":"src/components/system/LiveMonitorDialog.tsx:206:15",className:"text-[var(--dg-text-muted)] truncate",children:[t.username," · ",t.server_name," (",t.server_ip,") · ",O(t.start_time)]}),v&&e.jsx(w,{"code-path":"src/components/system/LiveMonitorDialog.tsx:211:15",variant:"outline",className:"border-emerald-500/30 text-emerald-400 bg-emerald-500/10 text-xs",children:"● 在线"}),!v&&!u&&e.jsxs(w,{"code-path":"src/components/system/LiveMonitorDialog.tsx:216:15",variant:"outline",className:"border-yellow-500/30 text-yellow-400 bg-yellow-500/10 text-xs",children:[e.jsx(ce,{"code-path":"src/components/system/LiveMonitorDialog.tsx:217:17",className:"h-3 w-3 animate-spin mr-1"}),"连接中"]}),u&&e.jsx(w,{"code-path":"src/components/system/LiveMonitorDialog.tsx:222:15",variant:"outline",className:"border-red-500/30 text-red-400 bg-red-500/10 text-xs",children:"连接失败"})]}),e.jsxs("div",{"code-path":"src/components/system/LiveMonitorDialog.tsx:227:11",className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{"code-path":"src/components/system/LiveMonitorDialog.tsx:228:13",type:"button",onClick:()=>T(!y),className:"p-1.5 rounded hover:bg-[var(--dg-bg-hover)] text-[var(--dg-text-secondary)]",title:y?"退出全屏":"全屏",children:y?e.jsx(we,{"code-path":"src/components/system/LiveMonitorDialog.tsx:234:29",className:"h-4 w-4"}):e.jsx(Pe,{"code-path":"src/components/system/LiveMonitorDialog.tsx:234:65",className:"h-4 w-4"})}),e.jsx("button",{"code-path":"src/components/system/LiveMonitorDialog.tsx:236:13",type:"button",onClick:()=>r(!1),className:"p-1.5 rounded hover:bg-[var(--dg-bg-hover)] text-[var(--dg-text-secondary)]",children:e.jsx(Y,{"code-path":"src/components/system/LiveMonitorDialog.tsx:241:15",className:"h-4 w-4"})})]})]}),u&&e.jsx("p",{"code-path":"src/components/system/LiveMonitorDialog.tsx:247:11",className:"text-sm text-red-400 px-4 py-2 border-b border-[var(--dg-border)]",children:u}),e.jsx("div",{"code-path":"src/components/system/LiveMonitorDialog.tsx:250:9",ref:n,className:"xterm-terminal-host",style:{height:y?"calc(100vh - 49px)":"520px"}})]})})}function ue(s={page:1,page_size:100}){return Z({queryKey:ee.terminalSessions(s),queryFn:async()=>{const r=await I.list(s);return se(r)}})}function $e(){const s=fe(),r=()=>s.invalidateQueries({queryKey:["terminal-sessions"]}),i=X({mutationFn:x=>I.kill(x),onSuccess:r}),c=X({mutationFn:x=>I.delete(x),onSuccess:r}),n=X({mutationFn:x=>I.batchDelete(x),onSuccess:r});return{killMutation:i,deleteMutation:c,batchDeleteMutation:n,invalidate:r}}function Be(s={page:1,page_size:50}){return Z({queryKey:ee.auditLogs(s),queryFn:async()=>{const r=await J.getLogs(s);return{list:se(r),total:Oe(r)}},staleTime:2e4})}function Ee(s={page:1,page_size:200}){return Z({queryKey:ee.sessionCommands(s),queryFn:async()=>{const r=await Ce.list(s);return se(r)}})}function ge(s){if(!s||s<0)return"--";if(s<60)return`${s}秒`;const r=Math.floor(s/60),i=s%60;if(r<60)return`${r}分${i>0?`${i}秒`:""}`;const c=Math.floor(r/60),n=r%60;return`${c}时${n>0?`${n}分`:""}`}fun
Line truncated
|
||||
`).filter(A=>A.trim()),m=[];for(const A of b)try{const P=JSON.parse(A);Array.isArray(P)&&P.length>=3&&m.push({time:P[0],eventType:P[1],data:P[2]})}catch{}if(m.length===0){t.write(O),f(100),j(!1);return}j(!1);const S=m[m.length-1].time;let D=0,H=0;const L=()=>{if(y||D>=m.length){f(100);return}const A=m[D],P=(A.time-H)*1e3;H=A.time,D++;const M=Math.min(P,2e3);x.current=setTimeout(()=>{y||(t.write(A.data),f(Math.round(A.time/S*100)),L())},M)};L()}).catch(T=>{y||(console.error("[Replay] Load failed:",T),l("Failed to load recording data"),j(!1))}),()=>{y=!0,x.current&&clearTimeout(x.current);try{t.dispose()}catch{}n.current=null}},[s,i]),e.jsx(ae,{"code-path":"src/components/system/ReplayDialog.tsx:153:5",open:s,onOpenChange:r,children:e.jsxs(re,{"code-path":"src/components/system/ReplayDialog.tsx:154:7",showOverlay:!1,className:"bg-slate-900 border-slate-800 p-0 gap-0",style:{maxWidth:"900px",width:"90vw"},children:[e.jsxs(ye,{"code-path":"src/components/system/ReplayDialog.tsx:155:9",className:"px-4 py-3 border-b border-slate-800",children:[e.jsxs(ne,{"code-path":"src/components/system/ReplayDialog.tsx:156:11",className:"text-slate-100 text-base flex items-center gap-2",children:["Terminal Replay #",i??"",u>0&&u<100&&e.jsxs("span",{"code-path":"src/components/system/ReplayDialog.tsx:159:15",className:"text-xs text-slate-500 font-normal ml-2",children:[u,"%"]})]}),e.jsx(oe,{"code-path":"src/components/system/ReplayDialog.tsx:162:11",className:"text-slate-500 sr-only",children:"Replay recorded terminal output"})]}),e.jsxs("div",{"code-path":"src/components/system/ReplayDialog.tsx:164:9",className:"relative bg-[#0a0e14]",style:{height:"460px"},children:[g&&e.jsx("div",{"code-path":"src/components/system/ReplayDialog.tsx:166:13",className:"absolute inset-0 z-10 flex items-center justify-center bg-black/40",children:e.jsx(ce,{"code-path":"src/components/system/ReplayDialog.tsx:167:15",className:"h-6 w-6 animate-spin text-blue-400"})}),v&&e.jsx("div",{"code-path":"src/components/system/ReplayDialog.tsx:171:13",className:"absolute inset-0 z-10 flex items-center justify-center bg-black/40",children:e.jsx("p",{"code-path":"src/components/system/ReplayDialog.tsx:172:15",className:"text-red-400 text-sm",children:v})}),u>0&&u<100&&e.jsx("div",{"code-path":"src/components/system/ReplayDialog.tsx:176:13",className:"absolute bottom-0 left-0 right-0 h-0.5 bg-slate-800 z-10",children:e.jsx("div",{"code-path":"src/components/system/ReplayDialog.tsx:177:15",className:"h-full bg-blue-500 transition-all duration-300",style:{width:`${u}%`}})}),e.jsx("div",{"code-path":"src/components/system/ReplayDialog.tsx:183:11",ref:c,className:"absolute inset-0 p-1"})]})]})})}function Qe(){const{data:s=[],isLoading:r,refetch:i}=ue({page:1,page_size:100,status:"closed"}),[c,n]=a.useState(""),[x,g]=a.useState(null),[j,v]=a.useState(!1),l=s.filter(t=>{const h=c.toLowerCase();return!h||(t.username||"").toLowerCase().includes(h)||(t.server_name||"").toLowerCase().includes(h)||(t.server_ip||"").toLowerCase().includes(h)}),u=t=>{g(t),v(!0)},f=async t=>{try{await I.download(t)}catch{}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{"code-path":"src/pages/terminal-audit/HistorySessionsPanel.tsx:57:7",className:"flex items-center gap-3 flex-wrap",children:[e.jsxs("div",{"code-path":"src/pages/terminal-audit/HistorySessionsPanel.tsx:58:9",className:"relative w-64",children:[e.jsx(z,{"code-path":"src/pages/terminal-audit/HistorySessionsPanel.tsx:59:11",className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-500"}),e.jsx(F,{"code-path":"src/pages/terminal-audit/HistorySessionsPanel.tsx:60:11",placeholder:"搜索用户/服务器/IP...",value:c,onChange:t=>n(t.target.value),className:"pl-9 h-9 bg-slate-800/50 border-slate-700 text-slate-200 placeholder:text-slate-500"})]}),e.jsxs(N,{"code-path":"src/pages/terminal-audit/HistorySessionsPanel.tsx:67:9",variant:"outline",className:"border-slate-700 text-slate-300 hover:text-slate-100 hover:bg-slate-800",onClick:()=>i(),children:[e.jsx(W,{"code-path":"src/pages/terminal-audit/HistorySessionsPanel.tsx:72:11",className:"h-4 w-4 mr-2"}),"刷新"]})]}),e.jsx($,{"code-path":"src/pages/terminal-audit/HistorySessionsPanel.tsx:77:7",className:"bg-slate-900 border-slate-800",children:e.jsx(B,{"code-path":"src/pages/terminal-audit/HistorySessionsPanel.tsx:78:9",className:"p-0",children:e.jsx("div",{"code-path":"src/pages/terminal-audit/HistorySessionsPanel.tsx:79:11",className:"border-t border-slate-800",children:r?e.jsx("div",{"code-path":"src/pages/terminal-audit/HistorySessionsPanel.tsx:81:15",className:"flex items-center justify-center py-16",children:e.jsx("div",{"code-path":"src/pages/terminal-audit/HistorySessionsPanel.tsx:82:17",className:"w-8 h-8 border-2 border-blue-500 border-t-transparent rounded-full animate-spin"})}):l.length===0?e.jsxs("div",{"code-path":"src/pages/terminal-audit/HistorySessionsPanel.tsx:85:15",className:"flex flex-col items-center justify-center py-16 text-slate-500",chil
Line truncated
|
||||
Reference in new issue
Block a user