import { createApp } from 'vue' import App from './App.vue' import { router, filterExclude } from './router' import store from './store' import type { RouteLocationNormalized, NavigationGuardNext } from 'vue-router' import { ElLoading } from 'element-plus' import 'element-plus/theme-chalk/el-message.css' import 'element-plus/theme-chalk/el-message-box.css' import 'element-plus/theme-chalk/el-image-viewer.css' import 'element-plus/theme-chalk/dark/css-vars.css' import * as ElementPlusIconsVue from '@element-plus/icons-vue' import { permissionDirective } from '@/utils/permission' // 全局路由导航前置守卫 router.beforeEach(function (to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext) { if (to.meta?.title) { store.commit('addTab', { title: to.meta.title, path: to.path, name: to.name }) } store.state.activeTab = to.path if(filterExclude.indexOf(to.path) !== -1 || store.state.loginInfo.token) { next() } else { next('/login') } }) const app = createApp(App) for (const [key, component] of Object.entries(ElementPlusIconsVue)) { app.component(key, component) } app.use(router) .use(store) .directive('loading', ElLoading.directive) .directive('permission', permissionDirective) .mount('#app')