import{d as tt,W as ht,r as k,at as W,i as et,c as C,o as $,aq as at,w as h,f as _,e as y,a2 as J,a as U,$ as r,S as St,Y as Q,ax as bt,h as E,B as $t,g as V,t as x,b as z,a5 as j,au as H,D as wt,aD as xt,_ as Tt,aa as X,j as Bt,k as Dt}from"./index-DGnN4tUo.js";import{u as kt}from"./echarts-DpOKb1-q.js";import{_ as Ct}from"./Spin-DKKyX_Jk.js";import{_ as Ft}from"./Space-CL0I_Xfq.js";import{_ as Rt}from"./DatePicker-CdUKGL7B.js";import{_ as It}from"./ButtonGroup-YUQB397Z.js";import{N as Mt}from"./DataTable-srFNopw0.js";import"./installCanvasRenderer-DwMtZqT-.js";import"./get-slot-Bk_rJcZu.js";import"./Forward-CG86rsx9.js";import"./RadioGroup-CrfPAuhp.js";const Et="/assets/code-DgpOl68s.png",Z="/assets/intercept-Be3g9gqA.png",Nt="/assets/log-BGFSDP_V.png",Pt=tt({name:"LineChart",__name:"line-chart",props:{trafficStats:{}},setup(O,{expose:p}){const v=O,F=ht(),w=k(!1);function d(a){const l=["bps","Kbps","Mbps","Gbps","Tbps"];let i=a,s=0;for(;i>=1e3&&s<l.length-1;)i/=1e3,s++;return{value:i,unit:l[s]}}function R(a){if(!a.length)return"bps";let l=Math.max(...a.map(i=>i.bits||0));return d(l).unit}function S(a,l){switch(l){case"Kbps":return a/1e3;case"Mbps":return a/1e6;case"Gbps":return a/1e9;case"Tbps":return a/1e12;default:return a}}const{domRef:I,updateOptions:u}=kt(()=>{const a=[],l=R(a);return{tooltip:{trigger:"axis",axisPointer:{type:"cross",label:{backgroundColor:"#6a7985"}},formatter(i){if(!i.length)return"";const s=i[0].data;if(!s)return"";const m=S(s.bits,l);return`
          时间: ${s.time.replace(/^(\d{2})(\d{2})$/,"$1:$2")}<br/>
          流量: ${m.toFixed(2)} ${l}<br/>
          bytes: ${s.bytes}<br/>
          day: ${s.day.replace(/^(\d{4})(\d{2})(\d{2})$/,"$1-$2-$3")}<br/>
          gbps: ${s.gbps}<br/>
          mbps: ${s.mbps}<br/>
          值: ${s.value}
        `}},grid:{left:"3%",right:"4%",bottom:"3%",containLabel:!0},xAxis:{type:"category",boundaryGap:!1,data:[]},yAxis:{type:"value",axisLabel:{formatter:i=>`${S(i,l).toFixed(2)} ${l}`}},series:[{color:"#47CE40",name:"用量",type:"line",smooth:!0,stack:"Total",areaStyle:{color:{type:"linear",x:0,y:0,x2:0,y2:1,colorStops:[{offset:0,color:"#10D0AD"},{offset:1,color:"#fff"}]}},emphasis:{focus:"series"},data:a}]}});async function N(){await new Promise(a=>setTimeout(a,500)),u(a=>{const l=[],i=[];for(const m of v.trafficStats.bandwidthStats){const g=m.day.replace(/^(\d{4})(\d{2})(\d{2})$/,"$1-$2-$3"),B=m.time.replace(/^(\d{2})(\d{2})$/,"$1:$2"),P=m.time==="0000"?g:`${g} ${B}`;l.push(P),i.push({value:m.bits,...m})}const s=R(i);return a.xAxis.data=l,a.series[0].data=i,a.yAxis.axisLabel.formatter=m=>`${S(m,s).toFixed(2)} ${s}`,a.tooltip.formatter=m=>{if(!m.length)return"";const g=m[0].data;if(!g)return"";const B=S(g.bits,s);return`
        时间: ${g.time.replace(/^(\d{2})(\d{2})$/,"$1:$2")}<br/>
        流量: ${B.toFixed(2)} ${s}<br/>
        bytes: ${g.bytes}<br/>
        day: ${g.day.replace(/^(\d{4})(\d{2})(\d{2})$/,"$1-$2-$3")}<br/>
        gbps: ${g.gbps}<br/>
        mbps: ${g.mbps}<br/>
        值: ${g.value}
      `},a})}async function T(){w.value=!0;try{await N()}finally{w.value=!1}}return W(()=>v.trafficStats,()=>{T()},{deep:!0}),W(()=>F.locale,()=>{u((a,l)=>{const i=l();return a.series[0].name=i.series[0].name,a})}),et(()=>{T()}),p({showLoading:()=>{w.value=!0}}),(a,l)=>{const i=Ct,s=at;return $(),C(s,{bordered:!1,class:"card-wrapper"},{default:h(()=>[_(i,{show:w.value},{default:h(()=>[y("div",{ref_key:"domRef",ref:I,class:"h-360px overflow-hidden"},null,512)]),_:1},8,["show"])]),_:1})}}}),At={VITE_OTHER_SERVICE_BASE_URL:`{
  "demo": "/"
}`,VITE_SERVICE_BASE_URL:""},Lt={class:"grid grid-cols-1 gap-2 md:grid-cols-4 sm:grid-cols-3 md:gap-4"},Ut={class:"justify-start rounded-2xl text-sm font-medium font-['PingFang_SC']"},Vt={class:"flex items-center gap-2"},zt={class:"justify-start text-3xl font-medium leading-9 font-['Outfit']"},Gt={class:"justify-start text-sm font-normal font-['PingFang_SC']"},qt=["src"],jt={class:"flex items-center justify-center gap-2"},Ht=["href"],Ot={class:"flex gap-1 items-center justify-center text-green"},Yt=tt({name:"servers_traffic-stats",__name:"index",setup(O){const p=k({from:null,to:null}),v=k({serverId:0,regionId:0}),F=k("today"),w=k("chart"),d=J({regions:[],servers:[],trafficStats:{bandwidth95thBits:0,maxBandwidthBits:0,maxBandwidthTime:"",totalTrafficBytes:0,totalTrafficRequests:0,bandwidthStats:[]}}),R=k(),S=(t=0)=>{const e=new Date;return e.setDate(e.getDate()+t),e.setHours(0,0,0,0),e},I=t=>{const e=new Date(t);return e.setHours(23,59,59,999),e},u=new Date,N=S(0),T=I(N),a=S(-1),l=I(a),i=S(-6),s=S(-29),m=new Date(u.getFullYear(),u.getMonth(),1);m.setHours(0,0,0,0);const g=new Date(u.getFullYear(),u.getMonth()-1,1);g.setHours(0,0,0,0);const B=new Date(u.getFullYear(),u.getMonth(),0);B.setHours(23,59,59,999);const P=u.getDay()||7,st=S(-P),nt=S(-P-6),ot=U(()=>[{name:r("page.trafficStats.dayRanges.today"),code:"today",from:N.getTime(),to:T.getTime()},{name:r("page.trafficStats.dayRanges.yesterday"),code:"yesterday",from:a.getTime(),to:l.getTime()},{name:r("page.trafficStats.dayRanges.latest7days"),code:"latest7days",from:i.getTime(),to:T.getTime()},{name:r("page.trafficStats.dayRanges.lastWeek"),code:"lastWeek",from:nt.getTime(),to:I(st).getTime()},{name:r("page.trafficStats.dayRanges.latest30days"),code:"latest30days",from:s.getTime(),to:T.getTime()},{name:r("page.trafficStats.dayRanges.currentMonth"),code:"currentMonth",from:m.getTime(),to:T.getTime()},{name:r("page.trafficStats.dayRanges.lastMonth"),code:"lastMonth",from:g.getTime(),to:B.getTime()}]),D=t=>{const e=new Date(t),n=e.getFullYear(),c=String(e.getMonth()+1).padStart(2,"0"),f=String(e.getDate()).padStart(2,"0");return`${n}-${c}-${f}`},rt=t=>{const e=u.getFullYear(),n=String(u.getMonth()+1).padStart(2,"0"),c=String(u.getDate()).padStart(2,"0"),f=String(u.getHours()).padStart(2,"0"),b=String(u.getMinutes()).padStart(2,"0"),q=String(u.getSeconds()).padStart(2,"0");return`${e}-${n}-${c} ${f}:${b}:${q}`},A=(t,e=1024)=>{if(t===0||t==null)return["0","bps"];const n=["bps","Kbps","Mbps","Gbps","Tbps"];let c=0,f=t;for(;f>=e&&c<n.length-1;)f=f/e,c++;return[f.toFixed(4),n[c]]};function Y(t,e=2){if(t===0)return["0","B"];const n=1024,c=["B","KiB","MiB","GiB","TiB","PiB"];let f=0,b=t;for(;b>=n&&f<c.length-1;)b/=n,f++;return[b.toFixed(e),c[f]]}const K=t=>{if(t==null)return["0",""];if(t<1e3)return[t.toString(),""];const e=["","K","M","B","T"];let n=0,c=t;for(;c>=1e3&&n<e.length-1;)c=c/1e3,n++;return[c.toFixed(2),e[n]]},it=U(()=>[{title:r("page.trafficStats.bandwidthPeak"),value:A(d.trafficStats.maxBandwidthBits)[0],unit:A(d.trafficStats.maxBandwidthBits)[1],icon:Z},{title:r("page.trafficStats.bandwidth95th"),value:A(d.trafficStats.bandwidth95thBits)[0],unit:A(d.trafficStats.bandwidth95thBits)[1],icon:Et},{title:r("page.trafficStats.totalTraffic"),value:Y(d.trafficStats.totalTrafficBytes)[0],unit:Y(d.trafficStats.totalTrafficBytes)[1],icon:Nt},{title:r("page.trafficStats.totalRequests"),value:K(d.trafficStats.totalTrafficRequests)[0]+K(d.trafficStats.totalTrafficRequests)[1],unit:r("page.trafficStats.times"),icon:Z}]),lt=U(()=>[{title:r("page.trafficStats.tableChoose.chart"),value:"chart"},{title:r("page.trafficStats.tableChoose.form"),value:"form"}]),ct=U(()=>[{title:r("page.trafficStats.time"),key:"day",align:"center",render:t=>{const e=t.day.replace(/^(\d{4})(\d{2})(\d{2})$/,"$1-$2-$3"),n=t.time.replace(/^(\d{2})(\d{2})$/,"$1:$2");return`${e} ${n}`}},{title:r("page.trafficStats.bandwidthMbps"),key:"mbps",align:"center"},{title:r("page.trafficStats.bandwidthGbps"),key:"gbps",align:"center"}]),dt=async()=>{const{data:t,error:e}=await X({serverId:v.value.serverId,regionId:v.value.regionId,dayFrom:D(p.value.from),dayTo:D(p.value.to)},"/servers/traffic-stats/serverOptions");e||(d.servers=t.servers)},L=J({page:1,pageSize:100,pageSlot:4,showSizePicker:!0,pageSizes:[50,100],onChange:t=>{L.page=t},onUpdatePageSize:t=>{L.pageSize=t,L.page=1}}),G=async()=>{var n;(n=R.value)==null||n.showLoading();const{data:t,error:e}=await X({serverId:v.value.serverId,regionId:v.value.regionId,dayFrom:D(p.value.from),dayTo:D(p.value.to)},"/servers/traffic-stats");e||(d.trafficStats=t)},ut=t=>{F.value=t.code,p.value={from:t.from,to:t.to},G()},ft=async()=>{const{data:t,error:e}=await Bt("/servers/traffic-stats");e||(d.regions=t.regions)},pt=()=>{F.value=null,G()},mt=()=>{const t=Date.now();p.value.from=t,p.value.to=t,ft(),dt(),G()};et(()=>{mt()});const{baseURL:gt}=St(At);return(t,e)=>{const n=Rt,c=bt,f=$t,b=Ft,q=It,_t=Tt,vt=Mt,yt=at;return $(),C(b,{vertical:"",size:16},{default:h(()=>[_(yt,null,{default:h(()=>[_(b,{vertical:"",size:20},{default:h(()=>[_(b,null,{default:h(()=>[_(n,{value:p.value.from,"onUpdate:value":e[0]||(e[0]=o=>p.value.from=o),type:"date"},null,8,["value"]),_(n,{value:p.value.to,"onUpdate:value":e[1]||(e[1]=o=>p.value.to=o),type:"date"},null,8,["value"]),_(c,{value:v.value.serverId,"onUpdate:value":e[2]||(e[2]=o=>v.value.serverId=o),class:"min-w-[200px]",options:d.servers,"label-field":"name","value-field":"id"},null,8,["value","options"]),_(c,{value:v.value.regionId===0?`${E(r)("page.trafficStats.allRegions")}`:v.value.regionId,class:"min-w-[200px]",options:d.regions,"label-field":"name","value-field":"id",placeholder:E(r)("page.trafficStats.allRegions"),onChange:e[3]||(e[3]=o=>v.value.regionId=o)},null,8,["value","options","placeholder"]),_(f,{class:"button-default",onClick:pt},{default:h(()=>[V(x(E(r)("page.trafficStats.query")),1)]),_:1})]),_:1}),y("div",Lt,[($(!0),z(j,null,H(it.value,(o,M)=>($(),z("div",{key:M,class:"relative flex flex-col rounded-2xl from-[#F2F9FD] to-[#E3FCF5] bg-gradient-to-r p-4 dark:from-[#0D2B2B]/90 dark:to-[#1A3A3A]/90"},[y("div",Ut,x(o.title),1),y("div",Vt,[y("span",zt,x(o.value),1),y("div",Gt,x(o.unit),1)]),wt(y("div",null,x(rt()),513),[[xt,M===0]]),y("img",{src:o.icon,alt:"block",class:"absolute bottom-0 right-0 h-[80%] w-auto opacity-10"},null,8,qt)]))),128))]),_(b,{justify:"space-between"},{default:h(()=>[y("div",jt,[_(q,null,{default:h(()=>[($(!0),z(j,null,H(lt.value,o=>($(),C(f,{key:o.value,type:w.value===o.value?"primary":"default",onClick:M=>w.value=o.value},{default:h(()=>[V(x(o.title),1)]),_:2},1032,["type","onClick"]))),128))]),_:1}),y("a",{href:`${E(gt)}/servers/traffic-stats/download?dayFrom=${D(p.value.from)}&dayTo=${D(p.value.to)}&serverId=0`,download:""},[y("div",Ot,[V(x(E(r)("common.dow"))+" ",1),_(_t,{"local-icon":"material-symbols--download"})])],8,Ht)]),y("div",null,[_(b,{size:"small"},{default:h(()=>[($(!0),z(j,null,H(ot.value,(o,M)=>($(),C(f,{key:M,size:"small",type:F.value===o.code?"primary":"default",onClick:Kt=>ut(o)},{default:h(()=>[V(x(o.name),1)]),_:2},1032,["type","onClick"]))),128))]),_:1})])]),_:1}),w.value==="chart"?($(),C(Pt,{key:0,ref_key:"childRef",ref:R,"traffic-stats":d.trafficStats},null,8,["traffic-stats"])):Q("",!0),w.value==="form"?($(),C(vt,{key:1,data:d.trafficStats.bandwidthStats,columns:ct.value,pagination:L,"max-height":550},null,8,["data","columns","pagination"])):Q("",!0)]),_:1})]),_:1})]),_:1})}}}),re=Dt(Yt,[["__scopeId","data-v-b37b3e07"]]);export{re as default};
