| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import { createApp } from 'vue'
- import { createPinia } from 'pinia'
- import ElementPlus from 'element-plus'
- import * as ElementPlusIconsVue from '@element-plus/icons-vue'
- import 'element-plus/dist/index.css'
- import 'element-plus/theme-chalk/dark/css-vars.css'
- import App from './App.vue'
- import router from './router'
- import { useAuthStore } from '@/stores/auth'
- const app = createApp(App)
- // 注册Element Plus图标
- for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
- app.component(key, component)
- }
- const pinia = createPinia()
- app.use(pinia)
- app.use(router)
- app.use(ElementPlus)
- // 初始化认证状态
- const initAuth = async () => {
- const authStore = useAuthStore()
-
- // 如果有token但没有用户信息,尝试获取用户信息
- if (authStore.token && !authStore.user) {
- try {
- await authStore.checkAuth()
- } catch (error) {
- console.error('初始化认证状态失败:', error)
- }
- }
- }
- // 在应用挂载前初始化认证状态
- initAuth().then(() => {
- app.mount('#app')
- }).catch((error) => {
- console.error('应用初始化失败:', error)
- app.mount('#app')
- })
|