main.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { createApp } from 'vue/dist/vue.esm-bundler.js';
  2. import Antd from 'ant-design-vue';
  3. import App from './App.vue';
  4. import 'ant-design-vue/dist/antd.css';
  5. import UCore from './utils/UCore.js';
  6. import './assets/css/index.css';
  7. import router from './router';
  8. import Vuex from 'vuex'
  9. import store from './store/index.js';
  10. import axios from 'axios';
  11. import ElementPlus from 'element-plus';
  12. import 'element-plus/lib/theme-chalk/index.css';
  13. import 'dayjs/locale/zh-cn';
  14. import locale from 'element-plus/lib/locale/lang/zh-cn';
  15. //引入rem字体配置
  16. import '@/assets/js/flexible.js';
  17. // 引入字体样式
  18. import '@/assets/fonts/font.css';
  19. import * as echarts from 'echarts'
  20. import 'echarts/lib/component/tooltip';
  21. import 'echarts/lib/component/title';
  22. import 'echarts/lib/component/legend';
  23. // import { ElMessage } from "element-plus";
  24. import { removeToken } from './utils/auth';
  25. const app = createApp(App);
  26. import Interface from "../public/InterfaceReturn.json"
  27. app.config.globalProperties.$Interface = Interface
  28. app.config.globalProperties.$UCore = UCore;
  29. app.config.globalProperties.$axios = axios;
  30. app.use(router).use(store).use(ElementPlus, { locale }).use(Vuex).use(echarts).use(Antd).mount('#app');
  31. store.commit("getTimeAll");
  32. /*路由守卫*/
  33. router.beforeEach((to, from, next) => {
  34. /* 路由发生变化修改页面title */
  35. if (to.meta.title) {
  36. document.title = to.meta.title
  37. }
  38. if (to.path !== '/') {
  39. if (localStorage.getItem('accessToken') === null) {
  40. removeToken()//不用管
  41. // if (localStorage.getItem('userInfo') === null) {
  42. // 本地存储的accessToken不存在时,跳转至后台登录页
  43. // alert('本地存储的accessToken不存在')
  44. // console.log(window.location.host.indexOf("localhost") != -1)
  45. if (window.location.host.indexOf("localhost") != -1) {
  46. next({ path: '/' })
  47. } else if (window.location.host.indexOf("pcdev.ewoogi.com") != -1) {
  48. window.location.href = 'https://pcdev.ewoogi.com/adminfiv/#/login'
  49. } else {
  50. window.location.href = 'https://wx.ewoogi.com/manage/#/login'
  51. }
  52. document.getElementById('routers').style.display = "none"
  53. // setTimeout(() => {
  54. // ElMessage.warning({
  55. // message: '请登录后重试!',
  56. // type: 'warning'
  57. // })
  58. // }, 100);
  59. } else {
  60. // alert('本地存储的accessToken存在')
  61. next();
  62. }
  63. } else {
  64. document.getElementById('routers').style.display = "block"
  65. //路由的next必须存在,否则无法进入下一页
  66. if (localStorage.getItem('accessToken') != null) {
  67. next({ path: '/home' })
  68. } else {
  69. next()
  70. }
  71. }
  72. })