import{_ as U,i as T,u as P,ac as I,r as S,p as x,o as N,q as A,c as y,b as g,d as u,F as D,x as E,t as L,e as O,h as j,f as B,bb as C,bc as V,bd as $,be as F}from"./index-BDh_pN-M.js";import{P as R}from"./index-CGYJVI3k.js";import{i as J}from"./info-Bq3qLitc.js";const M={class:"version-download-wrapper"},z={class:"app-list-container"},G={class:"top"},H={class:"title"},K={class:"info"},Q={class:"bottom"},W={class:"bottom-message"},X=["src"],Y={__name:"version-download",setup(Z){T.global.t;const c=P(),v=I(),m=v.query.isUpdateAll==="true",d=S({download:{}}),i=S(!1),o=x({systemType:"",installStatus:{},appLists:[]}),b=async()=>{try{const{code:s,data:e}=await V();return s===200?(o.appLists=e==null?void 0:e.map(r=>({...r,downloadStatus:"pending",downloadProgress:0})),!0):(console.error("获取下载列表失败",s),_(),!1)}catch(s){return console.error("获取下载列表异常",s),_(),!1}};function _(){c.push({name:"toolsUpgrade",query:{status:"failed"}})}const p=()=>{if(i.value)return;o.appLists.every(e=>e.downloadStatus==="success")&&(i.value=!0,Object.keys(d.value.download).forEach(e=>{clearInterval(d.value.download[e])}),d.value.download={},c.push({name:"versionInstall",query:{systemType:o.systemType,isUpdateAll:m}}).catch(e=>{console.error("跳转安装页面失败",e)}))},w=(s,e)=>{d.value[e][s]&&(clearInterval(d.value[e][s]),delete d.value[e][s])},h=async(s,e)=>new Promise(r=>{w(s,"download"),d.value.download[s]=setInterval(async()=>{try{const a=await $({taskId:e});if(a.code===200){const{progress:n,status:t}=a.data,l=o.appLists.find(q=>q.id===s);l&&(l.downloadProgress=n||0,l.downloadStatus=t||"pending",["success","failed"].includes(t)&&(w(s,"download"),p(),r()),(t==="failed"||t==="timeout")&&(w(s,"download"),c.push({name:"toolsUpgrade",query:{status:"failed"}}),r()))}else{w(s,"download");const n=o.appLists.find(t=>t.id===s);n&&(n.downloadStatus="failed"),p(),r()}}catch(a){w(s,"download"),console.error("查询下载进度异常",a);const n=o.appLists.find(t=>t.id===s);n&&(n.downloadStatus="failed"),p(),r()}},2e3)}),f=async(s=0)=>{var e;if(!i.value)for(let r=s;r<o.appLists.length;r++){const a=o.appLists[r];if(i.value)break;if(!["success","failed"].includes(a.downloadStatus))try{const n={systemType:o.systemType,module:{id:a.id,name:a.name}},t=await F(n);if(t.code===200){const l=(e=t.data)==null?void 0:e.taskId;if(l&&(a.downloadStatus="downloading",await h(a.id,l),a.downloadStatus!=="success")){c.push({name:"toolsUpgrade",query:{status:"failed"}});break}}else{console.error(`启动${a.name}下载失败`,t.code),a.downloadStatus="failed",p(),c.push({name:"toolsUpgrade",query:{status:"failed"}});break}}catch(n){console.error(`启动${a.name}下载异常`,n),a.downloadStatus="failed",p(),c.push({name:"toolsUpgrade",query:{status:"failed"}});break}}},k=async()=>{try{const{code:s,data:e}=await C();if(s===200)return o.installStatus=e==null?void 0:e.install_status,o.installStatus}catch(s){console.error("查询更新进度异常",s)}return null};return N(async()=>{var r;const s=await k();if(o.systemType=v.query.systemType||((r=o.installStatus)==null?void 0:r.systemType),(s==null?void 0:s.stage)==="update"){i.value=!0,Object.keys(d.value.download).forEach(a=>{clearInterval(d.value.download[a])}),d.value.download={},await c.push({name:"versionInstall",query:{systemType:o.systemType,isUpdateAll:m}}).catch(a=>{console.error("跳转安装页面失败",a)});return}if(await b()){if((s==null?void 0:s.stage)==="download"&&s.moduleName&&s.taskId){const a=s.moduleName,n=o.appLists.find(t=>t.name===a);if(n){const t=o.appLists.findIndex(l=>l.id===n.id);for(let l=0;l<t;l++)o.appLists[l].downloadStatus="success",o.appLists[l].downloadProgress=100;n.downloadStatus="downloading",await h(n.id,s.taskId),await f(t+1)}else console.error(`未找到模块【${s.moduleName}】对应的应用，走默认下载流程`),await f();return}await f()}}),A(()=>{Object.keys(d.value.download).forEach(s=>{clearInterval(d.value.download[s])}),d.value={download:{}}}),(s,e)=>{const r=R;return g(),y("div",M,[u("ul",z,[(g(!0),y(D,null,E(o.appLists,a=>(g(),y("li",{key:a.id},[u("div",G,[u("div",H,L(a.name),1),u("div",K,L((a==null?void 0:a.downloadStatus)==="downloading"||(a==null?void 0:a.downloadStatus)==="extracting"?"下载中":(a==null?void 0:a.downloadStatus)==="success"?"下载完成":(a==null?void 0:a.downloadStatus)==="failed"?"下载失败":"等待"),1)]),u("div",Q,[O(r,{class:"custom-progress",percentage:a.downloadProgress||0},null,8,["percentage"])])]))),128))]),u("div",W,[u("img",{src:B(J),alt:""},null,8,X),e[0]||(e[0]=j(" 为了避免中断，请勿关闭或刷新页面 "))])])}}},os=U(Y,[["__scopeId","data-v-b764271f"]]);export{os as default};
