main.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 '@utils/AmapSearch.js';
  23. import directiveInit from '@utils/directives';
  24. import http from '@utils/http.js';
  25. import apiService from './api/index';
  26. import store from './store/store.js';
  27. import '@utils/utils.js';
  28. import 'babel-polyfill';
  29. Vue.prototype.$moment = moment;
  30. Vue.config.productionTip = false;
  31. Vue.use(Vuex);
  32. Vue.use(commonComponents);
  33. Vue.use(directiveInit);
  34. Vue.use(ElementUI, {
  35. size: 'small'
  36. });
  37. window.onresize = () => {
  38. let size = document.body.clientWidth / 1920;
  39. store.commit("setScale", size);
  40. };
  41. Vue.prototype.routerLoad = {
  42. findOne(arr) {
  43. return arr.map(v => {
  44. if (v.children) {
  45. return this.findOne(v.children)
  46. } else {
  47. return {
  48. path: "/" + v.linkPath,
  49. name: v.name
  50. }
  51. }
  52. })
  53. },
  54. findMen(arr, indexPath) {
  55. let status = false;
  56. arr.map(v => {
  57. if (v.children) {
  58. this.findMen(v.children)
  59. } else {
  60. if (('/' + v.linkPath) === indexPath) {
  61. status = true
  62. }
  63. }
  64. })
  65. return status
  66. },
  67. close() {
  68. let activeRout = localStorage.getItem('path');
  69. let tagsList = store.getters['getTagsList'];
  70. tagsList.forEach((item, index) => {
  71. if (item.path == activeRout) {
  72. tagsList.splice(index, 1);
  73. return true;
  74. }
  75. });
  76. },
  77. // 获取菜单
  78. loadMenus() {
  79. http.get('/sc-user-center/user/findUserMenu', { appId: '1003' }).then(({ status, data, msg }) => {
  80. if (0 === status) {
  81. store.commit('setMenuList', data[0].children)
  82. }
  83. });
  84. }
  85. };
  86. router.beforeEach((to, from, next) => {
  87. if (to.path !== '/404') {
  88. // console.log()
  89. let PermissionsRouter = Vue.prototype.routerLoad.findMen(store.getters.getMenuList, to.fullPath)
  90. if (PermissionsRouter) {
  91. next();
  92. } else {
  93. next({ path: 404 })
  94. }
  95. // 跳转时存储路由
  96. localStorage.setItem('path', to.fullPath)
  97. } else {
  98. next();
  99. }
  100. });
  101. new Vue({
  102. router,
  103. store,
  104. render: h => h(App),
  105. created() {
  106. if (localStorage.getItem('SC_token')) {
  107. this.routerLoad.loadMenus();
  108. }
  109. }
  110. }).$mount('#app');
  111. Vue.prototype.$http = http;
  112. Vue.prototype.$api = apiService(http);