onLoad() {
//检测更新
this.updateVersion();
},
updateVersion() {
console.log("检查更新》》》》》》》》》》》》》》");
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
let sysInfo;
uni.getSystemInfo({
success: function (res) {
sysInfo = res;
},
});
//sysInfo.appVersion 为当前应用版本号
this.api.request( "xxx/xxxx/xxxx?versionNo=" +
sysInfo.appVersion, null,"get")
.then((res) => {
let that = this;
let resource = res;
if (res.code == 200) {
uni.showModal({
title: "更新提示",
showCancel: false,
confirmText: "确定更新", //只保留确定更新按钮
content: "检测到新版本,需要下载新版本的应用程序",
success: function (res) {
if (res.confirm) {
uni.showLoading({
title: "正在更新...",
});
console.log(resource);
//下载地址根据实际来修改,我这个是拼接前缀的下载地址
let downUrl =
that.api.baseUrl + resource.data.downloadAddress;
console.log("url:" + downUrl);
uni.downloadFile({
url: downUrl,
success: function (downloadResult) {
if (downloadResult.statusCode == 200) {
plus.runtime.install(
downloadResult.tempFilePath,
{
force: false,
},
function () {
uni.hideLoading();
uni.showModal({
confirmText: "重启应用", //只保留确定更新按钮
content: "应用更新完成!",
showCancel: false,
success: function (res) {
console.log(res);
if (res.confirm) {
console.log("安装成功");
plus.runtime.restart();
}
},
});
},
function (e) {
uni.hideLoading();
console.log(e);
console.log("安装失败...");
}
);
}
},
});
}
},
});
} else {
console.log("已经是最新版本,无需更新");
}
});
});
},