1
litian
2024-04-24 cd0b5d58bad2ed1e04fa0626c9de7b13d9692fa9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import './assets/main.css'
 
import { createApp } from 'vue'
import pinia from '@/store/index'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import App from './App.vue'
import router from './router'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import toolClass from '@/assets/js/toolClass'
import request from "@/plugin/axios/index.ts"
import "./child.ts" 
 
 
const handleGetToken = () => {
  return localStorage.getItem("token");
}
 
// 路由执行之前的一些操作
router.beforeEach((to, from, next) => {
  // 如果有token
  if (handleGetToken()) {
    // 是否是登录页面,直接到首页
    if (to.path === "/login") {
      next({ path: "/transmission" });
    } else {
      // 如果不是登录页面,跳转到目标的页面
      next();
    }
  } else {
    // 没有token
    if (!to.meta || !to.meta.auth) {
      // 在免登录白名单,直接进入
      next();
    } else {
      next(`/login?redirect=${to.fullPath}`); // 否则全部重定向到登录页
    }
  }
});
 
const app = createApp(App)
app.provide('toolClass', toolClass)
app.provide('request', request)
app.use(router)
app.use(ElementPlus)
app.use(pinia)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
 
app.mount('#app')