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 @@
import{i as os,aG as gs,r as i,j as t,L as ms,S as Y,B as A,aH as us,N as dt,I as bs,p as Ms,C as at,A as Wt,P as Hs,D as Kt,a as qt,b as Ut,c as Vt,d as Xt,e as Jt}from"./index-Dmami9WE.js";import{a as G}from"./agent-B3ElXCx8.js";import{C,a as S}from"./card-CIfC-8Rh.js";import{S as Qt,a as Yt,b as Zt,c as ts,d as rt}from"./select-DUbxjT0z.js";import{T as js,a as vs,b as fs,c as z}from"./tabs-lV44z_UR.js";import{B as Z}from"./badge-3UzCvU7L.js";import{H as W}from"./hard-drive-DmC04Y5r.js";import{D as mt}from"./disc-BPxL4arn.js";import{C as ut}from"./circle-x-BBQeW1R3.js";import{R as Mt,C as Ht,X as jt,Y as vt,T as ft,q as as}from"./generateCategoricalChart-ZqCvxO-S.js";import{A as Nt,a as it}from"./AreaChart-CrvX3B0s.js";import{R as ss}from"./refresh-cw-CTBERyFc.js";import{P as Ns}from"./plus-O65gX7Qz.js";import{S as _s}from"./square-pen-B3dPIBrm.js";import{T as ys}from"./trash-2-DWVnIU6o.js";import"./index-CtCQcvyh.js";import"./chevron-up-Cq4GPopa.js";const ws=[["path",{d:"M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5",key:"mvr1a0"}],["path",{d:"M3.22 13H9.5l.5-1 2 4.5 2-7 1.5 3.5h5.27",key:"auskq0"}]],ks=os("heart-pulse",ws);const Cs=[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]],es=os("list",Cs),bt=[{label:"1小时",hours:1,window:60,buckets:60},{label:"6小时",hours:6,window:300,buckets:72},{label:"12小时",hours:12,window:600,buckets:72},{label:"1天",hours:24,window:1800,buckets:96},{label:"3天",hours:72,window:3600,buckets:72},{label:"7天",hours:168,window:10800,buckets:56},{label:"14天",hours:336,window:21600,buckets:48}];function u(r,T,O){if(!r||r.length===0)return[];const F=Math.max(1,Math.ceil(r.length/O)),d=[];for(let j=0;j<r.length;j+=F){const y=r.slice(j,j+F),w=T.slice(j,j+F),v=y.reduce((nt,K)=>nt+K,0)/y.length,f=Math.max(...y),R=Math.min(...y),n=w[Math.floor(w.length/2)]||0;d.push({time:new Date(n*1e3).toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}),timestamp:n,avg:Number(v.toFixed(2)),max:Number(f.toFixed(2)),min:Number(R.toFixed(2)),count:y.length})}return d.slice(-O)}function M(r){if(!r)return{};if(typeof r=="object")return r;try{return JSON.parse(r)}catch{return{}}}function ct(r){return r>=1024*1024*1024?`${(r/1024/1024/1024).toFixed(1)} GB/s`:r>=1024*1024?`${(r/1024/1024).toFixed(1)} MB/s`:r>=1024?`${(r/1024).toFixed(1)} KB/s`:`${r.toFixed(1)} B/s`}function Us(){const[r]=gs(),T=r.get("host")||"",[O,F]=i.useState([]),[d,j]=i.useState(T),[y,w]=i.useState(!0),[P,v]=i.useState("basic"),[f,R]=i.useState(1),[n,nt]=i.useState("avg"),[K,_t]=i.useState([]),[o,yt]=i.useState(null),[b,rs]=i.useState(null),[wt,tt]=i.useState([]),[cs,q]=i.useState(!1),[U,kt]=i.useState(null),[a,N]=i.useState({name:"",hostname:"",probe_type:"http_get",http_url:"",http_method:"GET",http_expect_code:200,http_expect_body:"",tcp_host:"",tcp_port:3306,exec_command:"",timeout:10,interval:60,description:""}),V=i.useCallback(()=>{d&&G.getHealthProbes({hostname:d}).then(s=>{Array.isArray(s)?tt(s):s?.list?tt(s.list):tt([])}).catch(()=>tt([]))},[d]),[k,xt]=i.useState("whitelist"),[X,Ct]=i.useState([]),[ds,st]=i.useState(!1),[St,Tt]=i.useState(!1),pt=i.useCallback(()=>{d&&G.getPortPolicy(d).then(s=>{s?.data&&(xt(s.data.port_filter_mode||"blacklist"),Ct(s.data.port_whitelist||[]))}).catch(()=>{})},[d]);i.useEffect(()=>{pt()},[pt]);const is=async()=>{if(d){Tt(!0);try{await G.savePortPolicy(d,{port_filter_mode:k,port_whitelist:X}),st(!1)}catch{}finally{Tt(!1)}}};i.useEffect(()=>{V()},[V]);const h=bt.find(s=>s.hours===f)||bt[0];i.useEffect(()=>{G.getLatest().then(s=>{const e=Array.isArray(s)?s:s?.data||s?.list||[];if(F(e),e.length>0&&!d){const l=T?e.find(E=>E.hostname===T):null;j(l?.hostname||e[0]?.hostname||"")}const c=e.find(l=>l.hostname===(d||T));c&&(yt(c),rs(c))}).catch(()=>{}).finally(()=>w(!1))},[d]),i.useEffect(()=>{d&&G.getHistory(d,f).then(s=>{const e=Array.isArray(s)?s:s?.data||s?.list||[];if(_t(e),e.length>0){const c=e[e.length-1];yt(l=>({...l,...c}))}}).catch(()=>_t([])).finally(()=>w(!1))},[d,f]);const g=i.useMemo(()=>{const s=[],e=[],c=[],l=[],E=[],et=[],B=[],$t=[],At=[],Ft=[],It=[],Dt=[],Et=[],Bt=[],Ot=[],Gt=[],Rt=[],zt=[],Lt=[],ht=[],m=[];for(const x of K){const ns=x.report_time?new Date(x.report_time).getTime()/1e3:x.created_at?new Date(x.created_at).getTime()/1e3:0;m.push(ns),s.push(x.cpu_usage||0),Bt.push(x.cpu_iowait||0),e.push(x.mem_usage||0),Ot.push(x.mem_available||0),c.push(x.load1||0),l.push(x.disk_usage||0);const ot=M(x.disk_info);if(Array.isArray(ot)&&ot.length>0){const ls=ot.find(hs=>hs.mount==="/")||ot[0];ht.push(ls?.inode_usage_pct||0)}else ht.push(0);const $=M(x.net_info);E.push($.tcp_established||0),et.push($.tcp_time_wait||0),B.push($.tcp_close_wait||0),Rt.push(($.tcp_established||0)+($.tcp_time_wait||0)Line truncated