From 1e7a6e0ed0ff38c1f3ce3962062ed45621a36fa2 Mon Sep 17 00:00:00 2001 From: jevononlie <728254585@qq.com> Date: Tue, 14 May 2024 14:37:02 +0800 Subject: [PATCH] no message --- mes-ui/uni-app/src/App.vue | 92 ++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 49 deletions(-) diff --git a/mes-ui/uni-app/src/App.vue b/mes-ui/uni-app/src/App.vue index 273c01a3..8811ff83 100644 --- a/mes-ui/uni-app/src/App.vue +++ b/mes-ui/uni-app/src/App.vue @@ -2,7 +2,7 @@ * @Author: 王文杰 * @Date: 2024-01-04 12:54:56 * @LastEditors: jevononlie 728254585@qq.com - * @LastEditTime: 2024-05-14 13:41:07 + * @LastEditTime: 2024-05-14 14:28:33 * @FilePath: /app-nx-personal/src/App.vue * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE --> @@ -12,66 +12,60 @@ import { appUpdateApi } from '@/services/appUpdate' onLaunch(async () => { console.log('App Launch') //#ifdef APP-PLUS - let version = ''; - plus.runtime.getProperty(plus.runtime.appid, function (wgtinfo) { - if (wgtinfo.version) { - version = wgtinfo.version - } else { - version = plus.runtime.version - } - }); - console.log('App Show-----',version) const params = { //升级检测数据 appId: 'com.chanko.yunxi.mes.android' } const res = await appUpdateApi(params) - console.log('App Show-----', res) - if (res.versionId !== version) { - uni.showModal({ //提醒用户更新 - title: '更新提示', - showCancel: false, - content: res.remark || '有新版本更新,请点击确定下载', - success: (res) => { - if (res.confirm) { - plus.runtime.openURL(res.url); + plus.runtime.getProperty(plus.runtime.appid, function (wgtinfo) { + const version = wgtinfo.version || plus.runtime.version + if (res.versionId !== version) { + uni.showModal({ //提醒用户更新 + title: '版本更新', + showCancel: false, + confirmText: '立即更新', + content: res.remark || 'APP有新版本发布,点击 立即更新 进行最新版本下载。', + success: (res) => { + if (res.confirm) { + onSureClick(res.url) + } } - } - }) - } + }) + } + }) //#endif }) -onShow(() => { +onShow(async () => { + //#ifdef APP-PLUS console.log('App Show') - let version = ''; - plus.runtime.getProperty(plus.runtime.appid, function (wgtinfo) { - if (wgtinfo.version) { - version = wgtinfo.version - } else { - version = plus.runtime.version - } - }); - console.log('App Show-----',version) - const params = { //升级检测数据 - appId: 'com.chanko.yunxi.mes.android' - } - const res = await appUpdateApi(params) - console.log('App Show-----', res) - if (res.versionId !== version) { - uni.showModal({ //提醒用户更新 - title: '更新提示', - showCancel: false, - content: res.remark || '有新版本更新,请点击确定下载', - success: (res) => { - if (res.confirm) { - plus.runtime.openURL(res.url); - } - } - }) - } + //#endif }) onHide(() => { console.log('App Hide') }) +const onSureClick = (upDataUrl) => { + var downloadTask = uni.downloadFile({ + url: upDataUrl, + success: (downloadResult) => { + if (downloadResult.statusCode === 200) { + plus.runtime.install(downloadResult.tempFilePath, { + force: false + }, function () { + plus.runtime.restart(); + }, (e) => { + console.log(e) + uni.showToast({ + title: '安装升级包失败', + icon: 'none' + }) + }); + } + } + }); + // 下载进度变化事件的监听函数 + downloadTask.onProgressUpdate((e) => { + // + }) +}