| 1 |
- var S=(e,s,t)=>new Promise((c,o)=>{var i=n=>{try{d(t.next(n))}catch(m){o(m)}},a=n=>{try{d(t.throw(n))}catch(m){o(m)}},d=n=>n.done?c(n.value):Promise.resolve(n.value).then(i,a);d((t=t.apply(e,s)).next())});import{q as C,f as h,g as l,bT as T,bU as A,bV as O,aJ as B,bW as V,bR as k,aV as z,a9 as I,aG as b,z as M,o as f,J as P,j as E,h as r,P as U,L as p,M as u,l as j,S as D,G as F,bq as G,H as v,bX as H,a7 as R}from"./index-BvrJT4vV.js";const L="iOS",W="Android",J="Harmony";function q(e="0",s="0"){const t=String(e).split("."),c=String(s).split("."),o=Math.min(t.length,c.length);let i=0;for(let a=0;a<o;a++){const d=Number(t[a]),n=Number(c[a]);if(d>n){i=1;break}else if(d<n){i=-1;break}}if(i===0&&t.length!==c.length){const a=t.length>c.length,d=a?t:c;for(let n=o;n<d.length;n++)if(Number(d[n])>0){a?i=1:i=-1;break}}return i}const K="/uni_modules/uni-upgrade-center-app/static/app/bg_top.png",X="/uni_modules/uni-upgrade-center-app/static/app/app_update_close.png",y="UNI_ADMIN_UPGRADE_CENTER_LOCAL_FILE_PATH";let g=null,_;const Q={emits:["close","show"],data(){return{installForBeforeFilePath:"",installed:!1,installing:!1,downloadSuccess:!1,downloading:!1,downLoadPercent:0,downloadedSize:0,packageFileSize:0,tempFilePath:"",title:"更新日志",contents:"",version:"",is_mandatory:!1,url:"",platform:[],store_list:null,subTitle:"发现新版本",downLoadBtnTextiOS:"立即跳转更新",downLoadBtnText:"立即下载更新",downLoadingText:"安装包下载中,请稍后"}},onLoad({local_storage_key:e}){if(!e){k();return}const s=b(e);if(!s){k();return}this.setLocalPackageInfo(s)},onBackPress(){if(this.is_mandatory)return!0;this.needNotificationProgress||g&&g.abort()},onHide(){_=null},computed:{isWGT(){return this.type==="wgt"},isNativeApp(){return this.type==="native_app"},isiOS(){return this.platform.indexOf(L)!==-1},isAndroid(){return this.platform.indexOf(W)!==-1},isHarmony(){return this.platform.indexOf(J)!==-1},isApplicationStore(){return!this.isWGT&&this.isNativeApp&&(this.isiOS||this.isHarmony)},needNotificationProgress(){return this.platform.indexOf(L)===-1&&!this.is_mandatory&&!this.isHarmony}},methods:{show(e,s){},setLocalPackageInfo(e){const s=["version","url","type"];for(let t in e)if(s.indexOf(t)!==-1&&!e[t])return;Object.assign(this,e),this.checkLocalStoragePackage()},checkLocalStoragePackage(){const e=b(y);if(e){const{version:s,savedFilePath:t,installed:c}=e;!c&&q(s,this.version)===0?(this.downloadSuccess=!0,this.installForBeforeFilePath=t,this.tempFilePath=t):this.deleteSavedFile(t)}},askAbortDownload(){I({title:"是否取消下载?",cancelText:"否",confirmText:"是",success:e=>{e.confirm&&(g&&g.abort(),this.needNotificationProgress&&cancelNotificationProgress(),k())}})},closeUpdate(){return S(this,null,function*(){if(this.downloading){if(this.is_mandatory)return z({title:"下载中,请稍后……",icon:"none",duration:500});if(!this.needNotificationProgress){this.askAbortDownload();return}}!this.needNotificationProgress&&this.downloadSuccess&&this.tempFilePath&&(yield this.saveFile(this.tempFilePath,this.version))})},updateApp(){this.checkStoreScheme().catch(()=>{this.downloadPackage()}).finally(()=>{_=null})},checkStoreScheme(){const e=(this.store_list||[]).filter(s=>s.enable);return e&&e.length?(e.sort((s,t)=>t.priority-s.priority).map(s=>s.scheme).reduce((s,t,c)=>(_=(s||(s=Promise.reject())).catch(()=>new Promise((o,i)=>{plus.runtime.openURL(t,a=>{i(a)})})),_),_),_):Promise.reject()},downloadPackage(){this.downloading=!0,g=V({url:this.url,success:e=>{if(e.statusCode==200)if(this.isWGT&&e.tempFilePath.split(".").slice(-1)[0]!=="wgt"){const s=t=>{};plus.io.resolveLocalFileSystemURL(e.tempFilePath,t=>{t.getParent(c=>{const o=`new_wgt_${Date.now()}.wgt`;t.copyTo(c,o,i=>{this.tempFilePath=i.fullPath,this.downLoadComplete()},s)},s)},s)}else this.tempFilePath=e.tempFilePath,this.downLoadComplete();else this.downloadFail()},fail:e=>{this.downloadFail()}}),g.onProgressUpdate(e=>{this.downLoadPercent=e.progress,this.downloadedSize=(e.totalBytesWritten/Math.pow(1024,2)).toFixed(2),this.packageFileSize=(e.totalBytesExpectedToWrite/Math.pow(1024,2)).toFixed(2),this.needNotificationProgress&&!this.downloadSuccess&&createNotificationProgress({title:"升级中心正在下载安装包……",content:`${this.downLoadPercent}%`,progress:this.downLoadPercent,onClick:()=>{this.askAbortDownload()}})}),this.needNotificationProgress&&k()},downloadFail(){const e="下载失败,请点击重试";this.downloadSuccess=!1,this.downloading=!1,this.downLoadPercent=0,this.downloadedSize=0,this.packageFileSize=0,this.downLoadBtnText=e,g=null,this.needNotificationProgress&&finishNotificationProgress({title:"升级包下载失败",content:"请重新检查更新"})},downLoadComplete(){if(this.downloadSuccess=!0,this.downloading=!1,this.downLoadPercent=0,this.downloadedSize=0,this.packageFileSize=0,g=null,this.needNotificationProgress){finishNotificationProgress({title:"安装升级包",content:"下载完成"}),this.installPackage();return}this.is_mandatory&&this.installPackage()},installPackage(){},restart(){this.installed=!1},saveFile(e,s){return new Promise((t,c)=>{O({tempFilePath:e,success({savedFilePath:o}){B(y,{version:s,savedFilePath:o})},complete(){t()}})})},deleteSavedFile(e){return T(y),A({filePath:e})},jumpToApplicationStore(){plus.runtime.openURL(this.url)}}};function Y(e,s,t,c,o,i){const a=U,d=j,n=E,m=D,w=G,N=H,x=M("layout-default-uni");return f(),h(x,null,{default:l(()=>[e.shown?(f(),h(n,{key:0,class:"mask flex-center"},{default:l(()=>[r(n,{class:"content botton-radius"},{default:l(()=>[r(n,{class:"content-top"},{default:l(()=>[r(a,{class:"content-top-text"},{default:l(()=>[p(u(e.$t("upgrade.title")),1)]),_:1}),r(d,{class:"content-top",style:{top:"0"},width:"100%",height:"100%",src:K})]),_:1}),r(n,{class:"content-header"}),r(n,{class:"content-body"},{default:l(()=>[r(n,{class:"title"},{default:l(()=>[r(a,null,{default:l(()=>[p(u(e.$t("upgrade.newVersion")),1)]),_:1}),r(a,{class:"content-body-version"},{default:l(()=>[p(u(e.$t("upgrade.version").replace("{version}",o.version)),1)]),_:1})]),_:1}),r(n,{class:"body"},{default:l(()=>[r(m,{class:"box-des-scroll","scroll-y":"true"},{default:l(()=>[r(a,{class:"box-des"},{default:l(()=>[p(u(o.contents),1)]),_:1})]),_:1})]),_:1}),r(n,{class:"footer flex-center"},{default:l(()=>[i.isApplicationStore?(f(),h(w,{key:0,class:"content-button",style:{border:"none",color:"#fff"},plain:"",onClick:i.jumpToApplicationStore},{default:l(()=>[p(u(e.$t("upgrade.goToStore")),1)]),_:1},8,["onClick"])):(f(),F(v,{key:1},[o.downloadSuccess?o.downloadSuccess&&!o.installed?(f(),h(w,{key:1,class:"content-button",style:{border:"none",color:"#fff"},plain:"",loading:o.installing,disabled:o.installing,onClick:i.installPackage},{default:l(()=>[p(u(o.installing?e.$t("upgrade.installing"):e.$t("upgrade.install")),1)]),_:1},8,["loading","disabled","onClick"])):o.installed&&!i.isWGT?(f(),h(w,{key:2,class:"content-button",style:{border:"none",color:"#fff"},plain:"",loading:o.installing,disabled:o.installing,onClick:i.installPackage},{default:l(()=>[p(u(e.$t("upgrade.installIncomplete")),1)]),_:1},8,["loading","disabled","onClick"])):o.installed&&i.isWGT?(f(),h(w,{key:3,class:"content-button",style:{border:"none",color:"#fff"},plain:"",onClick:i.restart},{default:l(()=>[p(u(e.$t("upgrade.restart")),1)]),_:1},8,["onClick"])):P("",!0):(f(),F(v,{key:0},[o.downloading?(f(),h(n,{key:0,class:"progress-box flex-column"},{default:l(()=>[r(N,{class:"progress",percent:o.downLoadPercent,activeColor:"#3DA7FF","show-info":"","stroke-width":"10"},null,8,["percent"]),r(n,{style:{width:"100%","font-size":"28rpx",display:"flex","justify-content":"space-around"}},{default:l(()=>[r(a,null,{default:l(()=>[p(u(e.$t("upgrade.downloading")),1)]),_:1}),r(a,null,{default:l(()=>[p("("+u(o.downloadedSize)+"/"+u(o.packageFileSize)+"M)",1)]),_:1})]),_:1})]),_:1})):(f(),h(w,{key:1,class:"content-button",style:{border:"none",color:"#fff"},plain:"",onClick:i.updateApp},{default:l(()=>[p(u(e.$t("upgrade.download")),1)]),_:1},8,["onClick"]))],64))],64))]),_:1})]),_:1}),o.is_mandatory?P("",!0):(f(),h(d,{key:0,class:"close-img",src:X,onClick:R(i.closeUpdate,["stop"])},null,8,["onClick"]))]),_:1})]),_:1})):P("",!0)]),_:1})}const ee=C(Q,[["render",Y],["__scopeId","data-v-c7df1a15"]]);export{ee as default};
|