123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- 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 { drag } from "./directives/drag";
- import { get, post, postform, getFile } from "./utils/request.js";
- import urls from "./api/url";
- import CryptoJS from "./utils/publicFunction.js";
- // 引入dayjs库
- import dayjs from "dayjs";
- import * as echarts from "echarts";
- import proj4 from "proj4";
- // 滚动插件
- import scroll from "vue-seamless-scroll/src";
- Vue.directive("drag", drag);
- Vue.prototype.$CryptoJS = CryptoJS;
- Vue.prototype.$Post = post;
- Vue.prototype.$Get = get;
- Vue.prototype.$GetFile = getFile;
- Vue.prototype.$Echarts = echarts;
- Vue.prototype.$dayjs = dayjs;
- Vue.prototype.$proj4 = proj4;
- Vue.prototype.$PostForm = postform;
- Vue.prototype.urlsCollection = urls;
- Vue.config.productionTip = false;
- Vue.use(ElementUI);
- Vue.use(scroll);
- 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.meta.title) {
- document.title = to.meta.title;
- }
- 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");
- localStorage.removeItem("USER_NAME");
- ElementUI.Message.error("用户信息获取失败,请尝试重新登录!");
- next("/login");
- }
- },
- (error) => {
- // 请求失败!
- localStorage.removeItem("TOKEN");
- localStorage.removeItem("USER_ID");
- localStorage.removeItem("USER_NAME");
- ElementUI.Message.error(error);
- next("/login");
- }
- );
- }
- });
- new Vue({
- router,
- store,
- render: (h) => h(App),
- // 全局事件总线
- beforeCreate() {
- Vue.prototype.$bus = this;
- },
- }).$mount("#app");
|