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