Commit eea5c357 by liangjianmin

删除更新逻辑

parent 90e10a07
<script> <script>
import { API, ENV } from '@/util/api.js';
import { compareVersion, showUpdateModal } from '@/util/util.js';
export default { export default {
data() { data() {
return { return {};
localVersion: '', // 本地版本号
onlineVersion: '' // 线上版本号
};
}, },
onLaunch: function() { onLaunch: function() {
}, },
onShow: function() { onShow: function() {},
// 测试环境不检查更新
if (ENV === 'production') {
this.checkAppUpdate();
}
},
onHide: function() { onHide: function() {
}, },
methods: { methods: {}
/**
* 检查应用更新
* 使用 plus.runtime.getProperty 获取 manifest.json 中的 versionName
*/
checkAppUpdate() {
// #ifdef APP-PLUS
plus.runtime.getProperty(plus.runtime.appid, (info) => {
this.localVersion = info.version || '1.0.0';
this.doCheckUpdate();
});
// #endif
// #ifndef APP-PLUS
this.localVersion = '1.0.0';
this.doCheckUpdate();
// #endif
},
/**
* 执行版本检查
*/
doCheckUpdate() {
this.request(API.appVersionList, 'GET', {}, true).then(res => {
if (res.code === 0) {
this.onlineVersion = res.data.list[0].version;
var downloadUrl = res.data.list[0].download_url || '';
var remark = res.data.list[0].remark || '发现新版本,是否更新?';
console.log(`[版本检查] 本地版本: ${this.localVersion}, 线上版本: ${this.onlineVersion}`);
// 比较版本号
if (!compareVersion(this.localVersion, this.onlineVersion)) {
// 需要更新
showUpdateModal(remark, downloadUrl, this.onlineVersion, () => {
// 更新回调,无需更新本地版本变量,因为版本号来自 APP 配置
});
}
}
}).catch(err => {
console.log('检查更新失败:', err);
});
}
}
}; };
</script> </script>
......
<template> <template>
<view class="home-index"> <view class="home-index">
<!-- 更新弹窗 -->
<UpdateModal ref="updateModal" @confirm="onUpdateConfirm" @cancel="onUpdateCancel" />
<!-- 骨架屏 --> <!-- 骨架屏 -->
<view class="skeleton-head" v-if="loading"> <view class="skeleton-head" v-if="loading">
<view class="skeleton-avatar"></view> <view class="skeleton-avatar"></view>
...@@ -113,13 +111,8 @@ ...@@ -113,13 +111,8 @@
<script> <script>
import { API } from '@/util/api.js'; import { API } from '@/util/api.js';
import { compareVersion } from '@/util/util.js';
import UpdateModal from '@/components/UpdateModal.vue';
export default { export default {
components: {
UpdateModal
},
data() { data() {
return { return {
info: {}, info: {},
...@@ -139,14 +132,17 @@ ...@@ -139,14 +132,17 @@
// #ifdef APP-PLUS // #ifdef APP-PLUS
uni.vibrateShort(); uni.vibrateShort();
// #endif // #endif
Promise.all([this.getData(), this.getStayHandleCount()]).finally(() => {
this.checkAppUpdate(); uni.stopPullDownRefresh();
this.getData(); });
this.getStayHandleCount();
}, },
methods: { methods: {
/**
* 获取首页统计数据
* @return {Promise}
*/
getData() { getData() {
this.request(API.getStatisticsInfo, 'POST', {}, false).then(res => { return this.request(API.getStatisticsInfo, 'POST', {}, false).then(res => {
if (res.code === 0) { if (res.code === 0) {
this.info = res.data; this.info = res.data;
uni.setStorageSync('email', res.data.user_info.email); uni.setStorageSync('email', res.data.user_info.email);
...@@ -157,9 +153,10 @@ ...@@ -157,9 +153,10 @@
}, },
/** /**
* 获取待处理数量统计 * 获取待处理数量统计
* @return {Promise}
*/ */
getStayHandleCount() { getStayHandleCount() {
this.request(API.getStayHandleCount, 'POST', {}, false).then(res => { return this.request(API.getStayHandleCount, 'POST', {}, false).then(res => {
if (res.code === 0) { if (res.code === 0) {
// 处理新的数据结构 // 处理新的数据结构
this.abnormal_num = res.data.abnormal_num || 0; this.abnormal_num = res.data.abnormal_num || 0;
...@@ -173,58 +170,6 @@ ...@@ -173,58 +170,6 @@
}); });
}, },
/** /**
* 检查应用更新
*/
checkAppUpdate() {
// #ifdef APP-PLUS
plus.runtime.getProperty(plus.runtime.appid, (info) => {
var localVersion = info.version || '1.0.0';
this.doCheckUpdate(localVersion);
});
// #endif
// #ifndef APP-PLUS
this.doCheckUpdate('1.0.0');
// #endif
},
/**
* 执行版本检查
*/
doCheckUpdate(localVersion) {
this.request(API.appVersionList, 'GET', {}, true).then(res => {
uni.stopPullDownRefresh();
if (res.code === 0) {
var onlineVersion = res.data.list[0].version;
var downloadUrl = res.data.list[0].download_url || '';
var remark = res.data.list[0].remark || '发现新版本,是否更新?';
console.log(`[版本检查] 本地版本: ${localVersion}, 线上版本: ${onlineVersion}`);
// 比较版本号,不一致则提示更新
if (!compareVersion(localVersion, onlineVersion)) {
this.$refs.updateModal.show(remark, downloadUrl, onlineVersion);
} else {
uni.showToast({
title: '已是最新版本',
icon: 'none'
});
}
}
}).catch(err => {
uni.stopPullDownRefresh();
console.log('检查更新失败:', err);
});
},
/**
* 更新确认回调
*/
onUpdateConfirm() {
console.log('用户确认更新');
},
/**
* 更新取消回调
*/
onUpdateCancel() {
console.log('用户取消更新');
},
/**
* 退出系统 * 退出系统
*/ */
exit() { exit() {
......
<template> <template>
<view class="page-auth column rowCenter verCenter"> <view class="page-auth column rowCenter verCenter">
<!-- 更新弹窗 -->
<UpdateModal ref="updateModal" @confirm="onUpdateConfirm" />
<text class="logo"></text> <text class="logo"></text>
<text class="title">供应链商务系统</text> <text class="title">供应链商务系统</text>
<view class="form-box column rowCenter verCenter"> <view class="form-box column rowCenter verCenter">
...@@ -19,41 +17,22 @@ ...@@ -19,41 +17,22 @@
{{ isLoading ? '登录中' : '登录' }} {{ isLoading ? '登录中' : '登录' }}
</button> </button>
</view> </view>
<view class="update-btn-box row rowCenter">
<view class="update-btn row rowCenter verCenter" @click="checkUpdate()">检查更新
<text class="red-dot" v-if="hasUpdate"></text>
</view>
</view>
<view class="copyright">©{{ currentYear }} 深圳市猎芯供应链有限公司 ALL RIGHTS RESERVED</view> <view class="copyright">©{{ currentYear }} 深圳市猎芯供应链有限公司 ALL RIGHTS RESERVED</view>
<view class="version-bar" v-if="onlineVersion && localVersion !== onlineVersion">
<text class="version-current">v{{ localVersion }}</text>
<text class="version-arrow"></text>
<text class="version-latest">v{{ onlineVersion }}</text>
<text class="version-tag">可更新</text>
</view>
</view> </view>
</template> </template>
<script> <script>
import { API } from '@/util/api.js'; import { API } from '@/util/api.js';
import md5 from '@/util/md5.js'; import md5 from '@/util/md5.js';
import { compareVersion } from '@/util/util.js';
import UpdateModal from '@/components/UpdateModal.vue';
export default { export default {
components: {
UpdateModal
},
data() { data() {
return { return {
name: '', name: '',
passwd: '', passwd: '',
showPassword: false, showPassword: false,
isLoading: false, isLoading: false,
currentYear: new Date().getFullYear(), // 动态获取当前年份 currentYear: new Date().getFullYear() // 动态获取当前年份
localVersion: '', // 本地版本号
onlineVersion: '', // 线上版本号
hasUpdate: false // 是否有更新
}; };
}, },
onLoad() { onLoad() {
...@@ -69,107 +48,21 @@ ...@@ -69,107 +48,21 @@
this.name = savedName; this.name = savedName;
this.passwd = savedPasswd; this.passwd = savedPasswd;
} }
// 获取APP版本号
this.getAppVersion();
// 页面加载时静默检查更新
this.silentCheckUpdate();
},
onShow() {
// 可以根据需要决定是否在页面显示时自动检查更新
}, },
onShow() {},
methods: { methods: {
/** /**
* 获取APP版本号
* 使用 plus.runtime.getProperty 获取 manifest.json 中配置的 versionName
*/
getAppVersion() {
// #ifdef APP-PLUS
plus.runtime.getProperty(plus.runtime.appid, (info) => {
// info.version 对应 manifest.json 中的 versionName
this.localVersion = info.version || '1.0.0';
});
// #endif
// #ifndef APP-PLUS
this.localVersion = '1.0.0';
// #endif
},
/**
* 检查更新
*/
checkUpdate() {
this.request(API.appVersionList, 'GET', {}, true).then(res => {
uni.hideLoading();
if (res.code === 0) {
this.onlineVersion = res.data.list[0].version;
var downloadUrl = res.data.list[0].download_url || '';
var remark = res.data.list[0].remark || '发现新版本,是否更新?';
// 比较版本号
if (!compareVersion(this.localVersion, this.onlineVersion)) {
// 需要更新,使用自定义弹窗
this.hasUpdate = true;
this.$refs.updateModal.show(remark, downloadUrl, this.onlineVersion);
} else {
// 已是最新版本,提示当前版本号
this.hasUpdate = false;
uni.showModal({
title: '版本检查',
content: `当前已是最新版本\n版本号:v${this.localVersion}`,
showCancel: false,
confirmText: '知道了'
});
}
} else {
uni.showToast({
title: '检查更新失败',
icon: 'error'
});
}
}).catch(err => {
uni.hideLoading();
uni.showToast({
title: '网络异常',
icon: 'error'
});
});
},
/**
* 更新确认回调
*/
onUpdateConfirm() {
this.hasUpdate = false;
},
/**
* 静默检查更新(不显示加载和成功提示)
*/
silentCheckUpdate() {
this.request(API.appVersionList, 'GET', {}, true).then(res => {
if (res.code === 0) {
this.onlineVersion = res.data.list[0].version;
// 比较版本号,如果有更新则显示红点
if (!compareVersion(this.localVersion, this.onlineVersion)) {
this.hasUpdate = true;
} else {
this.hasUpdate = false;
}
}
}).catch(err => {
// 静默失败,不显示错误提示
console.log('静默检查更新失败:', err);
});
},
/**
* 切换密码显示/隐藏 * 切换密码显示/隐藏
* @return {void}
*/ */
togglePassword() { togglePassword() {
this.showPassword = !this.showPassword; this.showPassword = !this.showPassword;
}, },
/**
* 提交登录
* @return {void}
*/
submit() { submit() {
if (this.isLoading) return; if (this.isLoading) return;
...@@ -222,7 +115,7 @@ ...@@ -222,7 +115,7 @@
} }
}).catch(() => { }).catch(() => {
this.isLoading = false; this.isLoading = false;
}) });
} }
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment