main.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. app.config.globalProperties.$UCore = UCore;
  27. app.config.globalProperties.$axios = axios;
  28. app.use(router).use(store).use(ElementPlus, { locale }).use(Vuex).use(echarts).use(Antd).mount('#app');
  29. store.commit("getTimeAll");
  30. /*路由守卫*/
  31. router.beforeEach((to, from, next) => {
  32. /* 路由发生变化修改页面title */
  33. if (to.meta.title) {
  34. document.title = to.meta.title
  35. }
  36. //如果目标路由为登陆时,恢复用户原始状态
  37. if (to.path === '/') {
  38. // next({ path: '/home' })
  39. // removeToken()
  40. // localStorage.removeItem("accessToken");
  41. console.log(removeToken())
  42. document.getElementById('routers').style.display = "none"
  43. } else {
  44. document.getElementById('routers').style.display = "block"
  45. }
  46. if (to.path !== '/') {
  47. if (localStorage.getItem('accessToken') === null) {
  48. // 本地存储的accessToken不存在时,跳转至后台登录页
  49. // alert('本地存储的accessToken不存在')
  50. window.location.href = 'https://wx.ewoogi.com/adminfiv/#/login'
  51. // next({ path: '/' })
  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. //路由的next必须存在,否则无法进入下一页
  65. next()
  66. }
  67. })