var dtask = plus.downloader.createDownload(userl.value, {}, function(d, status) {if (status == 200) { // 下载完成-进行安装console.log('下载status', d, status)// console.log("Download success: " + d.filename);this.show_update = falseplus.runtime.install(d.filename, {force: true}, function() {plus.runtime.restart();}, function(e) {console.log(e)uni.hideLoading()plus.nativeUI.toast("安装失败");});} else {console.log("Download failed: " + status);}});dtask.start();
进度
onProgress(task) { // 获取下载进度console.log('下载中onProgress');this.show_update = truetask.addEventListener('statechanged', e => {console.log('下载中', e)if (e && e.downloadedSize > 0) {const progress = ((e.downloadedSize / e.totalSize) * 100).toFixed(0)console.log('下载中111', progress)this.progress = progress}
p判断版本号是否小于当前线上版本
plus.runtime.getProperty(plus.runtime.appid, function (inf) {console.log('当前应用版本号:', parseInt(inf.versionCode), parseInt(res.data.apkVersion),parseInt(inf.versionCode) < parseInt(res.data.apkVersion))if (parseInt(inf.versionCode) < parseInt(res.data.apkVersion)) {uModal.value.open()console.log(res,"参数--")userl.value=res.data.path}})