const downloadTask = uni.downloadFile({
url: this.upgradeInfo.downloadUrl,
success: (res) => {
if (res.statusCode === 200) {
this.popup.upgradeInfo = "下载成功,正在安装..."
//console.log('下载成功');
//console.log(res.tempFilePath);
plus.runtime.install(res.tempFilePath, {}, function() {
//进行重新启动;
plus.runtime.restart();
}, (e) => {
this.popup.upgradeInfo = '安装升级包失败:' + JSON.stringify(e)
});
}
},
fail: (res) => {
console.log("下载失败");
}
});  
                downloadTask.onProgressUpdate((res) => {  
                    let curDownload = !isNaN(res.totalBytesWritten) ? parseInt(res.totalBytesWritten) : 0;  
                    let total = !isNaN(res.totalBytesExpectedToWrite) ? parseInt(res.totalBytesExpectedToWrite) : 0;  
                    let info = "";  
                    if(total > 0) {  
                        info = this.$fk.statFileSize(curDownload) + " / " + this.$fk.statFileSize(total);  
                    } else {  
                        info = this.$fk.statFileSize(curDownload);  
                    }  
                    this.popup.upgradeInfo = "已下载:" + info  
                    //console.log('下载进度:' + res.progress);  
                    //console.log('已经下载的数据长度' + res.totalBytesWritten);    
                    //console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);  
                }); 
             
             
             
			 
                                        
                                     
            
1 个回复
DCloud_UNI_Anne
文档示例测试未复现此问题,请升级至HBuilder X3.6.1-alpha试下