Files
CoreInject/frontend/dist/assets/CqahAvH1.js
2025-11-16 05:39:11 +08:00

38 lines
8.5 KiB
JavaScript

import{d as e,r as s,c as a,o as l,i as t,a as o,e as n,m as i,F as c,B as r,n as u,g as d,z as v,b as m,v as p,u as g,t as w,h as f}from"./CdD4XvnD.js"
import{c as y,A as k,_ as b,M as h,T as C,a as x}from"./BaSQ3xJt.js"
import{f as T,a as S,b as D,c as M}from"./CFhT0fBm.js"
const z={class:"download-manager"},_={class:"filter-bar"},E=["onClick"],N={class:"filter-count"},$={class:"recent-updates-section"},A={class:"download-list"},F={key:0,class:"empty-state"},I={class:"item-icon"},j={class:"item-content"},R={class:"item-name-row"},L={class:"item-name"},P={class:"item-meta-row"},q={class:"item-type"},B={key:0,class:"item-progress-section"},G={class:"progress-bar"},X={class:"progress-info"},Y={class:"progress-text"},H={class:"progress-stats"},J={class:"progress-speed"},K={key:0,class:"progress-time"},O={key:1,class:"item-progress-section"},Q={class:"progress-info"},U={class:"progress-stats"},V={key:2,class:"item-error"},W={class:"item-right"},Z={key:0,class:"item-status-text"},ee={class:"item-actions"},se=["onClick"],ae={class:"btn-more-wrapper"},le=["onClick"],te=["onClick"],oe=["onClick"],ne=["onClick"],ie=["onClick"],ce=x(e({__name:"DownloadManager",setup(e){const{toasts:x,success:ce,error:re,removeToast:ue}=y(),de=s([]),ve=s("all")
let me=null
const pe=s(!1),ge=s({title:"",message:"",type:"warning",confirmText:"确认",cancelText:"取消"})
let we=null
const fe=s(!1),ye=s(null),ke=[{label:"全部",value:"all"},{label:"下载中",value:"downloading"},{label:"已完成",value:"completed"},{label:"已暂停",value:"paused"},{label:"失败",value:"error"}],be=a(()=>"all"===ve.value?de.value:de.value.filter(e=>e.status===ve.value)),he=e=>"all"===e?de.value.length:de.value.filter(s=>s.status===e).length,Ce=e=>({downloading:"fluent-color:arrow-square-down-32",completed:"fluent-color:checkmark-circle-24",paused:"fluent-color:clock-24",error:"fluent-color:error-circle-24",pending:"fluent-color:hourglass-24"}[e.status]||"fluent-color:document-24"),xe=e=>!!e&&e<Math.pow(1024,5)&&e<=Number.MAX_SAFE_INTEGER,Te=e=>{if("downloading"===e.status)return"下载中"
if("completed"===e.status&&e.updateTime){const s=new Date(1e3*e.updateTime),a=(new Date).getTime()-s.getTime()
return 0===Math.floor(a/864e5)?"今天更新":`已于${s.getFullYear()}/${String(s.getMonth()+1).padStart(2,"0")}/${String(s.getDate()).padStart(2,"0")}更新`}return""},Se=e=>{const s=e.target
!fe.value||s.closest(".menu-popup")||s.closest(".btn-more")||(fe.value=!1,ye.value=null)}
l(()=>{De(),me=setInterval(De,1e3),document.addEventListener("click",Se)}),t(()=>{me&&clearInterval(me),document.removeEventListener("click",Se)})
const De=async()=>{try{de.value=await k.getAllDownloads()}catch(e){}},Me=()=>{De()},ze=(e,s,a="warning")=>(fe.value=!1,ye.value=null,new Promise(l=>{ge.value={title:e,message:s,type:a,confirmText:"确认",cancelText:"取消"},pe.value=!0,we=l})),_e=()=>{pe.value=!1,we&&(we(!0),we=null)},Ee=()=>{pe.value=!1,we&&(we(!1),we=null)}
return(e,s)=>(f(),o("div",z,[n("div",{class:"page-header"},[s[1]||(s[1]=n("div",{class:"header-content"},[n("h1",{class:"page-title"},"更新和下载"),n("p",{class:"page-subtitle"},' 通过单击"检查更新"、"全部更新"或"更新"下载并安装应用更新 ')],-1)),n("button",{class:"btn-check-updates",onClick:Me}," 检查更新 ")]),n("div",_,[(f(),o(c,null,r(ke,e=>n("button",{key:e.value,class:u(["filter-btn",{active:ve.value===e.value}]),onClick:s=>ve.value=e.value},[d(v(e.label)+" ",1),n("span",N,v(he(e.value)),1)],10,E)),64))]),n("div",$,[s[12]||(s[12]=n("h2",{class:"section-title"},"最近的更新",-1)),n("div",A,[0===be.value.length?(f(),o("div",F,[i(b,{icon:"fluent-color:cloud-24",class:"empty-icon"}),s[2]||(s[2]=n("p",{class:"empty-text"},"暂无下载任务",-1))])):m("",!0),(f(!0),o(c,null,r(be.value,e=>{var a,l
return f(),o("div",{key:e.id,class:"download-item"},[n("div",I,[i(b,{icon:Ce(e),class:"icon"},null,8,["icon"])]),n("div",j,[n("div",R,[n("span",L,v(e.fileName),1)]),n("div",P,[s[3]||(s[3]=n("span",{class:"item-publisher"},"下载任务",-1)),s[4]||(s[4]=n("span",{class:"item-separator"},"•",-1)),n("span",q,v((l=e.status,{pending:"等待中",downloading:"下载中",paused:"已暂停",completed:"应用",error:"失败"}[l]||"下载任务")),1)]),"downloading"===e.status?(f(),o("div",B,[n("div",G,[n("div",{class:"progress-fill",style:p({width:xe(e.totalSize)?`${Math.min(100,Math.max(0,100*(e.progress||0)))}%`:"0%"})},null,4)]),n("div",X,[n("span",Y,v(xe(e.totalSize)?g(T)(100*(e.progress||0)):"--"),1),n("span",H,v(g(S)(e.downloadedSize||0))+" / "+v(g(S)(e.totalSize||0)),1),n("span",J,v(g(D)(e.downloadSpeed||0)),1),xe(e.totalSize)?(f(),o("span",K," 剩余 "+v(g(M)(e.remainingTime||0)),1)):m("",!0)])])):"completed"===e.status?(f(),o("div",O,[s[6]||(s[6]=n("div",{class:"progress-bar"},[n("div",{class:"progress-fill completed",style:{width:"100%"}})],-1)),n("div",Q,[s[5]||(s[5]=n("span",{class:"progress-text"},"100%",-1)),n("span",U,v(g(S)(e.totalSize)),1)])])):m("",!0),e.errorMsg?(f(),o("div",V,[i(b,{icon:"fluent-color:error-circle-24",class:"error-icon"}),d(" "+v(e.errorMsg),1)])):m("",!0)]),n("div",W,[Te(e)?(f(),o("div",Z,v(Te(e)),1)):m("",!0),n("div",ee,["completed"===e.status?(f(),o("button",{key:0,class:"btn-action btn-open",onClick:s=>(async e=>{var s,a
try{const s=await k.openDownloadFile(e)
s.success?ce(s.message||"打开文件成功",2e3):re(s.message||"打开文件失败",3e3)}catch(l){const e=(null==(a=null==(s=l.response)?void 0:s.data)?void 0:a.message)||l.message||"打开文件失败"
re(e,3e3)}})(e.id)},[i(b,{icon:"mdi:folder-open",class:"btn-icon"}),s[7]||(s[7]=d(" 打开 ",-1))],8,se)):m("",!0),n("div",ae,[n("button",{class:"btn-more",onClick:w(s=>((e,s)=>{var a
null==s||s.stopPropagation(),fe.value&&(null==(a=ye.value)?void 0:a.id)===e.id?(fe.value=!1,ye.value=null):(ye.value=e,fe.value=!0)})(e,s),["stop"])},[i(b,{icon:"mdi:dots-vertical"})],8,le),fe.value&&(null==(a=ye.value)?void 0:a.id)===e.id?(f(),o("div",{key:0,class:"menu-popup",onClick:s[0]||(s[0]=w(()=>{},["stop"]))},["downloading"===e.status?(f(),o("button",{key:0,class:"menu-item",onClick:w(s=>{(async e=>{var s,a
try{const s=await k.pauseDownload(e)
if(!s.success)return void re(s.message||"暂停下载失败",3e3)
ce(s.message||"暂停下载成功",2e3),await De()}catch(l){const e=(null==(a=null==(s=l.response)?void 0:s.data)?void 0:a.message)||l.message||"暂停下载失败"
re(e,3e3)}})(e.id),fe.value=!1},["stop"])},[i(b,{icon:"fluent-color:clock-24"}),s[8]||(s[8]=d(" 暂停 ",-1))],8,te)):m("",!0),"paused"===e.status?(f(),o("button",{key:1,class:"menu-item",onClick:w(s=>{(async e=>{var s,a
try{const s=await k.resumeDownload(e)
if(!s.success)return void re(s.message||"恢复下载失败",3e3)
ce(s.message||"恢复下载成功",2e3),await De()}catch(l){const e=(null==(a=null==(s=l.response)?void 0:s.data)?void 0:a.message)||l.message||"恢复下载失败"
re(e,3e3)}})(e.id),fe.value=!1},["stop"])},[i(b,{icon:"fluent-color:arrow-sync-24"}),s[9]||(s[9]=d(" 继续 ",-1))],8,oe)):m("",!0),"completed"===e.status||"error"===e.status?(f(),o("button",{key:2,class:"menu-item",onClick:w(s=>{(async e=>{var s,a
if(await ze("重新下载",`确定要重新下载 "${e.fileName}" 吗?这将删除并重新下载该文件。`,"warning"))try{await k.deleteDownload(e.id)
const s=await k.startDownload(e.url,e.fileName)
if(!s.success)throw new Error(s.message||"重新下载失败")
await De()}catch(l){const e=(null==(a=null==(s=l.response)?void 0:s.data)?void 0:a.message)||l.message||"重新下载失败"
re(e,3e3)}})(e),fe.value=!1},["stop"])},[i(b,{icon:"fluent-color:arrow-sync-24"}),s[10]||(s[10]=d(" 重新下载 ",-1))],8,ne)):m("",!0),n("button",{class:"menu-item danger",onClick:w(s=>{(async e=>{var s,a
if(await ze("删除下载任务","确定要删除这个下载任务吗?","danger"))try{const s=await k.deleteDownload(e)
if(!s.success)return void re(s.message||"删除下载任务失败",3e3)
ce(s.message||"删除下载任务成功",2e3),await De()}catch(l){const e=(null==(a=null==(s=l.response)?void 0:s.data)?void 0:a.message)||l.message||"删除下载任务失败"
re(e,3e3)}})(e.id),fe.value=!1},["stop"])},[i(b,{icon:"fluent-color:dismiss-circle-24"}),s[11]||(s[11]=d(" 删除 ",-1))],8,ie)])):m("",!0)])])])])}),128))])]),i(h,{visible:pe.value,title:ge.value.title,message:ge.value.message,type:"danger"===ge.value.type?"error":ge.value.type||"warning","confirm-text":ge.value.confirmText,"cancel-text":ge.value.cancelText,onConfirm:_e,onCancel:Ee},null,8,["visible","title","message","type","confirm-text","cancel-text"]),i(C,{toasts:g(x),onRemove:g(ue)},null,8,["toasts","onRemove"])]))}}),[["__scopeId","data-v-f3ad47eb"]])
export{ce as default}