| | |
| | | import { getToken } from '@/utils/auth' |
| | | import { getUnreadCount } from '@/api/message' |
| | | import storage from '@/utils/storage' |
| | | import { redirectToLoginByEnvironment } from '@/utils/wechat' |
| | | |
| | | export default { |
| | | data() { |
| | |
| | | lastToken: null // 用于检测 token 变化 |
| | | } |
| | | }, |
| | | onLaunch: function() { |
| | | onLaunch: function(options) { |
| | | this.lastToken = getToken() |
| | | this.initApp() |
| | | this.initApp(options) |
| | | |
| | | // 检查并清理存储空间 |
| | | this.checkStorage() |
| | |
| | | }, |
| | | methods: { |
| | | // 初始化应用 |
| | | initApp() { |
| | | initApp(options) { |
| | | // 初始化应用配置 |
| | | this.initConfig() |
| | | // 检查用户登录状态 |
| | | //#ifdef H5 |
| | | this.checkLogin() |
| | | //#endif |
| | | // 检查用户登录状态并自动跳转到合适的登录页面 |
| | | this.checkLoginAndRedirect(options) |
| | | |
| | | // 注意:不在应用启动时自动启动轮询 |
| | | // 只有在用户主动登录成功后才启动(通过 user-login 事件触发) |
| | |
| | | initConfig() { |
| | | this.globalData.config = config |
| | | }, |
| | | checkLogin() { |
| | | // 检查登录状态并自动跳转到合适的登录页面 |
| | | checkLoginAndRedirect(options) { |
| | | if (!getToken()) { |
| | | this.$tab.reLaunch('/pages/login') |
| | | // 使用工具类根据环境自动跳转到合适的登录页面 |
| | | redirectToLoginByEnvironment(options, this.$tab); |
| | | } |
| | | }, |
| | | |
| | |
| | | |
| | | <style lang="scss"> |
| | | @import '@/static/scss/index.scss' |
| | | </style> |
| | | </style> |