<script setup>
import { useSystemStore } from '@/store/system.js'
import { useUserStore } from '@/store/user.js'
import { onLaunch, onShow } from '@dcloudio/uni-app'

const systemStore = useSystemStore()
const userStore = useUserStore()

onLaunch(() => {
  systemStore.init()
  checkLoginStatus()
})

onShow(() => {
  // 每次显示时检查登录状态
  checkLoginStatus()
})

// 检查登录状态
const checkLoginStatus = () => {
  const isLoggedIn = userStore.checkLoginStatus()
  
  // 如果未登录且不在登录页面，则跳转到登录页
  if (!isLoggedIn) {
    const pages = getCurrentPages()
    const currentPage = pages[pages.length - 1]
    
    if (currentPage && currentPage.route !== 'pages/user/login') {
      uni.reLaunch({
        url: '/pages/user/login'
      })
    }
  }
}
</script>

<style lang="scss">
/*每个页面公共css */
@import 'styles/global.scss';
@import 'static/font/iconfont.css';
//主题scss
.default-theme {
  @import 'styles/themes/default-theme.scss';
}
//主题scss
.red-theme {
  @import 'styles/themes/default-theme.scss';
}
</style>

<style></style>
