From 43e66babcf2cd049741473b57f308caa54df8d0e Mon Sep 17 00:00:00 2001 From: linju-json Date: Fri, 23 Apr 2021 00:12:05 +0800 Subject: [PATCH] 123 --- pages/ucenter/ucenter.vue | 15 ++- .../uni-upgrade-center-app/changelog.md | 2 + .../uni-upgrade-center-app/package.json | 2 +- .../pages/upgrade-popup.vue | 7 +- uni_modules/uni-upgrade-center-app/readme.md | 21 +-- .../cloudfunctions/check-version/index.js | 2 +- .../utils/check-update.js | 127 +++++++++--------- 7 files changed, 94 insertions(+), 82 deletions(-) diff --git a/pages/ucenter/ucenter.vue b/pages/ucenter/ucenter.vue index ee65885..dfca1db 100644 --- a/pages/ucenter/ucenter.vue +++ b/pages/ucenter/ucenter.vue @@ -80,12 +80,12 @@ [{ title: '问题与反馈', to: '/uni_modules/uni-feedback/pages/opendb-feedback/list' // /pages/ucenter/uni-feedback/uni-feedback uni_modules/uni-feedback/pages/opendb-feedback/list - }, { - title: '关于', - to: '/pages/ucenter/about/about' }, { title: '设置', to: '/pages/ucenter/settings/settings' + }, { + title: '关于', + to: '/pages/ucenter/about/about' }] ] } @@ -129,7 +129,14 @@ } }, async checkVersion() { - console.log(await callCheckVersion()); + let res = await callCheckVersion() + console.log(res); + if(res.result.code == 0){ + uni.showToast({ + title: res.result.message, + icon: 'none' + }); + } checkUpdate() }, toEdit() { diff --git a/uni_modules/uni-upgrade-center-app/changelog.md b/uni_modules/uni-upgrade-center-app/changelog.md index 74cd62c..fafc47c 100644 --- a/uni_modules/uni-upgrade-center-app/changelog.md +++ b/uni_modules/uni-upgrade-center-app/changelog.md @@ -1,3 +1,5 @@ +## 0.1.5(2021-04-22) +- 更新check-update函数。现在返回一个Promise,有更新时成功回调,其他情况错误回调 ## 0.1.4(2021-04-13) - 更新文档。明确云函数调用结果 ## 0.1.3(2021-04-13) diff --git a/uni_modules/uni-upgrade-center-app/package.json b/uni_modules/uni-upgrade-center-app/package.json index 86cd3b4..ebf2fb1 100644 --- a/uni_modules/uni-upgrade-center-app/package.json +++ b/uni_modules/uni-upgrade-center-app/package.json @@ -1,7 +1,7 @@ { "id": "uni-upgrade-center-app", "displayName": "升级中心 uni-upgrade-center - App", - "version": "0.1.4", + "version": "0.1.5", "description": "升级中心前台检查更新", "keywords": [ "uniCloud", 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 049f714..00d928b 100644 --- a/uni_modules/uni-upgrade-center-app/pages/upgrade-popup.vue +++ b/uni_modules/uni-upgrade-center-app/pages/upgrade-popup.vue @@ -384,11 +384,10 @@ left: 0; top: 0; right: 0; - bottom: 0; - background-color:rgba(0,0,0,.65); + bottom: 0; + background-color: rgba(0, 0, 0, .65); } - - + .botton-radius { border-bottom-left-radius: 30rpx; border-bottom-right-radius: 30rpx; diff --git a/uni_modules/uni-upgrade-center-app/readme.md b/uni_modules/uni-upgrade-center-app/readme.md index 2f6fd08..7f27ea4 100644 --- a/uni_modules/uni-upgrade-center-app/readme.md +++ b/uni_modules/uni-upgrade-center-app/readme.md @@ -11,6 +11,8 @@ - 好看、实用、可自定义、可拓展的前台更新弹框 ## 安装指引 + +0. 依赖数据库`opendb-app-versions`,如果没有此库,请在云服务空间中创建。 1. 使用`HBuilderX 3.1.0+`,因为要使用到`uni_modules` @@ -67,9 +69,7 @@ 4. `wgtVersion` 使用 plus.runtime.getProperty(plus.runtime.appid,(wgtInfo) => { wgtInfo.version }) 获取 -5. `check-version`云函数内部会自动获取 App 平台 - -6. 检查更新前端使用示例:`uni_modules/uni-upgrade-center-app/utils/check-update.js`,在要检查更新的地方导入调用即可 +5. `check-version`云函数内部会自动获取 App 平台 **Tips** @@ -107,10 +107,11 @@ - 使用上一步取出的版本包的版本号 和传参 appVersion、wgtVersion 来检测是否有更新。必须同时大于这两项,因为上一次可能是wgt热更新,否则返回暂无更新 - 如果库中 wgt包 版本大于传参 appVersion,但是不满足 min_uni_version < appVersion,则不会使用wgt更新,会接着判断库中 app包version 是否大于 appVersion - 返回结果: - |code|message| - |:-:|:-:| - |0|当前版本已经是最新的,不需要更新| - |101|wgt更新| - |102|整包更新| - |-101|暂无更新或检查appid是否填写正确| - |-102|请检查传参是否填写正确| \ No newline at end of file + + |code|message| + |:-:|:-:| + |0|当前版本已经是最新的,不需要更新| + |101|wgt更新| + |102|整包更新| + |-101|暂无更新或检查appid是否填写正确| + |-102|请检查传参是否填写正确| \ No newline at end of file diff --git a/uni_modules/uni-upgrade-center-app/uniCloud/cloudfunctions/check-version/index.js b/uni_modules/uni-upgrade-center-app/uniCloud/cloudfunctions/check-version/index.js index 24087d3..2f00ccb 100644 --- a/uni_modules/uni-upgrade-center-app/uniCloud/cloudfunctions/check-version/index.js +++ b/uni_modules/uni-upgrade-center-app/uniCloud/cloudfunctions/check-version/index.js @@ -107,7 +107,7 @@ exports.main = async (event, context) => { return { code: 0, - message: '当前版本已经是最新的,不需要更新' + message: '已经是最新版本' }; } diff --git a/uni_modules/uni-upgrade-center-app/utils/check-update.js b/uni_modules/uni-upgrade-center-app/utils/check-update.js index dcb5027..669210a 100644 --- a/uni_modules/uni-upgrade-center-app/utils/check-update.js +++ b/uni_modules/uni-upgrade-center-app/utils/check-update.js @@ -3,74 +3,77 @@ import callCheckVersion from './call-check-version' // 推荐再App.vue中使用 const PACKAGE_INFO_KEY = '__package_info__' -export default function() { - +export default function () { // #ifdef APP-PLUS - callCheckVersion().then(async (e) => { - if (!e.result) return; - const { - code, - message, - is_silently, // 是否静默更新 - url, // 安装包下载地址 - platform, // 安装包平台 - type // 安装包类型 - } = e.result; - - // 此处逻辑仅为实例,可自行编写 - if (code > 0) { - // 腾讯云和阿里云下载链接不同,需要处理一下,阿里云会原样返回 + return new Promise((resolve, reject) => { + callCheckVersion().then(async (e) => { + if (!e.result) return; const { - fileList - } = await uniCloud.getTempFileURL({ - fileList: [url] - }); - e.result.url = fileList[0].tempFileURL + code, + message, + is_silently, // 是否静默更新 + url, // 安装包下载地址 + platform, // 安装包平台 + type // 安装包类型 + } = e.result; - // 静默更新,只有wgt有 - if (is_silently) { - uni.downloadFile({ - url: e.result.url, - success: res => { - if (res.statusCode == 200) { - // 下载好直接安装,下次启动生效 - plus.runtime.install(res.tempFilePath, { - force: false - }); - } - } + // 此处逻辑仅为实例,可自行编写 + if (code > 0) { + // 腾讯云和阿里云下载链接不同,需要处理一下,阿里云会原样返回 + const { + fileList + } = await uniCloud.getTempFileURL({ + fileList: [url] }); - return; - } - - /** - * 提示升级一 - * 使用 uni.showModal - */ - // return updateUseModal(e.result) + e.result.url = fileList[0].tempFileURL + + resolve(e) - /** - * 提示升级二 - * 官方适配的升级弹窗,可自行替换资源适配UI风格 - */ - uni.setStorageSync(PACKAGE_INFO_KEY, e.result) - uni.navigateTo({ - url: `/uni_modules/uni-upgrade-center-app/pages/upgrade-popup?local_storage_key=${PACKAGE_INFO_KEY}`, - fail: (err) => { - console.error('更新弹框跳转失败', err) - uni.removeStorageSync(PACKAGE_INFO_KEY) + // 静默更新,只有wgt有 + if (is_silently) { + uni.downloadFile({ + url: e.result.url, + success: res => { + if (res.statusCode == 200) { + // 下载好直接安装,下次启动生效 + plus.runtime.install(res.tempFilePath, { + force: false + }); + } + } + }); + return; } - }) - } else if (code < 0) { + + /** + * 提示升级一 + * 使用 uni.showModal + */ + // return updateUseModal(e.result) + + /** + * 提示升级二 + * 官方适配的升级弹窗,可自行替换资源适配UI风格 + */ + uni.setStorageSync(PACKAGE_INFO_KEY, e.result) + uni.navigateTo({ + url: `/uni_modules/uni-upgrade-center-app/pages/upgrade-popup?local_storage_key=${PACKAGE_INFO_KEY}`, + fail: (err) => { + console.error('更新弹框跳转失败', err) + uni.removeStorageSync(PACKAGE_INFO_KEY) + } + }) + } else if (code < 0) { + // TODO 云函数报错处理 + console.error(message) + reject(e) + } + }).catch(err => { // TODO 云函数报错处理 - console.error(message) - } - - - }).catch(err => { - // TODO 云函数报错处理 - console.error(err.message) - }) + console.error(err.message) + reject(err) + }) + }); // #endif } @@ -148,4 +151,4 @@ function updateUseModal(packageInfo) { }); } }); -} +} -- GitLab