杨磊
1 天以前 cabc1ce19c57a7c7388502952eaaafd558363145
src/main.js
@@ -1,71 +1,33 @@
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import './assets/main.css'
// 自定义配置
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import "@/assets/iconfont/iconfont.css";
import config from "@/assets/js/config";
Vue.prototype.config = config;
import App from './App.vue'
// 完整引入 Element Plus
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import router from './router'
import MG from '@/assets/js/middleGround/WebMiddleGroundApi.js'
import toolClass from '@/assets/js/toolClass.js'
import config from '@/assets/js/config.js'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
// axios
import service from "@/plugin/axios";
Vue.prototype.request = service;
const app = createApp(App)
import {
  setNewView
} from "@/assets/js/userAction"
Vue.prototype.setNewView = setNewView;
// ElementUI
import ElementUI from "element-ui";
import "@/assets/theme/index.css";
Vue.use(ElementUI);
app.provide('config', config)
app.provide('MG', MG)
app.provide('toolClass', toolClass)
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");
// 注册所有图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
app.use(ElementPlus)
app.use(createPinia())
app.use(router)
app.use(ElementPlus, {
  locale: zhCn,
})
app.mount('#app')