import{_ as R,i as P,r as g,q as M,$ as V,s as q,c as C,d as h,h as y,f as v,e as n,w as _,t as c,g as p,j as b,F as G,bm as K,bn as T,K as z,bo as D}from"./index-ojdwC1S2.js";import"./index-SLHq6L4P.js";import{B as E}from"./index-CQpN59BC.js";import{C as j}from"./index-CwrlpCyS.js";const A={key:0,class:"wrapper"},$={class:"circle-text"},H={class:"line1"},J={class:"line2"},L={class:"text"},O={key:1,class:"wrapper"},Q={class:"circle-text"},W={class:"line1"},X={class:"line2"},Y={class:"text"},Z={key:2,class:"wrapper-cleaning"},ee=["src"],ae={__name:"index",setup(se){const o=P.global.t,f=g(0),x={"25.93%":"#42C652","68.43%":"#FFD412","82.74%":"#FF6912"},F={"0%":"#46A2FF","100%":"#12F3FF"},e=M({useSpace:0,originUseSpace:0,totalSpace:0,releasedSpace:0,status:"idle",process:0,spaceRate:0}),t=g(null),r=g(null),d=g(0),w=async()=>{t.value&&(clearInterval(t.value),t.value=null);try{e.originUseSpace=e.useSpace;const{code:s,data:a}=await D();if(s===200){if(e.status=a==null?void 0:a.status,e.status!=="running")return}else{e.status="failed";return}t.value=setInterval(()=>{I()},2e3)}catch(s){console.error("清理接口调用失败",s),e.status="failed",clearInterval(t.value)}},S=s=>{const a=Number(s);return isNaN(a)||a<0?0:(a/1024).toFixed(1)},N=(s,a)=>{if(a<=0){e.process=0,clearInterval(r.value);return}switch(s){case"cleaning":clearInterval(r.value),d.value=e.process||0,r.value=setInterval(()=>{const u=Math.random()*2+1;d.value+=u,d.value>=98&&(d.value=98),e.process=Number(d.value.toFixed(1))},500);break;case"success":clearInterval(r.value),e.process=100;break;case"idle":case"failed":clearInterval(r.value),e.process=0,d.value=0;break;default:e.process=0;break}},I=async(s=!0)=>{try{const a=[K().catch(l=>({err:l,code:-1}))];s&&a.push(T().catch(l=>({err:l,code:-1})));const[u,i]=await Promise.all(a);if(u.code===200){const{total_space:l,used_space:k,releaseable_space:U}=u==null?void 0:u.data;e.totalSpace=S(l),e.useSpace=S(k),e.releasedSpace=U,e.spaceRate=Math.round(e.useSpace/e.totalSpace*100)}if(s&&i&&i.code===200){const{status:l}=i==null?void 0:i.data;e.status=l,["success","failed","idle"].includes(e.status)&&(clearInterval(t.value),t.value=null,clearInterval(r.value),r.value=null),N(l,e.releasedSpace)}}catch(a){console.error(a),t.value&&(clearInterval(t.value),clearInterval(r.value),t.value=null,r.value=null,e.status="failed",e.process=0)}};let m;V(()=>e.status,s=>{s=="success"&&(m=z({type:"success",message:o("spaceClear.notifyMessage",{value:S(e.originUseSpace-e.useSpace)}),className:"bottom-notify",position:"bottom"}))}),I(!1);const B=()=>{e.status="idle"};return q(()=>{m==null||m.close(),t.value&&clearInterval(t.value),r.value&&clearInterval(r.value)}),(s,a)=>{const u=j,i=E;return h(),C(G,null,[e.status==="idle"||e.status==="success"?(h(),C("div",A,[v(u,{"current-rate":f.value,"onUpdate:currentRate":a[0]||(a[0]=l=>f.value=l),rate:e.spaceRate,speed:100,size:"150px",color:x},{default:_(()=>[n("div",$,[n("span",H,c(p(o)("spaceClear.diskUsageStatus")),1),n("span",J,c(e.useSpace)+"/"+c(e.totalSpace)+"GB ",1)])]),_:1},8,["current-rate","rate"]),n("div",L,c(p(o)("spaceClear.expectedRelease",{value:e.releasedSpace})),1),v(i,{round:"",type:"primary",class:"clear-btn",onClick:w},{default:_(()=>[b(c(p(o)("spaceClear.oneKeyClear")),1)]),_:1})])):y("",!0),e.status==="running"?(h(),C("div",O,[v(u,{"current-rate":f.value,"onUpdate:currentRate":a[1]||(a[1]=l=>f.value=l),rate:e.process,speed:100,size:"150px",color:F},{default:_(()=>[n("div",Q,[n("span",W,c(p(o)("spaceClear.diskCleaning")),1),n("span",X,c(e.process)+"%",1)])]),_:1},8,["current-rate","rate"]),n("div",Y,c(p(o)("spaceClear.expectedRelease",{value:e.releasedSpace})),1),v(i,{round:"",type:"primary",class:"clear-btn",disabled:""},{default:_(()=>[b(c(p(o)("spaceClear.oneKeyClear")),1)]),_:1})])):y("",!0),e.status==="failed"?(h(),C("div",Z,[n("img",{src:s.loadingImg,class:"loading-img",alt:""},null,8,ee),n("p",null,c(p(o)("spaceClear.serverError")),1),v(i,{round:"",type:"primary",class:"back-btn",onClick:B},{default:_(()=>[b(c(p(o)("spaceClear.back")),1)]),_:1})])):y("",!0)],64)}}},ne=R(ae,[["__scopeId","data-v-d777e6ee"]]);export{ne as default};
