diff --git a/uni_modules/uni-upgrade-center-app/components/uni-upgrade-center-app/uni-upgrade-center-app.uvue b/uni_modules/uni-upgrade-center-app/components/uni-upgrade-center-app/uni-upgrade-center-app.uvue index 99e76e997c3ddb36ee35bfdf7ad6f16702c03d45..e16b5e793db736a67e987813a17e874199839035 100644 --- a/uni_modules/uni-upgrade-center-app/components/uni-upgrade-center-app/uni-upgrade-center-app.uvue +++ b/uni_modules/uni-upgrade-center-app/components/uni-upgrade-center-app/uni-upgrade-center-app.uvue @@ -46,8 +46,8 @@ {{installing ? '正在安装……' : '下载完成,立即安装'}} - @@ -67,9 +67,11 @@ const localFilePathKey = 'UNI_ADMIN_UPGRADE_CENTER_LOCAL_FILE_PATH' const platform_iOS = 'iOS'; + const platform_Android = 'Android'; const requiredKey = ['version', 'url', 'type'] let downloadTask : DownloadTask | null = null; let openSchemePromise: Promise | null = null; + let notificationAbortDownload: boolean = false /** * 对比版本号,如需要,请自行修改判断规则 @@ -115,6 +117,7 @@ } export default { + emits: ['close'], data() { return { shown: false, @@ -141,23 +144,33 @@ contents: '', version: '', is_mandatory: false, + url: "", + platform: [] as string[], + store_list: null as StoreListItem[] | null, // 可自定义属性 subTitle: '发现新版本', downLoadBtnTextiOS: '立即跳转更新', downLoadBtnText: '立即下载更新', - downLoadingText: '安装包下载中,请稍后', - - url: "", - platform: [] as string[], - store_list: null as StoreListItem[] | null + downLoadingText: '安装包下载中,请稍后' } }, computed: { isiOS() : boolean { return this.platform.includes(platform_iOS); + }, + isAndroid() : boolean { + return this.platform.includes(platform_Android); + }, + needNotificationProgress(): boolean { + return this.isAndroid && !this.is_mandatory } }, + beforeUnmount() { + if (this.needNotificationProgress) { + uni.cancelNotificationProgress() + } + }, methods: { show(shown : boolean, localPackageInfo : UniUpgradeCenterResult | null) { if (localPackageInfo === null) return; @@ -181,6 +194,19 @@ this.store_list = localPackageInfo.store_list this.shown = shown }, + askAbortDownload() { + uni.showModal({ + title: '是否取消下载?', + cancelText: '否', + confirmText: '是', + success: res => { + if (res.confirm) { + if (downloadTask !== null) downloadTask!.abort() + this.closePopup() + } + } + }); + }, closeUpdate() { if (this.downloading) { if (this.is_mandatory) { @@ -190,18 +216,10 @@ duration: 500 }) } - uni.showModal({ - title: '是否取消下载?', - cancelText: '否', - confirmText: '是', - success: res => { - if (res.confirm) { - if (downloadTask !== null) downloadTask!.abort() - this.closePopup() - } - } - }); - return; + if (!this.needNotificationProgress) { + this.askAbortDownload() + return; + } } this.closePopup() }, @@ -222,7 +240,11 @@ this.installed = false this.showTabbar = false - this.$emit('close') + if (this.needNotificationProgress) uni.cancelNotificationProgress() + + if (!notificationAbortDownload) this.$emit('close') + + notificationAbortDownload = false }, updateApp() { const checkStoreScheme = this.checkStoreScheme() @@ -261,7 +283,6 @@ downloadTask = uni.downloadFile({ url: this.url, success: res => { - console.log('downloadFile res: ', res); if (res.statusCode == 200) { this.tempFilePath = res.tempFilePath this.downLoadComplete() @@ -273,10 +294,27 @@ }); if (downloadTask !== null) { this.downloading = true; + if (this.needNotificationProgress) { + this.closePopup() + } downloadTask!.onProgressUpdate(res => { this.downLoadPercent = parseFloat(res.progress.toFixed(0)); this.downloadedSize = parseFloat((res.totalBytesWritten / Math.pow(1024, 2)).toFixed(2)); this.packageFileSize = parseFloat((res.totalBytesExpectedToWrite / Math.pow(1024, 2)).toFixed(2)); + + if (this.needNotificationProgress) { + uni.createNotificationProgress({ + title: "升级中心正在下载安装包……", + content: `${this.downLoadPercent}%`, + progress: this.downLoadPercent, + onClick: () => { + if (!this.downloadSuccess) { + this.askAbortDownload() + notificationAbortDownload = true + } + } + }) + } }); } }, @@ -290,9 +328,20 @@ downloadTask = null; + if (this.needNotificationProgress) { + uni.finishNotificationProgress({ + title: "安装升级包", + content: "下载完成", + onClick(){} + }) + + this.installPackage(); + return + } + // 强制更新,直接安装 if (this.is_mandatory) { - this.installPackage(); + this.installPackage(); } }, installPackage() { @@ -306,7 +355,7 @@ this.installed = true; }, fail: err => { - console.log('installApk fail'); + console.error('installApk fail', err); // 安装失败需要重新下载安装包 this.installing = false; this.installed = false; @@ -319,7 +368,7 @@ } }); - // 非wgt包,安装跳出覆盖安装,此处直接返回上一页 + // 安装跳出覆盖安装,此处直接返回上一页 if (!this.is_mandatory) { uni.navigateBack() } diff --git a/uni_modules/uni-upgrade-center-app/package.json b/uni_modules/uni-upgrade-center-app/package.json index 8869b744c2901aad2bddd4e46ca9d5a62fe6bee2..7bb89a143f205e5f5d8ebadf0b8dcd812d3b90f2 100644 --- a/uni_modules/uni-upgrade-center-app/package.json +++ b/uni_modules/uni-upgrade-center-app/package.json @@ -34,7 +34,9 @@ "type": "unicloud-template-page" }, "uni_modules": { - "dependencies": [], + "dependencies": [ + "uni-progress-notification" + ], "encrypt": [], "platforms": { "cloud": { diff --git a/uni_modules/uni-upgrade-center-app/pages/upgrade-popup.vue b/uni_modules/uni-upgrade-center-app/pages/upgrade-popup.vue index b82cdc1965d68cfd22be0e08e748c6279d321b99..d6619345a4ef76079f26b6a3dd9d9559198468de 100644 --- a/uni_modules/uni-upgrade-center-app/pages/upgrade-popup.vue +++ b/uni_modules/uni-upgrade-center-app/pages/upgrade-popup.vue @@ -10,7 +10,7 @@ {{subTitle}} - + {{version}} @@ -44,8 +44,12 @@ plain :loading="installing" :disabled="installing" @click="installPackage"> {{installing ? '正在安装……' : '下载完成,立即安装'}} + - @@ -62,6 +66,7 @@