<template>
  <a-config-provider :locale="zhCN">
    <router-view />
  </a-config-provider>
</template>

<script setup>
import zhCN from 'ant-design-vue/es/locale/zh_CN'
import { onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'

const router = useRouter()
const userStore = useUserStore()

// 检查登录状态
onMounted(() => {
  const token = userStore.token
  
  // 如果没有token且当前不是登录页，则跳转到登录页
  if (!token && router.currentRoute.value.path !== '/login') {
    router.push('/login')
  }
  
  // 如果有token且当前是登录页，则跳转到首页
  if (token && router.currentRoute.value.path === '/login') {
    router.push('/')
  }
})
</script>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  background-color: #f5f5f5;
}

#app {
  min-height: 100vh;
}
</style>
