html進度條代碼:html
<template> <div id="app" > <div v-show='proess' style="position: fixed;bottom:73px;left:0;width: 100%; z-index: 9999; "> <div style="width: 80%;margin: 0 auto; position: relative;"> <mt-progress :value="progressVal" :bar-height="5"></mt-progress> <p class="color-white">正在更新{{progressVal}}%</p> </div> </div> </div> </template> <script> export default { name: 'app', data() { return { progressVal:'0',proess:false } }, methods:{ // 下載wgt文件 downWgt(wgtUrl) { var that=this; that.proess=true; var dtask =plus.downloader.createDownload(wgtUrl, { filename: "_doc/update/" }, function(d, status) { console.log("下載和更新成功:" + d.filename); if (status == 200) { that.installWgt(d.filename); // 安裝wgt資源包 } else { console.log("下載更新失敗:" + d.filename); plus.nativeUI.toast("下載更新失敗!"); } that.proess=false; }) dtask.addEventListener("statechanged", function(task, status){ if(task.state==3){ var progressVals = (task.downloadedSize / task.totalSize) * 100; that.progressVal=parseInt(progressVals); } }, false); dtask.start(); }, installWgt(path) { // 更新應用資源 plus.nativeUI.showWaiting("安裝更新"); plus.runtime.install(path, {}, function() { plus.nativeUI.closeWaiting(); console.log("安裝和更新成功!"); plus.nativeUI.alert("更新已完成!", function() { // 更新完成後重啓應用 plus.runtime.restart(); }); }, function(e) { plus.nativeUI.closeWaiting(); plus.nativeUI.toast("安裝更新失敗![" + e.code + "]:" + e.message); }); }, } },mounted() { mui.plusReady(function() { plus.runtime.getProperty(plus.runtime.appid, function(inf) { var wgtVer = inf.version; //當前版本號 localStorage.setItem('dwgtVer', inf.version) //plus.nativeUI.toast("當前系統版本是什麼" + wgtVer); that.axios.get('version/update', { params: { version: wgtVer } }) .then(function(data) { console.log(JSON.stringify(data.data)); var datas=data.data; //wgtVer當前版本號 datas.version.versionNo最新版本號 var wgtVerattr = localStorage.getItem('wgtVer'); if(that.toNum(wgtVer)<that.toNum(datas.version.versionNo)){ if ((wgtVerattr == null || wgtVerattr == undefined) || wgtVerattr != data.version.versionNo) { if (datas.version.versionNo != wgtVer) { if (datas.version.forcedUpdate == 1) { //強制更新 //forcedUpdate ==1是強制更新 ==0是不強制更新 if (datas.version != null && datas.version != "") { mui.alert('檢測到新版本'+datas.version.versionNo, '提示', function() { that.downWgt(datas.version.path); // 下載wgt資源包 }); } } else if (datas.version.forcedUpdate == 0) { //不強制更新 var btnArray = ['取消', '肯定']; mui.confirm('檢測到新版本'+datas.version.versionNo+',是否進行升級?', '提示', btnArray, function(e) { if (e.index == 1) { //點擊肯定 that.downWgt(datas.version.path); // 下載wgt資源包 } else { localStorage.setItem('wgtVer', datas.version.versionNo); //點擊取消 /* that.proess=false; that.hiddees=false; localStorage.setItem('wgtVer', datas.version.versionNo);*/ } }) } } } } }) .catch(function(error) { console.log(error); }) }) }) } } </script>