main.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * @Author: zouwenying
  3. * @Date: 2020-10-21 18:14:35
  4. * @LastEditTime: 2020-11-18 16:28:23
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: \vue-manage-system-master\src\main.js
  8. */
  9. import Vue from 'vue';
  10. import App from './App.vue';
  11. import router from './router';
  12. import Vuex from 'vuex';
  13. import ElementUI from 'element-ui';
  14. import commonComponents from './components/common';
  15. import 'element-ui/lib/theme-chalk/index.css'; // 默认主题
  16. import moment from 'moment';
  17. moment.locale('zh-cn');
  18. import './assets/css/icon.css';
  19. import './assets/css/main.scss';
  20. import './assets/css/element-variables.scss';
  21. import '@utils/rem.js';
  22. import directiveInit from '@utils/directives';
  23. import http from '@utils/http.js';
  24. import apiService from './api/index';
  25. import store from './store/store.js';
  26. import '@utils/utils.js';
  27. import 'babel-polyfill';
  28. Vue.prototype.$moment = moment;
  29. Vue.config.productionTip = false;
  30. Vue.use(Vuex);
  31. Vue.use(commonComponents);
  32. Vue.use(directiveInit);
  33. Vue.use(ElementUI, {
  34. size: 'small'
  35. });
  36. Vue.prototype.$http = http;
  37. Vue.prototype.$api = apiService(http);
  38. let defaultPath = '';
  39. Vue.prototype.routerLoad = {
  40. findOne(arr) {
  41. return arr.map(v => {
  42. if (v.children) {
  43. return this.findOne(v.children)
  44. } else {
  45. return {
  46. path: "/" + v.linkPath,
  47. name: v.name
  48. }
  49. }
  50. })
  51. },
  52. findMen(arr, indexPath) {
  53. let status = false;
  54. arr.map(v => {
  55. if (v.children) {
  56. this.findMen(v.children)
  57. } else {
  58. if (('/' + v.linkPath) === indexPath) {
  59. status = true
  60. }
  61. }
  62. })
  63. return status
  64. },
  65. close() {
  66. let activeRout = localStorage.getItem('path');
  67. let tagsList = store.getters['getTagsList'];
  68. tagsList.forEach((item, index) => {
  69. if (item.path == activeRout) {
  70. tagsList.splice(index, 1);
  71. return true;
  72. }
  73. });
  74. },
  75. // 获取菜单
  76. loadMenus() {
  77. http.get('/user/findUserMenu', { appId: '1001' }).then(({ status, data, msg }) => {
  78. if (0 === status) {
  79. let routerArr = this.findOne(data[0].children);
  80. store.commit('setThisMenuList', data[0].children);
  81. if (routerArr[0].length) {
  82. defaultPath = routerArr[0][0].path;
  83. } else {
  84. defaultPath = routerArr[0].path;
  85. }
  86. if (localStorage.getItem('path') == '/') {
  87. localStorage.setItem('path', defaultPath)
  88. }
  89. if (this.findMen(data[0].children, localStorage.getItem('path'))) {
  90. router.push({ path: localStorage.getItem('path') })
  91. } else {
  92. // this.close();
  93. router.push({ path: defaultPath})
  94. // router.replace({ path: '403' })
  95. }
  96. }
  97. });
  98. }
  99. };
  100. //使用钩子函数对路由进行权限跳转
  101. router.beforeEach((to, from, next) => {
  102. if (to.path != '/404') {
  103. // 跳转时存储路由
  104. localStorage.setItem('path', to.fullPath)
  105. }
  106. next();
  107. });
  108. new Vue({
  109. router,
  110. store,
  111. render: h => h(App),
  112. created() {
  113. if (localStorage.getItem('SC_token')) {
  114. this.routerLoad.loadMenus();
  115. }
  116. }
  117. }).$mount('#app');