From 95597083d7ed9f58f9c5c4f3af9dbe2877dceea2 Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Fri, 8 Dec 2023 15:40:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8D=87=E7=BA=A7=E4=B8=AD=E5=BF=83?= =?UTF-8?q?=E9=80=82=E9=85=8D=E9=80=9A=E7=9F=A5=E6=A0=8F=E8=BF=9B=E5=BA=A6?= =?UTF-8?q?=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uni-upgrade-center-app.uvue | 97 +++++++++++++---- .../uni-upgrade-center-app/package.json | 4 +- .../pages/upgrade-popup.vue | 103 +++++++++++++----- .../utils/call-check-version.ts | 2 +- .../utils/check-update.ts | 18 +++ 5 files changed, 169 insertions(+), 55 deletions(-) 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 99e76e99..e16b5e79 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 8869b744..7bb89a14 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 b82cdc19..d6619345 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 @@