main.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 { funcRouter } from './router/dynamicMuen';
  13. import Vuex from 'vuex';
  14. import ElementUI from 'element-ui';
  15. import commonComponents from './components/common';
  16. import 'element-ui/lib/theme-chalk/index.css'; // 默认主题
  17. import moment from 'moment';
  18. moment.locale('zh-cn');
  19. import './assets/css/icon.css';
  20. import './assets/css/main.scss';
  21. import './assets/css/element-variables.scss';
  22. import '@utils/rem.js';
  23. import '@utils/AmapSearch.js';
  24. import directiveInit from '@utils/directives';
  25. import directived from '@utils/directived';
  26. import http from '@utils/http.js';
  27. import apiService from './api/index';
  28. import store from './store/store.js';
  29. import '@utils/utils.js';
  30. import 'babel-polyfill';
  31. import publicArray from '@utils/publicArray';
  32. // 过滤
  33. import filter from './utils/filters';
  34. Object.keys(filter).forEach((key) => Vue.filter(key, filter[key]));
  35. // 滚动条
  36. import GeminiScrollbar from 'vue-gemini-scrollbar';
  37. Vue.use(GeminiScrollbar);
  38. Vue.prototype.$publicArray = publicArray;
  39. Vue.prototype.$moment = moment;
  40. Vue.config.productionTip = false;
  41. Vue.use(Vuex);
  42. Vue.use(commonComponents);
  43. Vue.use(directiveInit);
  44. Vue.use(directived);
  45. Vue.use(ElementUI, {
  46. size: 'small'
  47. });
  48. window.onresize = () => {
  49. let size = document.body.clientWidth / 1920;
  50. store.commit("setScale", size);
  51. };
  52. let defaultPath = '';
  53. Vue.prototype.routerLoad = {
  54. findOne(arr) {
  55. return arr.map((v) => {
  56. if (v.children) {
  57. return this.findOne(v.children);
  58. } else {
  59. return {
  60. path: '/' + v.linkPath,
  61. name: v.name
  62. };
  63. }
  64. });
  65. },
  66. findMen(arrList, arr, indexPath) {
  67. arr.map((v) => {
  68. if (v.children) {
  69. this.findMen(arrList, v.children, indexPath);
  70. } else {
  71. if ('/' + v.linkPath == indexPath) {
  72. arrList.push(true)
  73. }
  74. }
  75. });
  76. },
  77. close() {
  78. let activeRout = localStorage.getItem('path');
  79. let tagsList = store.getters['getTagsList'];
  80. tagsList.forEach((item, index) => {
  81. if (item.path == activeRout) {
  82. tagsList.splice(index, 1);
  83. return true;
  84. }
  85. });
  86. },
  87. };
  88. //使用钩子函数对路由进行权限跳转
  89. router.beforeEach((to, from, next) => {
  90. document.title = store.getters['getThisDetai'].name || !!window.sessionStorage.getItem('setThisDetai') ? JSON.parse(window.sessionStorage.getItem('setThisDetai')).name : ''
  91. if (localStorage.getItem("SC_token")) {
  92. let menuList = window.sessionStorage.getItem("SC_listMuen")
  93. let newAr = [];
  94. if (menuList == null || menuList == undefined) {
  95. http.get('/sc-user-center/user/findUserMenu', { appId: '1002' }).then(({ status, data, msg }) => {
  96. if (0 == status) {
  97. let datas = data[0].children
  98. window.sessionStorage.setItem('SC_listMuen', JSON.stringify(datas))
  99. window.sessionStorage.setItem('setThisDetai', JSON.stringify(data[0]))
  100. store.commit('setThisDetai', data[0]);
  101. funcRouter(newAr, datas, router)
  102. next({ ...to, replace: true })
  103. } else {
  104. this.$message.error(msg);
  105. }
  106. })
  107. } else {
  108. if (router.options.routes[0].children.length == 0) {
  109. funcRouter(newAr, JSON.parse(menuList), router)
  110. next({ ...to, replace: true })
  111. } else {
  112. let thisAll = JSON.parse(menuList)[0];
  113. if (to.path == '/') {
  114. if (!!thisAll.children) {
  115. next({ path: `/${thisAll.children[0].linkPath}` })
  116. } else {
  117. next({ path: `/${thisAll.linkPath}` })
  118. }
  119. } else {
  120. next()
  121. }
  122. }
  123. }
  124. } else {
  125. next();
  126. }
  127. });
  128. new Vue({
  129. router,
  130. store,
  131. render: (h) => h(App),
  132. }).$mount('#app');
  133. Vue.prototype.$http = http;
  134. Vue.prototype.$api = apiService(http);