71 lines
2.5 KiB
JavaScript
71 lines
2.5 KiB
JavaScript
import { createApp } from 'vue'
|
|
import App from '@/App.vue'
|
|
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
|
|
// 导入 Element Plus 样式(必须)
|
|
import 'element-plus/dist/index.css'
|
|
// 导入 Element Plus 暗黑模式样式
|
|
import 'element-plus/theme-chalk/dark/css-vars.css'
|
|
import 'viewerjs/dist/viewer.css'
|
|
import VueViewer from 'v-viewer'
|
|
import '@/assets/less/index.less'
|
|
import '@/assets/css/all.min.css'
|
|
import '@/assets/js/all.min.js'
|
|
import router from './router'
|
|
import { loadAndAddDynamicRoutes } from './router'
|
|
import { createPinia } from 'pinia'
|
|
import { useAuthStore } from './stores/auth'
|
|
import { redirectToAuthorize, isAuthHandoff } from '@/utils/authClient'
|
|
// import { initTheme } from './utils/theme'
|
|
// 导入全局组件
|
|
import UmoEditor from '@/views/components/UmoEditor.vue';
|
|
|
|
// 兼容某些依赖(如 HTML→docx 转换库)对 Node 全局变量 global 的引用
|
|
if (typeof window !== 'undefined' && !window.global) {
|
|
window.global = window;
|
|
}
|
|
|
|
const app = createApp(App)
|
|
const pinia = createPinia()
|
|
// 全局注册 UmoEditor 组件
|
|
app.component('UmoEditor', UmoEditor);
|
|
|
|
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
|
app.component(key, component)
|
|
}
|
|
|
|
app.use(pinia)
|
|
app.use(router)
|
|
app.use(VueViewer)
|
|
|
|
// 初始化主题(必须在挂载前执行)
|
|
// initTheme()
|
|
|
|
// 初始化时检查认证状态。
|
|
// 认证交接页(/auth/callback、/app-login、/mp-login)正在兑换令牌,此时
|
|
// localStorage 里还是旧 token。启动期请求带旧 token 打到后端会触发 401 自动
|
|
// 恢复,进而清掉刚换到的新令牌并重新跳回登录页。交接页一律跳过启动期的
|
|
// 登录态请求与自动跳转,由交接页写完令牌后整页重载。
|
|
const authStore = useAuthStore()
|
|
if (!isAuthHandoff()) {
|
|
authStore.checkAuth()
|
|
|
|
// 如果用户已登录,在应用启动时加载动态路由
|
|
if (authStore.isLoggedIn) {
|
|
loadAndAddDynamicRoutes()
|
|
.catch(err => {
|
|
console.error('应用启动时加载动态路由失败:', err);
|
|
})
|
|
.then(() => {
|
|
// 检查是否因为 token 无效而导致路由加载失败
|
|
const token = localStorage.getItem('token');
|
|
if (!token) {
|
|
// 本地登录已停用:直接回认证中心重新登录(不再跳 #/login)
|
|
redirectToAuthorize().catch((err) => {
|
|
console.error('跳转统一认证失败:', err);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
app.mount('#app') |