|
@@ -42,15 +42,12 @@
|
|
|
} = uni.getAppBaseInfo()
|
|
} = uni.getAppBaseInfo()
|
|
|
if (appVersion != res.versionCode) {
|
|
if (appVersion != res.versionCode) {
|
|
|
uni.showModal({
|
|
uni.showModal({
|
|
|
- title: '发现新版本',
|
|
|
|
|
|
|
+ title: `发现新版本(${res.versionCode})`,
|
|
|
content: '更新说明:' + res.releaseNotes,
|
|
content: '更新说明:' + res.releaseNotes,
|
|
|
confirmText: '立即更新',
|
|
confirmText: '立即更新',
|
|
|
success: (val) => {
|
|
success: (val) => {
|
|
|
if (val.confirm) {
|
|
if (val.confirm) {
|
|
|
- // uni.showLoading({
|
|
|
|
|
- // title: "正在下载安装包...",
|
|
|
|
|
- // mask: true,
|
|
|
|
|
- // });
|
|
|
|
|
|
|
+
|
|
|
const downloadTask = uni.downloadFile({
|
|
const downloadTask = uni.downloadFile({
|
|
|
url: `${Vue.prototype.webviewUrl}/kd-aiot/${res.fileStorePath}`,
|
|
url: `${Vue.prototype.webviewUrl}/kd-aiot/${res.fileStorePath}`,
|
|
|
success: (data) => {
|
|
success: (data) => {
|
|
@@ -75,12 +72,12 @@
|
|
|
force: true
|
|
force: true
|
|
|
},
|
|
},
|
|
|
function() {
|
|
function() {
|
|
|
- uni
|
|
|
|
|
- .hideLoading();
|
|
|
|
|
|
|
+ // uni
|
|
|
|
|
+ // .hideLoading();
|
|
|
},
|
|
},
|
|
|
function() {
|
|
function() {
|
|
|
- uni
|
|
|
|
|
- .hideLoading();
|
|
|
|
|
|
|
+ // uni
|
|
|
|
|
+ // .hideLoading();
|
|
|
uni.showToast({
|
|
uni.showToast({
|
|
|
title: '更新失败',
|
|
title: '更新失败',
|
|
|
icon: 'error'
|
|
icon: 'error'
|
|
@@ -92,23 +89,51 @@
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- downloadTask.onProgressUpdate((res) => {
|
|
|
|
|
- console.log('下载进度:', res)
|
|
|
|
|
- // uni.showModal({
|
|
|
|
|
- // content: '下载进度:' + res.progress + '%',
|
|
|
|
|
- // showCancel: false,
|
|
|
|
|
- // success: (val) => {
|
|
|
|
|
- // if (val.confirm) {
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // })
|
|
|
|
|
- uni.showLoading({
|
|
|
|
|
- title: "正在下载安装包: " + res.progress + "%",
|
|
|
|
|
- mask: true,
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- if (res.progress == 100) {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 先显示初始的loading提示
|
|
|
|
|
+ uni.showLoading({
|
|
|
|
|
+ title: "正在下载安装包: 0%",
|
|
|
|
|
+ mask: true,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 记录上次显示的进度,避免频繁更新
|
|
|
|
|
+ let lastProgress = 0;
|
|
|
|
|
+ let loadingVisible = true;
|
|
|
|
|
+
|
|
|
|
|
+ downloadTask.onProgressUpdate((ress) => {
|
|
|
|
|
+ console.log('下载进度:', ress)
|
|
|
|
|
+
|
|
|
|
|
+ // 只在进度有明显变化(每10%)或者达到100%时更新提示
|
|
|
|
|
+ if ((ress.progress > lastProgress && ress.progress % 10 === 0) || ress.progress === 100) {
|
|
|
|
|
+ // 先隐藏再显示以更新内容
|
|
|
|
|
+ if (loadingVisible) {
|
|
|
|
|
+ uni.hideLoading();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (ress.progress < 100) {
|
|
|
|
|
+ uni.showLoading({
|
|
|
|
|
+ title: "正在下载安装包: " + ress.progress + "%",
|
|
|
|
|
+ mask: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ loadingVisible = true;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ loadingVisible = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ lastProgress = ress.progress;
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ // 确保任务完成时隐藏loading
|
|
|
|
|
+ downloadTask.onStop(() => {
|
|
|
|
|
+ if (loadingVisible) {
|
|
|
|
|
+ uni.hideLoading();
|
|
|
|
|
+ loadingVisible = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ downloadTask.onError(() => {
|
|
|
|
|
+ if (loadingVisible) {
|
|
|
uni.hideLoading();
|
|
uni.hideLoading();
|
|
|
|
|
+ loadingVisible = false;
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|