refactor(frontend): API 子模块化、大组件拆分与 TanStack Query hooks

P1: kubernetes/system API 拆为子目录模块,导出工具下沉到 lib/export-utils,
    http 统一 buildApiUrl/getWsBase;HostMonitor、DeploymentEdit* 拆至子组件。

P2: 新增 hooks/api(queryKeys、useTerminalSessions、useHostMonitor),
    TerminalSessionsTab 与 HostMonitor 接入 TanStack Query。

P3: 保留 services/api 路径,未迁移至 api/ 目录。
This commit is contained in:
Logan.Li committed 2026-06-26 00:02:29 +08:00
1 parent 7fb2236b4d
commit 0b404b4611
226 files changed
+3040 -2596

No files matched your search

@@ -0,0 +1,3 @@
import{i as ce,r as a,j as e,D as pe,a as xe,b as he,c as me,d as ue,L as ge,$ as _e,aH as Y,U as De,S as Re,C as Me,f as be,A as Te,a0 as ze,B as v,O as je,X as fe,aP as Ee,G as Ie,x as Be}from"./index-Dmami9WE.js";import{C as K,a as U}from"./card-CIfC-8Rh.js";import{I as F}from"./input-NsU9nXZF.js";import{B as _}from"./badge-3UzCvU7L.js";import{T as W,a as q,b as E,c as l,d as G,e as o}from"./table-CG4mjNfb.js";import{t as H,s as $e,a as X,l as Fe}from"./system-C3cYTuQH.js";import{x as Ae,a as ve}from"./xterm-DSqgeKvr.js";import{S as B}from"./search-Dd-PeBfg.js";import{R as J}from"./refresh-cw-CTBERyFc.js";import{P as Pe}from"./play-0EwQQJX_.js";import{D as Ne}from"./download-Vuij9wGr.js";const He=[["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"}]],Ke=ce("octagon-x",He);const Ue=[["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"}]],We=ce("timer-off",Ue);const qe=[["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"}]],Ge=ce("timer",qe);function Je({open:s,onOpenChange:i,sessionId:d}){const n=a.useRef(null),p=a.useRef(null),g=a.useRef(null),[m,w]=a.useState(!1),[b,N]=a.useState(""),[T,j]=a.useState(0);return a.useEffect(()=>{if(!s||!d)return;const r=new Ae.Terminal({cursorBlink:!1,fontSize:13,fontFamily:'Menlo, Monaco, "Courier New", monospace',disableStdin:!0,cols:80,rows:24,theme:{background:"#0a0e14",foreground:"#d6d6d6",cursor:"#0a0e14",selectionBackground:"rgba(255,255,255,0.2)"}}),u=new ve.FitAddon;r.loadAddon(u),p.current=r;let O=!1;return w(!0),N(""),j(0),H.getRecord(d).then(x=>{if(O)return;const y=typeof x=="string"?x:x?.data||x?.record_data||"";if(!y||y.trim()===""){N("No recording data available for this session"),w(!1);return}if(n.current){r.open(n.current);try{u.fit()}catch{}}const D=y.split(`
`).filter(L=>L.trim()),S=[];for(const L of D)try{const h=JSON.parse(L);Array.isArray(h)&&h.length>=3&&S.push({time:h[0],eventType:h[1],data:h[2]})}catch{}if(S.length===0){r.write(y),j(100),w(!1);return}w(!1);const P=S[S.length-1].time;let R=0,k=0;const C=()=>{if(O||R>=S.length){j(100);return}const L=S[R],h=(L.time-k)*1e3;k=L.time,R++;const f=Math.min(h,2e3);g.current=setTimeout(()=>{O||(r.write(L.data),j(Math.round(L.time/P*100)),C())},f)};C()}).catch(x=>{O||(console.error("[Replay] Load failed:",x),N("Failed to load recording data"),w(!1))}),()=>{O=!0,g.current&&clearTimeout(g.current);try{r.dispose()}catch{}p.current=null}},[s,d]),e.jsx(pe,{"code-path":"src/components/system/ReplayDialog.tsx:153:5",open:s,onOpenChange:i,children:e.jsxs(xe,{"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(he,{"code-path":"src/components/system/ReplayDialog.tsx:155:9",className:"px-4 py-3 border-b border-slate-800",children:[e.jsxs(me,{"code-path":"src/components/system/ReplayDialog.tsx:156:11",className:"text-slate-100 text-base flex items-center gap-2",children:["Terminal Replay #",d??"",T>0&&T<100&&e.jsxs("span",{"code-path":"src/components/system/ReplayDialog.tsx:159:15",className:"text-xs text-slate-500 font-normal ml-2",children:[T,"%"]})]}),e.jsx(ue,{"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:[m&&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(ge,{"code-path":"src/components/system/ReplayDialog.tsx:167:15",className:"h-6 w-6 animate-spin text-blue-400"})}),b&&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:b})}),T>0&&T<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:`${T}%`}})}),e.jsx("div",{"code-path":"src/components/system/ReplayDialog.tsx:183:11",ref:n,className:"absolute inset-0 p-1"})]})]})})}function Xe({open:s,onOpenChange:i,sessionId:d,sessionInfo:n}){const p=a.useRef(null),g=a.useRef(null),m=a.useRef(null),w=a.useRef(null),[b,N]=a.useState(!1),[T,j]=a.useState(""),[r,u]=a.useState(n||null);a.useEffect(()=>{s||(N(!1),j(""))},[s]),a.useEffect(()=>{if(!s||!d)return;N(!1),j("");const x=new Ae.Terminal({cursorBlink:!1,fontSize:13,fontFamily:'Menlo, Monaco, "Courier New", monospace',disableStdin:!0,theme:{background:"#0a0e14",foreground:"#d6d6d6",cursor:"#d6d6d6",selectionBackground:"#264f78",black:"#1a1a2e",red:"#ff6b6b",green:"#69db7c",yellow:"#ffd43b",blue:"#4dabf7",magenta:"#da77f2",cyan:"#63e6be",white:"#d6d6d6",brightBlack:"#4a4a4a",brightRed:"#ff8787",brightGreen:"#8ce99a",brightYellow:"#ffe066",brightBlue:"#74c0fc",brightMagenta:"#e599f7",brightCyan:"#7ae5d5",brightWhite:"#f8f9fa"}}),y=new ve.FitAddon;x.loadAddon(y),g.current=x,m.current=y;const D=()=>{const h=p.current;if(!h){requestAnimationFrame(D);return}x.open(h);try{y.fit()}catch{}},S=_e.getState().token||localStorage.getItem("token")||(()=>{try{return JSON.parse(localStorage.getItem("user-storage")||"{}")?.state?.token||""}catch{return""}})(),R=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws/audit/${d}?token=${encodeURIComponent(S)}`;console.log("[LiveMonitor] Connecting to:",R.replace(/token=[^&]+/,"token=***"));const k=new WebSocket(R);w.current=k;let C=!1;k.onopen=()=>{console.log("[LiveMonitor] WS connected for session:",d),C=!0,N(!0),j(""),D(),x.writeln("\x1B[36m[审计监控] 已连接到会话...\x1B[0m")},k.onmessage=h=>{try{const f=JSON.parse(h.data);switch(f.type){case"session_info":u(f.payload),x.writeln(`\x1B[36m用户: ${f.payload.username} 服务器: ${f.payload.server_name}\x1B[0m`);break;case"history":f.data&&x.write(f.data);break;case"output":f.data&&x.write(f.data);break}}catch{}},k.onerror=h=>{console.log("[LiveMonitor] WS error:",h),j("WebSocket 连接失败")},k.onclose=h=>{console.log("[LiveMonitor] WS closed code:",h.code,"reason:",h.reason),C||j(`连接失败 (code=${h.code}): ${h.reason||"认证失败或网络问题"}`),N(!1),x.writeln(`\r
\x1B[33m[审计监控] 连接已断开\x1B[0m`)};const L=setTimeout(()=>{C||(j("连接超时 — 请确认已登录且有活跃会话"),k.close())},5e3);return()=>{clearTimeout(L),k.close(),x.dispose(),g.current=null,m.current=null,w.current=null,N(!1)}},[s,d]),a.useEffect(()=>{if(!s)return;const x=p.current;if(!x)return;let y;const D=new ResizeObserver(()=>{clearTimeout(y),y=setTimeout(()=>{try{m.current?.fit()}catch{}},60)});return D.observe(x),()=>{clearTimeout(y),D.disconnect()}},[s,d]);const O=x=>x?new Date(x).toLocaleString():"--";return e.jsx(pe,{"code-path":"src/components/system/LiveMonitorDialog.tsx:223:5",open:s,onOpenChange:i,children:e.jsxs(xe,{"code-path":"src/components/system/LiveMonitorDialog.tsx:224:7",showOverlay:!1,className:"bg-[var(--dg-bg-secondary)] border-[var(--dg-border)] max-w-[95vw] max-h-[90vh] w-[1200px]",children:[e.jsxs(he,{"code-path":"src/components/system/LiveMonitorDialog.tsx:225:9",children:[e.jsxs(me,{"code-path":"src/components/system/LiveMonitorDialog.tsx:226:11",className:"text-[var(--dg-text-primary)] flex items-center gap-2",children:[e.jsx(Y,{"code-path":"src/components/system/LiveMonitorDialog.tsx:227:13",className:"h-5 w-5 text-emerald-400"}),"终端实时监控",b&&e.jsx(_,{"code-path":"src/components/system/LiveMonitorDialog.tsx:230:15",variant:"outline",className:"border-emerald-500/30 text-emerald-400 bg-emerald-500/10 ml-2 text-xs",children:"● 在线"}),!b&&!T&&e.jsxs(_,{"code-path":"src/components/system/LiveMonitorDialog.tsx:235:15",variant:"outline",className:"border-yellow-500/30 text-yellow-400 bg-yellow-500/10 ml-2 text-xs",children:[e.jsx(ge,{"code-path":"src/components/system/LiveMonitorDialog.tsx:236:17",className:"h-3 w-3 animate-spin mr-1"}),"连接中"]}),T&&e.jsx(_,{"code-path":"src/components/system/LiveMonitorDialog.tsx:241:15",variant:"outline",className:"border-red-500/30 text-red-400 bg-red-500/10 ml-2 text-xs",children:"连接失败"})]}),e.jsx(ue,{"code-path":"src/components/system/LiveMonitorDialog.tsx:246:11",className:"text-[var(--dg-text-secondary)]",children:r&&e.jsxs("div",{"code-path":"src/components/system/LiveMonitorDialog.tsx:248:15",className:"flex items-center gap-4 text-xs mt-1 flex-wrap",children:[e.jsxs("span",{"code-path":"src/components/system/LiveMonitorDialog.tsx:249:17",className:"flex items-center gap-1",children:[e.jsx(De,{"code-path":"src/components/system/LiveMonitorDialog.tsx:250:19",className:"h-3 w-3"}),r.username]}),e.jsxs("span",{"code-path":"src/components/system/LiveMonitorDialog.tsx:253:17",className:"flex items-center gap-1",children:[e.jsx(Re,{"code-path":"src/components/system/LiveMonitorDialog.tsx:254:19",className:"h-3 w-3"}),r.server_name," (",r.server_ip,")"]}),e.jsxs("span",{"code-path":"src/components/system/LiveMonitorDialog.tsx:257:17",className:"flex items-center gap-1",children:[e.jsx(Me,{"code-path":"src/components/system/LiveMonitorDialog.tsx:258:19",className:"h-3 w-3"}),O(r.start_time)]})]})})]}),T&&e.jsx("p",{"code-path":"src/components/system/LiveMonitorDialog.tsx:267:11",className:"text-sm text-red-400 px-1",children:T}),e.jsx("div",{"code-path":"src/components/system/LiveMonitorDialog.tsx:270:9",ref:p,className:"w-full rounded-md overflow-hidden border border-[var(--dg-border)]",style:{height:"55vh"}})]})})}function ye(s){if(!s||s<0)return"--";if(s<60)return`${s}秒`;const i=Math.floor(s/60),d=s%60;if(i<60)return`${i}分${d>0?`${d}秒`:""}`;const n=Math.floor(i/60),p=i%60;return`${n}时${p>0?`${p}分`:""}`}function Ve(s){return s?s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(1)} KB`:`${(s/1024/1024).toFixed(2)} MB`:"0 B"}function Le(s){return s==="active"?e.jsxs(_,{"code-path":"src/pages/TerminalAuditTab.tsx:86:7",variant:"outline",className:"border-emerald-500/30 text-emerald-400 bg-emerald-500/10",children:[e.jsx("span",{"code-path":"src/pages/TerminalAuditTab.tsx:87:9",className:"w-1.5 h-1.5 rounded-full bg-emerald-400 mr-1.5 inline-block animate-pulse"}),"活动中"]}):s==="failed"?e.jsx(_,{"code-path":"src/pages/TerminalAuditTab.tsx:94:7",variant:"outline",className:"border-red-500/30 text-red-400 bg-red-500/10",children:"失败"}):e.jsx(_,{"code-path":"src/pages/TerminalAuditTab.tsx:100:5",variant:"outline",className:"border-slate-500/30 text-slate-400 bg-slate-500/10",children:"已关闭"})}function Ye(s){const[i,d]=a.useState(0);return a.useEffect(()=>{if(!s)return;const n=new Date(s).getTime(),p=()=>d(Math.floor((Date.now()-n)/1e3));p();const g=setInterval(p,1e3);return()=>clearInterval(g)},[s]),i}const Qe=[{id:"active",name:"在线会话",icon:Te},{id:"history",name:"历史会话",icon:Y},{id:"commands",name:"会话命令",icon:B}];function de(){const s=be(),[i,d]=a.useState("active"),[n,p]=a.useState([]),[g,m]=a.useState(!0),[w,b]=a.useState(""),[N,T]=a.useState([]),[j,r]=a.useState(!0),[u,O]=a.useState(""),[x,y]=a.useState(null),[D,S]=a.useState(!1),[P,R]=a.useState([]),[k,C]=a.useState(!0),[L,h]=a.useState(""),[f,Q]=a.useState(""),[Z,c]=a.useState(!1),[M,ee]=a.useSta Line truncated