downloader(downloadUrl) {
let that = this;
// console.log(downloadUrl);
that.showper = true;
plus.downloader.clear(); //清除下载任务
let dtask = plus.downloader.createDownload(
downloadUrl, {
filename: that.vuex_config.UrlDown_apk
},
(d, status) => {
// 下载完成
if (status == 200) {
uni.showToast({
title: " Download file sucess "+d.filename,
mask: false,
duration: 1000,
});
let installurl=plus.io.convertLocalFileSystemURL(d.filename);
uni.showToast({
title: " File local path "+installurl,
mask: false,
duration: 3500,
});
plus.runtime.install(installurl, {}, {},
(error) => {
uni.showToast({
title: that.$t("common.InstallFailed"),
mask: false,
duration: 3500,
});
}
);
} else {
uni.showToast({
title: that.$t("common.InstallFailed"),
mask: false,
duration: 3500,
});
plus.downloader.clear(); //清除下载任务
}
}
);
dtask.addEventListener("statechanged", (download, status) => {
switch (download.state) {
case 1:
uni.showToast({
title: that.$t("common.Downloading"),
});
break;
case 2:
// console.log("链接到服务器...");
break;
case 3:
this.downcurrentSize = download.downloadedSize;
this.downtotalSize = download.totalSize;
this.percent = parseInt(
(parseFloat(this.downcurrentSize) /
parseFloat(this.downtotalSize)) * 100);
// console.log("下载文件百分比..." + this.percent);
//显示的回调函数
// if(cb2) cb2()
break;
case 4:
// console.log("监听下载完成");
plus.nativeUI.closeWaiting();
//回调函数
// if(cb2) cb2()
break;
}
});
dtask.start();
}