2 lines
8.7 KiB
JavaScript
2 lines
8.7 KiB
JavaScript
import{r as c,j as e}from"./vendor-codemirror-C7mXSpXt.js";import{C as E,a as L}from"./card-B1TdHH8z.js";import{g as H,i as M,L as k,B as j}from"./index-BZzvNKfa.js";import{B as D}from"./badge-IN84WXM6.js";import{S as P,a as N,b as f,c as v,d as x}from"./select-BFGszUub.js";import{T as z,a as U,b as d,c as r,d as F,e as n}from"./table-CQE_AU2l.js";import{k as p}from"./index-DPhaKvWI.js";import{f as S,u as I,R as G,v as J,g as w,H as _}from"./vendor-icons-DIDdqO_o.js";import"./index-CYARH0Cq.js";function te(){const{clusterCode:$}=H(),h=M(),[l,u]=c.useState(!1),[b,g]=c.useState([]),[q,T]=c.useState([]),[A,R]=c.useState([]),[o,V]=c.useState("all"),[a,C]=c.useState($||"");c.useEffect(()=>{p.getClusters().then(s=>{const t=s?.list||[];if(T(t),!a&&t.length>0){const y=t[0].code||String(t[0].id);C(y),h(`/kubernetes/${y}/capacity`,{replace:!0})}}).catch(()=>{})},[]),c.useEffect(()=>{a&&p.getNamespaces(a).then(s=>{R(Array.isArray(s)?s:s?.list||s?.data||[])}).catch(()=>{})},[a]);const i=c.useCallback(async()=>{if(a){u(!0);try{const s=o==="all"?void 0:o,t=await p.getCapacity(a,s);g(Array.isArray(t)?t:t?.list||[])}catch{g([])}finally{u(!1)}}},[a,o]);c.useEffect(()=>{i()},[i]);const m=c.useMemo(()=>b.flatMap(s=>(s.containers||[]).map(t=>({namespace:s.namespace,deployment:s.name,replicas:s.replicas,container:t.name,cpu_req:t.cpu_request||"-",cpu_lim:t.cpu_limit||"-",mem_req:t.mem_request||"-",mem_lim:t.mem_limit||"-"}))),[b]),B=()=>p.exportAsCSV(`capacity-${a}.csv`,m);return e.jsxs("div",{"code-path":"src/components/kubernetes/CapacityPage.tsx:73:5",className:"space-y-4",children:[e.jsxs("div",{"code-path":"src/components/kubernetes/CapacityPage.tsx:74:7",className:"flex items-center gap-2 text-sm text-slate-500",children:[e.jsx(k,{"code-path":"src/components/kubernetes/CapacityPage.tsx:75:9",to:"/kubernetes",className:"hover:text-slate-300",children:"集群"}),a&&e.jsxs(e.Fragment,{children:[e.jsx(S,{"code-path":"src/components/kubernetes/CapacityPage.tsx:76:29",className:"h-3 w-3"}),e.jsx(k,{"code-path":"src/components/kubernetes/CapacityPage.tsx:76:65",to:`/kubernetes/${a}`,className:"hover:text-slate-300",children:a})]}),e.jsx(S,{"code-path":"src/components/kubernetes/CapacityPage.tsx:77:9",className:"h-3 w-3"}),e.jsx("span",{"code-path":"src/components/kubernetes/CapacityPage.tsx:77:45",className:"text-slate-300",children:"容量分析"})]}),e.jsxs("div",{"code-path":"src/components/kubernetes/CapacityPage.tsx:80:7",className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("h2",{"code-path":"src/components/kubernetes/CapacityPage.tsx:81:9",className:"text-lg font-semibold text-slate-100 flex items-center gap-2",children:[e.jsx(I,{"code-path":"src/components/kubernetes/CapacityPage.tsx:81:86",className:"h-5 w-5 text-purple-400"}),"资源容量分析"]}),e.jsxs("div",{"code-path":"src/components/kubernetes/CapacityPage.tsx:82:9",className:"flex items-center gap-2",children:[e.jsxs(P,{"code-path":"src/components/kubernetes/CapacityPage.tsx:83:11",value:a,onValueChange:s=>{C(s),h(`/kubernetes/${s}/capacity`)},children:[e.jsx(N,{"code-path":"src/components/kubernetes/CapacityPage.tsx:84:13",className:"w-40 h-8 text-xs bg-slate-800 border-slate-700",children:e.jsx(f,{"code-path":"src/components/kubernetes/CapacityPage.tsx:84:87"})}),e.jsx(v,{"code-path":"src/components/kubernetes/CapacityPage.tsx:85:13",className:"bg-slate-800 border-slate-700",children:q.map(s=>e.jsx(x,{"code-path":"src/components/kubernetes/CapacityPage.tsx:86:42",value:s.code||String(s.id),className:"text-xs",children:s.name||s.code},s.id))})]}),e.jsxs(P,{"code-path":"src/components/kubernetes/CapacityPage.tsx:89:11",value:o,onValueChange:V,children:[e.jsx(N,{"code-path":"src/components/kubernetes/CapacityPage.tsx:90:13",className:"w-32 h-8 text-xs bg-slate-800 border-slate-700",children:e.jsx(f,{"code-path":"src/components/kubernetes/CapacityPage.tsx:90:87",placeholder:"所有命名空间"})}),e.jsxs(v,{"code-path":"src/components/kubernetes/CapacityPage.tsx:91:13",className:"bg-slate-800 border-slate-700",children:[e.jsx(x,{"code-path":"src/components/kubernetes/CapacityPage.tsx:92:15",value:"all",className:"text-xs",children:"所有命名空间"}),A.map(s=>e.jsx(x,{"code-path":"src/components/kubernetes/CapacityPage.tsx:93:36",value:s,className:"text-xs",children:s},s))]})]}),e.jsxs(j,{"code-path":"src/components/kubernetes/CapacityPage.tsx:96:11",variant:"outline",size:"sm",className:"h-8 border-slate-700 text-slate-300 text-xs",onClick:i,disabled:l,children:[e.jsx(G,{"code-path":"src/components/kubernetes/CapacityPage.tsx:97:13",className:`h-3 w-3 mr-1 ${l?"animate-spin":""}`}),"刷新"]}),e.jsxs(j,{"code-path":"src/components/kubernetes/CapacityPage.tsx:99:11",variant:"outline",size:"sm",className:"h-8 border-slate-700 text-slate-300 text-xs",onClick:B,children:[e.jsx(J,{"code-path":"src/components/kubernetes/CapacityPage.tsx:100:13",className:"h-3 w-3 mr-1"}),"CSV"]})]})]}),e.jsx(E,{"code-path":"src/components/kubernetes/CapacityPage.tsx:105:7",className:"bg-slate-900 border-slate-800",children:e.jsx(L,{"code-path":"src/components/kubernetes/CapacityPage.tsx:106:9",className:"p-0",children:e.jsxs(z,{"code-path":"src/components/kubernetes/CapacityPage.tsx:107:11",children:[e.jsx(U,{"code-path":"src/components/kubernetes/CapacityPage.tsx:108:13",children:e.jsxs(d,{"code-path":"src/components/kubernetes/CapacityPage.tsx:108:26",className:"border-slate-800 hover:bg-transparent",children:[e.jsx(r,{"code-path":"src/components/kubernetes/CapacityPage.tsx:109:15",className:"text-slate-400",children:"Deployment"}),e.jsx(r,{"code-path":"src/components/kubernetes/CapacityPage.tsx:110:15",className:"text-slate-400",children:"命名空间"}),e.jsx(r,{"code-path":"src/components/kubernetes/CapacityPage.tsx:111:15",className:"text-slate-400",children:"副本"}),e.jsx(r,{"code-path":"src/components/kubernetes/CapacityPage.tsx:112:15",className:"text-slate-400",children:"容器"}),e.jsxs(r,{"code-path":"src/components/kubernetes/CapacityPage.tsx:113:15",className:"text-slate-400",children:[e.jsx(w,{"code-path":"src/components/kubernetes/CapacityPage.tsx:113:53",className:"h-3 w-3 inline mr-1"}),"CPU Req"]}),e.jsxs(r,{"code-path":"src/components/kubernetes/CapacityPage.tsx:114:15",className:"text-slate-400",children:[e.jsx(w,{"code-path":"src/components/kubernetes/CapacityPage.tsx:114:53",className:"h-3 w-3 inline mr-1"}),"CPU Lim"]}),e.jsxs(r,{"code-path":"src/components/kubernetes/CapacityPage.tsx:115:15",className:"text-slate-400",children:[e.jsx(_,{"code-path":"src/components/kubernetes/CapacityPage.tsx:115:53",className:"h-3 w-3 inline mr-1"}),"Mem Req"]}),e.jsxs(r,{"code-path":"src/components/kubernetes/CapacityPage.tsx:116:15",className:"text-slate-400",children:[e.jsx(_,{"code-path":"src/components/kubernetes/CapacityPage.tsx:116:53",className:"h-3 w-3 inline mr-1"}),"Mem Lim"]})]})}),e.jsx(F,{"code-path":"src/components/kubernetes/CapacityPage.tsx:118:13",children:m.length===0?e.jsx(d,{"code-path":"src/components/kubernetes/CapacityPage.tsx:120:17",children:e.jsxs(n,{"code-path":"src/components/kubernetes/CapacityPage.tsx:120:27",colSpan:8,className:"text-center text-slate-500 py-8",children:["暂无数据",l?e.jsx("span",{"code-path":"src/components/kubernetes/CapacityPage.tsx:120:109",className:"animate-spin inline-block ml-2",children:"⏳"}):""]})}):m.map((s,t)=>e.jsxs(d,{"code-path":"src/components/kubernetes/CapacityPage.tsx:122:17",className:"border-slate-800 hover:bg-slate-800/30",children:[e.jsx(n,{"code-path":"src/components/kubernetes/CapacityPage.tsx:123:19",className:"font-medium text-slate-200 text-sm",children:s.deployment}),e.jsx(n,{"code-path":"src/components/kubernetes/CapacityPage.tsx:124:19",children:e.jsx(D,{"code-path":"src/components/kubernetes/CapacityPage.tsx:124:30",variant:"outline",className:"border-slate-700 text-slate-400 text-xs",children:s.namespace})}),e.jsx(n,{"code-path":"src/components/kubernetes/CapacityPage.tsx:125:19",className:"text-sm text-slate-300",children:s.replicas}),e.jsx(n,{"code-path":"src/components/kubernetes/CapacityPage.tsx:126:19",className:"text-sm text-slate-400",children:s.container}),e.jsx(n,{"code-path":"src/components/kubernetes/CapacityPage.tsx:127:19",className:`text-sm ${s.cpu_req!=="-"?"text-blue-400":"text-slate-600"}`,children:s.cpu_req}),e.jsx(n,{"code-path":"src/components/kubernetes/CapacityPage.tsx:128:19",className:`text-sm ${s.cpu_lim!=="-"?"text-cyan-400":"text-slate-600"}`,children:s.cpu_lim}),e.jsx(n,{"code-path":"src/components/kubernetes/CapacityPage.tsx:129:19",className:`text-sm ${s.mem_req!=="-"?"text-emerald-400":"text-slate-600"}`,children:s.mem_req}),e.jsx(n,{"code-path":"src/components/kubernetes/CapacityPage.tsx:130:19",className:`text-sm ${s.mem_lim!=="-"?"text-teal-400":"text-slate-600"}`,children:s.mem_lim})]},`${s.deployment}-${s.container}-${t}`))})]})})})]})}export{te as default};
|