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