diff --git a/App.vue b/App.vue
index 3c19485..10c04bf 100644
--- a/App.vue
+++ b/App.vue
@@ -5,8 +5,9 @@
import {
version
} from './package.json'
- 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 { USERKEY, COMMONKEY } from "@/store/actionKey"
+ import { checkUpdate } from "@/common/appUpdate"
export default {
globalData: {
@@ -27,9 +28,11 @@
console.log('App Launch');
// #ifdef APP-PLUS
// App平台检测升级,服务端代码是通过uniCloud的云函数实现的,详情可参考:https://ext.dcloud.net.cn/plugin?id=4542
- if (plus.runtime.appid !== 'HBuilder') { // 真机运行不需要检查更新,真机运行时appid固定为'HBuilder',这是调试基座的appid
- checkUpdate()
- }
+ // if (plus.runtime.appid !== 'HBuilder') { // 真机运行不需要检查更新,真机运行时appid固定为'HBuilder',这是调试基座的appid
+ // checkUpdate()
+ // }
+
+ checkUpdate()
// 一键登录预登陆,可以显著提高登录速度
uni.preLogin({
diff --git a/common/appUpdate/index.js b/common/appUpdate/index.js
new file mode 100644
index 0000000..a181e28
--- /dev/null
+++ b/common/appUpdate/index.js
@@ -0,0 +1,106 @@
+import { confirmModal, showLoading, hideLoading, showToast } from "@/common/untool"
+
+export const getSystemInfo = ()=> {
+ let info = uni.getSystemInfoSync()
+ console.log('getSystemInfo=====', info)
+ return info
+}
+
+export const getCurrentAppInfo = ()=> {
+ return new Promise((resolve, reject)=> {
+ // 保存 app 版本信息
+ // #ifdef APP-PLUS
+ plus.runtime.getProperty(plus.runtime.appid, (widgetInfo)=> {
+ console.log('plus.runtime.appid=========', plus.runtime.appid);
+ console.log('widgetInfo=========', widgetInfo);
+ widgetInfo._appVersion = `${widgetInfo.version}.${widgetInfo.versionCode}`
+ resolve(widgetInfo)
+ });
+ // #endif
+ })
+}
+
+const installNewApk = (url)=> {
+ return new Promise((resolve, reject)=> {
+ let downInstance = uni.downloadFile({
+ url: url,
+ success: (downloadResult) => {
+ hideLoading()
+ if (downloadResult.statusCode === 200) {
+ showLoading('正在安装...')
+ plus.runtime.install(downloadResult.tempFilePath, {
+ force: true
+ }, function() {
+ hideLoading()
+ console.log('install success...');
+ plus.runtime.restart();
+ resolve()
+ }, function(e) {
+ hideLoading()
+ console.error('install fail...');
+ reject()
+ });
+ } else {
+ reject()
+ }
+ },
+ fail: (err)=> {
+ console.log('download file err...', err);
+ hideLoading()
+ }
+ });
+ downInstance.onProgressUpdate((res)=> {
+ let { totalBytesExpectedToWrite, totalBytesWritten } = res
+ let percent = (totalBytesWritten / totalBytesExpectedToWrite) * 100
+ showLoading(`下载进度:${parseInt(percent)}%`)
+ })
+ })
+}
+
+const getLastAppInfo = async (curAppInfo)=> {
+ return {
+ version: '1.0.1',
+ versionCode: 101,
+ apkUrl: '',
+ wgtUrl: '',
+ // whiteDeviceIds: ['F9E778C90D0E9A8DA9D95AA97B00A3FB'],
+ }
+}
+
+const compareInfo = (curAppInfo, lastAppInfo)=> {
+ let hasNewVersion = false
+ let url = ''
+ // 强制更新app
+ if(lastAppInfo.version && curAppInfo.version != lastAppInfo.version) {
+ hasNewVersion = true
+ url = lastAppInfo.apkUrl
+ }
+ // 热更新
+ if(!url && lastAppInfo.versionCode && curAppInfo.versionCode != lastAppInfo.versionCode) {
+ hasNewVersion = true
+ url = lastAppInfo.wgtUrl
+ }
+ // 判断是否走白名单更新
+ if(lastAppInfo.whiteDeviceIds?.length > 0) {
+ let sysInfo = getSystemInfo()
+ hasNewVersion = lastAppInfo.whiteDeviceIds.indexOf(sysInfo?.deviceId) > -1
+ }
+
+ return {
+ hasNewVersion,
+ url,
+ lastAppInfo
+ }
+}
+
+export const checkUpdate = async ()=> {
+ let curAppInfo = await getCurrentAppInfo()
+ let lastAppInfo = await getLastAppInfo(curAppInfo)
+ let cmpRes = await compareInfo(curAppInfo, lastAppInfo)
+ if(cmpRes.hasNewVersion) {
+ let fmBl = confirmModal(`app最新版本:${cmpRes.lastAppInfo.version}.${cmpRes.lastAppInfo.versionCode}, 是否更新?`)
+ if(fmBl) {
+ await installNewApk(cmpRes.url)
+ }
+ }
+}
\ No newline at end of file
diff --git a/pages/tabBar/mine/mine.vue b/pages/tabBar/mine/mine.vue
index 848d8c8..f0fec6d 100644
--- a/pages/tabBar/mine/mine.vue
+++ b/pages/tabBar/mine/mine.vue
@@ -64,7 +64,18 @@
-
+
+
+
+
+
+
+
+
+
+
+
+ {{curDeviceId}}
@@ -117,6 +128,7 @@
import { dealBtnMap } from "@/common/enum"
import * as apiService from "@/common/api"
import { getAuthList, authCodeEnum } from "@/common/authCode"
+ import { getCurrentAppInfo, getSystemInfo } from "@/common/appUpdate"
export default {
computed: {
@@ -152,7 +164,8 @@
orderStat: {},
},
saomiao: true,
-
+ curAppVersion: '',
+ curDeviceId: ''
}
},
@@ -170,6 +183,9 @@
methods: {
async initData(){
this.getAppHomeStatData()
+ let appRes = await getCurrentAppInfo()
+ this.curAppVersion = appRes._appVersion
+ this.curDeviceId = getSystemInfo()?.deviceId
},
async getAppHomeStatData(){
let res = await apiService.getAppHomeStatData()