门店端优化
This commit is contained in:
@@ -1,37 +1,14 @@
|
||||
<script>
|
||||
import { hasValidToken, redirectToLogin } from './api/utils/auth';
|
||||
import { appApi } from './api/modules/app';
|
||||
import UpdateModal from './components/UpdateModal.vue';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
UpdateModal
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
// #ifdef APP-PLUS
|
||||
// 更新弹窗相关数据(仅APP端)
|
||||
showUpdateModal: false,
|
||||
updateInfo: {
|
||||
version: '',
|
||||
updateContent: '',
|
||||
downloadUrl: '',
|
||||
forceUpdate: false
|
||||
}
|
||||
// #endif
|
||||
};
|
||||
},
|
||||
onLaunch: function() {
|
||||
console.log('App Launch');
|
||||
// 检测APP更新
|
||||
this.checkAppUpdate();
|
||||
// 全局检查token
|
||||
this.checkToken();
|
||||
},
|
||||
onShow: function() {
|
||||
console.log('App Show');
|
||||
// 每次显示时检测APP更新
|
||||
this.checkAppUpdate();
|
||||
// 应用恢复时再次检查token
|
||||
this.checkToken();
|
||||
},
|
||||
@@ -44,69 +21,12 @@
|
||||
// 获取当前页面
|
||||
const pages = getCurrentPages();
|
||||
const currentPage = pages.length ? pages[pages.length - 1] : null;
|
||||
const currentRoute = currentPage ? currentPage.route : '';
|
||||
|
||||
// 如果token无效且不在登录页面,则跳转到登录页面
|
||||
if (!hasValidToken() && currentRoute && currentRoute !== 'pages/login/index') {
|
||||
console.log('Token无效,从', currentRoute, '重定向到登录页面');
|
||||
if (!hasValidToken() && currentPage && currentPage.route !== 'pages/login/index') {
|
||||
redirectToLogin();
|
||||
}
|
||||
},
|
||||
|
||||
// 检测APP更新
|
||||
async checkAppUpdate() {
|
||||
// #ifdef APP-PLUS
|
||||
try {
|
||||
console.log('开始检测APP更新...');
|
||||
const res = await appApi.checkUpdate();
|
||||
console.log('更新检测结果:', res);
|
||||
|
||||
if (res.code === 200 && res.data) {
|
||||
const data = res.data;
|
||||
|
||||
// 清理 downloadUrl 中的换行符
|
||||
const downloadUrl = data.downloadUrl ? data.downloadUrl.trim() : '';
|
||||
|
||||
// 设置更新信息
|
||||
this.updateInfo = {
|
||||
version: data.version || '',
|
||||
updateContent: data.updateContent || '本次更新包含性能优化和问题修复',
|
||||
downloadUrl: downloadUrl,
|
||||
forceUpdate: data.forceUpdate || false
|
||||
};
|
||||
|
||||
// 显示更新弹窗
|
||||
this.showUpdateModal = true;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('检测更新失败:', error);
|
||||
// 更新检测失败不影响应用正常使用,只记录日志
|
||||
}
|
||||
// #endif
|
||||
},
|
||||
|
||||
// 处理更新确认
|
||||
handleUpdateConfirm(downloadUrl) {
|
||||
// #ifdef APP-PLUS
|
||||
if (downloadUrl) {
|
||||
plus.runtime.openURL(downloadUrl);
|
||||
}
|
||||
// #endif
|
||||
this.showUpdateModal = false;
|
||||
},
|
||||
|
||||
// 处理更新取消
|
||||
handleUpdateCancel() {
|
||||
if (this.updateInfo.forceUpdate) {
|
||||
// 强制更新时,取消则退出应用
|
||||
// #ifdef APP-PLUS
|
||||
plus.runtime.quit();
|
||||
// #endif
|
||||
} else {
|
||||
// 关闭弹窗
|
||||
this.showUpdateModal = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,21 +59,6 @@
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- #ifdef APP-PLUS -->
|
||||
<!-- 更新弹窗(仅APP端) -->
|
||||
<UpdateModal
|
||||
:show="showUpdateModal"
|
||||
:version="updateInfo.version"
|
||||
:updateContent="updateInfo.updateContent"
|
||||
:downloadUrl="updateInfo.downloadUrl"
|
||||
:forceUpdate="updateInfo.forceUpdate"
|
||||
@confirm="handleUpdateConfirm"
|
||||
@cancel="handleUpdateCancel"
|
||||
/>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<style lang="scss">
|
||||
/*每个页面公共css */
|
||||
@import 'uview-ui/index.scss';
|
||||
|
||||
Reference in New Issue
Block a user