Files
sbnews/server/public/mobile/assets/uni_modules-uni-upgrade-center-app-pages-upgrade-popup.BMmzpahs.js
T

2 lines
8.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{_ as t,c as e,w as o,D as i,aY as s,b2 as a,b3 as n,s as l,b4 as r,a0 as c,j as d,N as h,X as f,k as p,o as u,l as g,q as w,t as P,v as m,p as k,S as y,aO as _,x as b,F as S,b5 as F,R as L}from"./index-CXWaumcQ.js";const v="UNI_ADMIN_UPGRADE_CENTER_LOCAL_FILE_PATH";let N,x=null;const C=t({emits:["close","show"],data:()=>({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:t}){if(!t)return console.error("local_storage_key为空,请检查后重试"),void c();const e=f(t);if(!e)return console.error("安装包信息为空,请检查后重试"),void c();this.setLocalPackageInfo(e)},onBackPress(){if(this.is_mandatory)return!0;this.needNotificationProgress||x&&x.abort()},onHide(){N=null},computed:{isWGT(){return"wgt"===this.type},isNativeApp(){return"native_app"===this.type},isiOS(){return-1!==this.platform.indexOf("iOS")},isAndroid(){return-1!==this.platform.indexOf("Android")},isHarmony(){return-1!==this.platform.indexOf("Harmony")},isApplicationStore(){return!this.isWGT&&this.isNativeApp&&(this.isiOS||this.isHarmony)},needNotificationProgress(){return-1===this.platform.indexOf("iOS")&&!this.is_mandatory&&!this.isHarmony}},methods:{show(t,e){},setLocalPackageInfo(t){const e=["version","url","type"];for(let o in t)if(-1!==e.indexOf(o)&&!t[o])return void console.error(`参数 ${o} 必填,请检查后重试`);Object.assign(this,t),this.checkLocalStoragePackage()},checkLocalStoragePackage(){const t=f(v);if(t){const{version:e,savedFilePath:o,installed:i}=t;i||0!==function(t="0",e="0"){const o=String(t).split("."),i=String(e).split("."),s=Math.min(o.length,i.length);let a=0;for(let n=0;n<s;n++){const t=Number(o[n]),e=Number(i[n]);if(t>e){a=1;break}if(t<e){a=-1;break}}if(0===a&&o.length!==i.length){const t=o.length>i.length,e=t?o:i;for(let o=s;o<e.length;o++)if(Number(e[o])>0){a=t?1:-1;break}}return a}(e,this.version)?this.deleteSavedFile(o):(this.downloadSuccess=!0,this.installForBeforeFilePath=o,this.tempFilePath=o)}},askAbortDownload(){h({title:"是否取消下载?",cancelText:"否",confirmText:"是",success:t=>{if(t.confirm){if(x&&x.abort(),this.needNotificationProgress)try{cancelNotificationProgress()}catch(e){console.warn("[upgrade] cancelNotificationProgress not available:",e)}c()}}})},async closeUpdate(){if(this.downloading){if(this.is_mandatory)return d({title:"下载中,请稍后……",icon:"none",duration:500});if(!this.needNotificationProgress)return void this.askAbortDownload()}!this.needNotificationProgress&&this.downloadSuccess&&this.tempFilePath&&await this.saveFile(this.tempFilePath,this.version)},updateApp(){this.checkStoreScheme().catch(()=>{this.downloadPackage()}).finally(()=>{N=null})},checkStoreScheme(){const t=(this.store_list||[]).filter(t=>t.enable);return t&&t.length?(t.sort((t,e)=>e.priority-t.priority).map(t=>t.scheme).reduce((t,e,o)=>(N=(t||(t=Promise.reject())).catch(()=>new Promise((t,o)=>{plus.runtime.openURL(e,t=>{o(t)})})),N),N),N):Promise.reject()},async downloadPackage(){this.downloading=!0;let t=this.url;x=r({url:t,success:t=>{if(200==t.statusCode)if(this.isWGT&&"wgt"!==t.tempFilePath.split(".").slice(-1)[0]){const e=t=>{console.log("[FILE RENAME FAIL]",JSON.stringify(t))};plus.io.resolveLocalFileSystemURL(t.tempFilePath,t=>{t.getParent(o=>{const i=`new_wgt_${Date.now()}.wgt`;t.copyTo(o,i,t=>{this.tempFilePath=t.fullPath,this.downLoadComplete()},e)},e)},e)}else this.tempFilePath=t.tempFilePath,this.downLoadComplete();else console.log("下载错误:"+JSON.stringify(t)),this.downloadFail()},fail:t=>{console.log("下载错误:"+JSON.stringify(t)),this.downloadFail()}}),x.onProgressUpdate(t=>{if(this.downLoadPercent=t.progress,this.downloadedSize=(t.totalBytesWritten/Math.pow(1024,2)).toFixed(2),this.packageFileSize=(t.totalBytesExpectedToWrite/Math.pow(1024,2)).toFixed(2),this.needNotificationProgress&&!this.downloadSuccess)try{createNotificationProgress({title:"升级中心正在下载安装包……",content:`${this.downLoadPercent}%`,progress:this.downLoadPercent,onClick:()=>{this.askAbortDownload()}})}catch(e){console.warn("[upgrade] createNotificationProgress not available:",e)}}),this.needNotificationProgress&&c()},downloadFail(){if(this.downloadSuccess=!1,this.downloading=!1,this.downLoadPercent=0,this.downloadedSize=0,this.packageFileSize=0,this.downLoadBtnText="下载失败,请点击重试",x=null,this.needNotificationProgress)try{finishNotificationProgress({title:"升级包下载失败",content:"请重新检查更新",onClick:()=>{}})}catch(t){console.warn("[upgrade] finishNotificationProgress not available:",t)}},downLoadComplete(){if(this.downloadSuccess=!0,this.downloading=!1,this.downLoadPercent=0,this.downloadedSize=0,this.packageFileSize=0,x=null,this.needNotificationProgress){try{finishNotificationProgress({title:"安装升级包",content:"下载完成",onClick:()=>{}})}catch(t){console.warn("[upgrade] finishNotificationProgress not available:",t)}this.installPackage()}else this.is_mandatory&&this.installPackage()},installPackage(){},restart(){this.installed=!1},saveFile:(t,e)=>new Promise((o,i)=>{n({tempFilePath:t,success({savedFilePath:t}){l(v,{version:e,savedFilePath:t})},complete(){o()}})}),deleteSavedFile:t=>(s(v),a({filePath:t})),jumpToApplicationStore(){plus.runtime.openURL(this.url)}}},[["render",function(t,s,a,n,l,r){const c=w,d=k,h=p,f=y,v=_,N=F;return t.shown?(u(),e(h,{key:0,class:"mask flex-center"},{default:o(()=>[g(h,{class:"content botton-radius"},{default:o(()=>[g(h,{class:"content-top"},{default:o(()=>[g(c,{class:"content-top-text"},{default:o(()=>[P(m(l.title),1)]),_:1}),g(d,{class:"content-top",style:{top:"0"},width:"100%",height:"100%",src:"/uni_modules/uni-upgrade-center-app/static/app/bg_top.png"})]),_:1}),g(h,{class:"content-header"}),g(h,{class:"content-body"},{default:o(()=>[g(h,{class:"title"},{default:o(()=>[g(c,null,{default:o(()=>[P(m(l.subTitle),1)]),_:1}),g(c,{class:"content-body-version"},{default:o(()=>[P(m(l.version),1)]),_:1})]),_:1}),g(h,{class:"body"},{default:o(()=>[g(f,{class:"box-des-scroll","scroll-y":"true"},{default:o(()=>[g(c,{class:"box-des"},{default:o(()=>[P(m(l.contents),1)]),_:1})]),_:1})]),_:1}),g(h,{class:"footer flex-center"},{default:o(()=>[r.isApplicationStore?(u(),e(v,{key:0,class:"content-button",style:{border:"none",color:"#fff"},plain:"",onClick:r.jumpToApplicationStore},{default:o(()=>[P(m(l.downLoadBtnTextiOS),1)]),_:1},8,["onClick"])):(u(),b(S,{key:1},[l.downloadSuccess?l.downloadSuccess&&!l.installed?(u(),e(v,{key:1,class:"content-button",style:{border:"none",color:"#fff"},plain:"",loading:l.installing,disabled:l.installing,onClick:r.installPackage},{default:o(()=>[P(m(l.installing?"正在安装……":"下载完成,立即安装"),1)]),_:1},8,["loading","disabled","onClick"])):l.installed&&!r.isWGT?(u(),e(v,{key:2,class:"content-button",style:{border:"none",color:"#fff"},plain:"",loading:l.installing,disabled:l.installing,onClick:r.installPackage},{default:o(()=>[P(" 安装未完成,点击安装 ")]),_:1},8,["loading","disabled","onClick"])):l.installed&&r.isWGT?(u(),e(v,{key:3,class:"content-button",style:{border:"none",color:"#fff"},plain:"",onClick:r.restart},{default:o(()=>[P("安装完毕,点击重启")]),_:1},8,["onClick"])):i("",!0):(u(),b(S,{key:0},[l.downloading?(u(),e(h,{key:0,class:"progress-box flex-column"},{default:o(()=>[g(N,{class:"progress",percent:l.downLoadPercent,activeColor:"#3DA7FF","show-info":"","stroke-width":"10"},null,8,["percent"]),g(h,{style:{width:"100%","font-size":"28rpx",display:"flex","justify-content":"space-around"}},{default:o(()=>[g(c,null,{default:o(()=>[P(m(l.downLoadingText),1)]),_:1}),g(c,null,{default:o(()=>[P("("+m(l.downloadedSize)+"/"+m(l.packageFileSize)+"M)",1)]),_:1})]),_:1})]),_:1})):(u(),e(v,{key:1,class:"content-button",style:{border:"none",color:"#fff"},plain:"",onClick:r.updateApp},{default:o(()=>[P(m(l.downLoadBtnText),1)]),_:1},8,["onClick"]))],64))],64))]),_:1})]),_:1}),l.is_mandatory?i("",!0):(u(),e(d,{key:0,class:"close-img",src:"/uni_modules/uni-upgrade-center-app/static/app/app_update_close.png",onClick:L(r.closeUpdate,["stop"])},null,8,["onClick"]))]),_:1})]),_:1})):i("",!0)}],["__scopeId","data-v-4c67c0d4"]]);export{C as default};