Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

肖康 / cloudSystem

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Settings
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Find file
BlameHistoryPermalink
Switch branch/tag
  • cloudSystem
  • src
  • main.js
  • LJM's avatar
    兼容 · 66b99d75
    LJM committed 2 years ago
    66b99d75
main.js 2.66 KB
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import filters from './filters'
import directive from './directive'
import {http} from './ajax/index.js';
import axios from 'axios'

import {hideLoading, showLoading} from './ajax/loading';
import Util from "./tool";

//加载全局样式
import '@/assets/css/public/common.min.css'
import '@/assets/css/font/iconfont.css'

//本地环境开启提示信息
Vue.config.productionTip = true;

Vue.prototype.$ELEMENT = {
  size: 'mini',
  zIndex: 30000
};

//加载过滤器
Object.keys(filters).forEach(key => Vue.filter(key, filters[key]));

//加载自定义指令
Vue.use(directive);

//处理顶部导航TAB
router.afterEach((to, from, next) => {
  if (to.path == "/" || to.path == "/login" || to.path == '/notfound' || to.path == '/bindError') {
    return;
  }
  let tabOldArr = sessionStorage.getItem('tabs');
  let tabOldJson;
  let tabNewJson = [];
  if (tabOldArr) {
    tabOldJson = JSON.parse(tabOldArr);
    for (var i = 0; i < tabOldJson.length; i++) {
      tabNewJson.push(JSON.stringify(tabOldJson[i]))
    }
    if (tabNewJson.indexOf(JSON.stringify({path: to.path, title: to.meta.title, query: to.query})) == -1) {
      tabOldJson.push({
        path: to.path,
        title: to.meta.title,
        query: to.query
      })
    }
  } else {
    tabOldJson = [{
      path: to.path,
      title: to.meta.title,
      query: to.query
    }]
  }
  if (tabOldJson) {
    sessionStorage.setItem('tabs', JSON.stringify(tabOldJson));
  }
});

axios.interceptors.request.use((config) => {
  if (config.loading) {
    showLoading();
  }
  return config;
}, (err) => {
  return Promise.reject(err)
})

axios.interceptors.response.use(res => {
  hideLoading();
  if (res.data.code == 101) {
    //token验证失败
    var path = window.location.hash;
    path = path.substr(1)
    router.push({
      path: "/login",
      query: {
        referer: encodeURI(path)
      }
    })
  }
  return res.data;
}, error => {
  Message('网络出现问题,请检查网络');
  hideLoading();
  return Promise.reject(new Error(error))
})

//挂载到VUE原型上封装后的http请求
Vue.prototype.$http = http;

//路由页面回跳处理  
router.beforeEach((to, from, next) => {
  if (to.path == "/login" || to.path == '/notfound' || to.path == '/bindError') {
    next()
  } else {
    let token = Util.getCookie('token') || '';
    if (!token) {
      window.userInfo = ""
      var path_ = window.location.hash
      path_ = path_.substr(1)
      window.location.href = '/#/login?referer=' + encodeURI(path_);
      history.go(0);
    } else {
      next();
    }
  }
});


new Vue({
  router,
  render: (h) => h(App),
}).$mount("#app");