提交 db11835d 编写于 作者: 芊里

检查更新完成

上级 e89739ed
// #ifdef APP-PLUS
import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'; import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update';
import callCheckVersion from '@/uni_modules/uni-upgrade-center-app/utils/call-check-version';
// #endif
export default function() { export default function() {
// 初始化appVersion // 初始化appVersion
...@@ -21,16 +24,25 @@ function initAppVersion() { ...@@ -21,16 +24,25 @@ function initAppVersion() {
// #ifdef APP-PLUS // #ifdef APP-PLUS
let appid = plus.runtime.appid; let appid = plus.runtime.appid;
plus.runtime.getProperty(appid, (wgtInfo) => { plus.runtime.getProperty(appid, (wgtInfo) => {
wgtInfo.version
let appVersion = plus.runtime; let appVersion = plus.runtime;
let currentVersion = appVersion.versionCode > wgtInfo.versionCode ? appVersion : wgtInfo;
getApp({ getApp({
allowDefault: true allowDefault: true
}).appVersion = { }).appVersion = {
...currentVersion,
appid, appid,
version: appVersion, hasNew:true
wgtVersion: wgtInfo,
finall: appVersion.versionCode > wgtInfo.versionCode ? appVersion : wgtInfo
} }
// 检查更新小红点
callCheckVersion()
.then(res=>{
if(res.result.code>0){
// 有新版本
getApp({
allowDefault: true
}).appVersion.hasNew = true;
}
})
}); });
// #endif // #endif
} }
......
...@@ -20,7 +20,12 @@ ...@@ -20,7 +20,12 @@
:clickable="true" :clickable="true"
:to="item.to" :to="item.to"
@click="ucenterListClick(item)" @click="ucenterListClick(item)"
></uni-list-item> >
<view v-if="item.showBadge" class="item-footer" slot="footer">
<text class="item-footer-text">{{item.rightText}}</text>
<view class="item-footer-badge"></view>
</view>
</uni-list-item>
</uni-list> </uni-list>
</view> </view>
</template> </template>
...@@ -74,8 +79,9 @@ ...@@ -74,8 +79,9 @@
//#ifdef APP-PLUS //#ifdef APP-PLUS
{ {
title: '检查更新', title: '检查更新',
rightText: `V${getApp().appVersion.finall.version}_${getApp().appVersion.finall.versionCode}`, rightText: `V${getApp().appVersion.version}_${getApp().appVersion.versionCode}`,
event:'checkVersion' event:'checkVersion',
showBadge:true
} }
//#endif //#endif
], ],
...@@ -251,5 +257,25 @@ ...@@ -251,5 +257,25 @@
transform: scaleY(0.2); transform: scaleY(0.2);
} }
/* #endif */ /* #endif */
.item-footer{
flex-direction: row;
align-items: center;
}
.item-footer-text{
color: #999;
font-size: 24rpx;
padding-right: 10rpx;
}
.item-footer-badge{
width: 20rpx;
height: 20rpx;
/* #ifndef APP-NVUE */
border-radius: 50%;
/* #endif */
/* #ifdef APP-NVUE */
border-radius: 10rpx;
/* #endif */
background-color: #DD524D;
}
</style> </style>
## 0.1.4(2021-04-13)
- 更新文档。明确云函数调用结果
## 0.1.3(2021-04-13)
- 解耦云函数与弹框处理。utils中新增 call-check-version.js,可用于单独检测是否有更新
## 0.1.2(2021-04-07) ## 0.1.2(2021-04-07)
- 更新版本对比函数 compare - 更新版本对比函数 compare
## 0.1.1(2021-04-07) ## 0.1.1(2021-04-07)
......
{ {
"id": "uni-upgrade-center-app", "id": "uni-upgrade-center-app",
"displayName": "升级中心 uni-upgrade-center - App", "displayName": "升级中心 uni-upgrade-center - App",
"version": "0.1.2", "version": "0.1.4",
"description": "升级中心前台检查更新", "description": "升级中心前台检查更新",
"keywords": [ "keywords": [
"uniCloud", "uniCloud",
......
...@@ -71,11 +71,18 @@ ...@@ -71,11 +71,18 @@
6. 检查更新前端使用示例:`uni_modules/uni-upgrade-center-app/utils/check-update.js`,在要检查更新的地方导入调用即可 6. 检查更新前端使用示例:`uni_modules/uni-upgrade-center-app/utils/check-update.js`,在要检查更新的地方导入调用即可
**Tips**
1. `check-version`云函数内部有版本对比函数(compare)。
- 使用多段式版本格式(如:"3.0.0.0.0.1.0.1", "3.0.0.0.0.1")。如果不满足对比规则,请自行修改。
- 如果修改,请将*pages/upgrade-popup.vue**compare*函数一并修改
## 项目代码说明 ## 项目代码说明
### 更新弹框 ### 更新弹框
- `upgrade-popup.vue` - 更新应用: - `upgrade-popup.vue` - 更新应用:
- 如果`check-version`返回的参数表明需要更新,则将参数保存在localStorage中,带着键值跳转该页面 - 如果云函数`check-version`返回的参数表明需要更新,则将参数保存在localStorage中,带着键值跳转该页面
- 进入时会先从localStorage中尝试取出之前存的安装包路径(此包不会是强制安装类型的包) - 进入时会先从localStorage中尝试取出之前存的安装包路径(此包不会是强制安装类型的包)
- 如果有已经保存的包,则和传进来的 `version` 进行比较,如果相等则安装。大于和小于都不进行安装,因为admin端可能会调整包的版本。不符合更新会将此包删除 - 如果有已经保存的包,则和传进来的 `version` 进行比较,如果相等则安装。大于和小于都不进行安装,因为admin端可能会调整包的版本。不符合更新会将此包删除
- 如果本地没有包或者包不符合安装条件,则进行下载安装包 - 如果本地没有包或者包不符合安装条件,则进行下载安装包
...@@ -86,6 +93,12 @@ ...@@ -86,6 +93,12 @@
- 下载过程中,如果退出会提示是否取消下载。如果是强制更新,则只会提示正在下载请稍后,此时不可退出 - 下载过程中,如果退出会提示是否取消下载。如果是强制更新,则只会提示正在下载请稍后,此时不可退出
- 如果是下载完成了没有安装就退出,则会将下载完成的包保存在本地。将包的本地路径和包version保存在localStorage中 - 如果是下载完成了没有安装就退出,则会将下载完成的包保存在本地。将包的本地路径和包version保存在localStorage中
### 工具类 utils
- `call-check-version`
- 请求云函数`check-version`拿取版本检测结果
- `check-update`
- 调用`call-check-version`并根据结果判断是否显示更新弹框
### 云函数 ### 云函数
- `check-version` - 检查应用更新: - `check-version` - 检查应用更新:
- 根据传参,先检测传参是否完整,appid appVersion wgtVersion 必传 - 根据传参,先检测传参是否完整,appid appVersion wgtVersion 必传
...@@ -93,3 +106,11 @@ ...@@ -93,3 +106,11 @@
- 再从所有线上发行更新中取出版本最大的一版。如果可以,尽量先检测wgt的线上发行版更新 - 再从所有线上发行更新中取出版本最大的一版。如果可以,尽量先检测wgt的线上发行版更新
- 使用上一步取出的版本包的版本号 和传参 appVersion、wgtVersion 来检测是否有更新。必须同时大于这两项,因为上一次可能是wgt热更新,否则返回暂无更新 - 使用上一步取出的版本包的版本号 和传参 appVersion、wgtVersion 来检测是否有更新。必须同时大于这两项,因为上一次可能是wgt热更新,否则返回暂无更新
- 如果库中 wgt包 版本大于传参 appVersion,但是不满足 min_uni_version < appVersion,则不会使用wgt更新,会接着判断库中 app包version 是否大于 appVersion - 如果库中 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
export default function() {
// #ifdef APP-PLUS
return new Promise((resolve, reject) => {
plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
uniCloud.callFunction({
name: 'check-version',
data: {
appid: plus.runtime.appid,
appVersion: plus.runtime.version,
wgtVersion: widgetInfo.version
},
success: (e) => {
resolve(e)
},
fail: (error) => {
reject(error)
}
})
})
})
// #endif
// #ifndef APP-PLUS
return new Promise((resolve, reject) => {
reject({
message: '请在App中使用'
})
})
// #endif
}
import callCheckVersion from './call-check-version'
// 推荐再App.vue中使用 // 推荐再App.vue中使用
const PACKAGE_INFO_KEY = '__package_info__' const PACKAGE_INFO_KEY = '__package_info__'
export default function() { export default function() {
// #ifdef APP-PLUS // #ifdef APP-PLUS
plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) { callCheckVersion().then(async (e) => {
uniCloud.callFunction({
name: 'check-version',
data: {
appid: plus.runtime.appid,
appVersion: plus.runtime.version,
wgtVersion: widgetInfo.version
},
success: async (e) => {
if (!e.result) return; if (!e.result) return;
const { const {
code, code,
...@@ -70,13 +64,10 @@ export default function() { ...@@ -70,13 +64,10 @@ export default function() {
// TODO 云函数报错处理 // TODO 云函数报错处理
console.error(message) console.error(message)
} }
}, }).catch(err => {
fail: (err) => {
// TODO 云函数报错处理 // TODO 云函数报错处理
console.error(err.message) console.error(err.message)
}
}) })
});
// #endif // #endif
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册