flaunt-web/src/main.js

40 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import router from './router'
import { createPinia } from 'pinia'
import App from './App.vue'
import './styles/global.scss'
import authService from '@/api/authService'
const app = createApp(App)
// Register all Element Plus icons
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component)
}
app.use(ElementPlus, { locale: zhCn })
app.use(createPinia())
app.use(router)
app.mount('#app')
// 后台异步获取配置与游客 Token不阻塞首屏渲染
authService.getUserConfig().then(res => {
if (res && res.data) {
console.log("用户配置", res.data)
// 只有在本地没有 token 时,才写入游客 token
if (res.data.token && !localStorage.getItem('token')) {
localStorage.setItem('token', res.data.token)
}
if (res.data.config) {
window.__USER_CONFIG__ = res.data.config
}
}
}).catch(err => {
console.error('获取用户配置失败:', err)
})