1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import Vue from "vue";
- // 进入svg自定义icon插件
- import "./assets/icons/index.js";
- import App from "./App.vue";
- import router from "./router";
- import store from "./store";
- import ElementUI from "element-ui";
- import "element-ui/lib/theme-chalk/index.css";
- // 添加字体(优设标题黑)
- import "./assets/font/font.css";
- import "./assets/global.css";
- import SvgIcon from "@/components/SvgIcon";
- Vue.component("svg-icon", SvgIcon);
- import $ from "jquery";
- import { drag } from "./directives/drag";
- import { post, postform } from "./utils/request.js";
- import urls from "./api/url";
- // 引入dayjs库
- import dayjs from 'dayjs';
- import * as echarts from "echarts";
- Vue.directive("drag", drag);
- Vue.prototype.$Post = post;
- Vue.prototype.$Echarts = echarts;
- Vue.prototype.$dayjs = dayjs;
- Vue.prototype.$PostForm = postform
- Vue.prototype.urlsCollection = urls;
- Vue.config.productionTip = false;
- Vue.use(ElementUI);
- Vue.prototype.$store = store;
- // 根据菜单index,和已选中的菜单返回是否相同
- Vue.prototype.$ifMenu = (menuIndex, subMenuIndex) => {
- if (
- store.state.navSelect !== undefined &&
- store.state.navSelect.index == menuIndex &&
- (subMenuIndex !== ""
- ? store.state.navSelect.subIndex === subMenuIndex
- : true)
- ) {
- return true;
- } else {
- return false;
- }
- };
- // 根据左侧菜单选中暂存index,与传入的菜单index对比,返回状态(主要使用于MenuCard组件type为imageMenu的元素,《疑点分析》下的子菜单)
- Vue.prototype.$ifLeftMenu = (leftMenuTitle) => {
- return store.state.leftMenuTitle == leftMenuTitle;
- };
- // 添加全局路由前置守卫
- router.beforeEach((to, from, next) => {
- if (to.path === '/' && from.path === '/login') {
- // 退出操作成功后
- next();
- }
- if (to.path === '/login' && from.path === '/') {
- // 登录操作成功后
- next();
- }
- if (to.path === '/' && from.path === '/') {
- // 首页刷新操作
- post(urls.getUserInfo).then(
- res => {
- // 请求成功
- if (res.code == 200 && res.content !== "无效token") {
- next();
- } else {
- localStorage.removeItem('TOKEN');
- localStorage.removeItem('USER_ID');
- ElementUI.Message.error("用户信息获取失败,请尝试重新登录!");
- next('/login');
- }
- },
- error => {
- // 请求失败!
- localStorage.removeItem('TOKEN');
- localStorage.removeItem('USER_ID');
- ElementUI.Message.error(error)
- next('/login');
- }
- );
- }
- })
- new Vue({
- router,
- store,
- render: (h) => h(App),
- // 全局事件总线
- beforeCreate() {
- Vue.prototype.$bus = this;
- },
- }).$mount("#app");
|