杨磊
2025-08-07 375513370cc01fcd976987d07797249600b0bb3e
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
 
// 自定义配置
 
import "@/assets/iconfont/iconfont.css";
import config from "@/assets/js/config";
Vue.prototype.config = config;
 
// axios
import service from "@/plugin/axios";
Vue.prototype.request = service;
 
import {
  setNewView
} from "@/assets/js/userAction"
Vue.prototype.setNewView = setNewView;
// ElementUI
import ElementUI from "element-ui";
import "@/assets/theme/index.css";
Vue.use(ElementUI);
 
import {
  tokenKey
} from "@/assets/js/config";
//工具类
import tool from "@/assets/js/toolClass";
Vue.prototype.tool = tool;
 
// 路由判断登录 根据路由配置文件的参数
router.beforeEach((to, from, next) => {
  if (to.matched.some((record) => record.meta.authentication)) {
    // 判断该路由是否需要登录权限
    if (tool.getCookie(tokenKey)) {
      // 判断当前的token是否存在 ; 登录存入的token
      if (to.path === "/login") {
        tool.delCookie(tokenKey);
        // removeToken();
        window.location.reload();
      } else {
        next();
      }
    } else {
      next({
        path: "/login",
        query: {
          redirect: to.fullPath
        }, // 将跳转的路由path作为参数,登录成功后跳转到该路由
      });
    }
  } else {
    next();
  }
});
// 请求处理
import MG from "@/assets/js/middleGround/WebMiddleGroundApi";
Vue.prototype.MG = MG;
 
// 时间处理
import moment from "moment";
Vue.prototype.moment = moment;
 
Vue.config.productionTip = false;
 
new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");