main.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. // 过滤
  32. import filter from './utils/filters';
  33. Object.keys(filter).forEach((key) => Vue.filter(key, filter[key]));
  34. // 滚动条
  35. import GeminiScrollbar from 'vue-gemini-scrollbar';
  36. Vue.use(GeminiScrollbar);
  37. // import VueAMap from 'vue-amap';
  38. Vue.prototype.$moment = moment;
  39. Vue.config.productionTip = false;
  40. Vue.use(Vuex);
  41. Vue.use(commonComponents);
  42. Vue.use(directiveInit);
  43. Vue.use(directived);
  44. Vue.use(ElementUI, {
  45. size: 'small'
  46. });
  47. // Vue.use(VueAMap);
  48. //
  49. // // 初始化vue-amap
  50. // VueAMap.initAMapApiLoader({
  51. // // 高德的key
  52. // key: 'def65c683e32ae89dd7f8982b433b7f8',
  53. // // 插件集合
  54. // plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'],
  55. // // 高德 sdk 版本,默认为 1.4.4
  56. // v: '1.4.4'
  57. // });
  58. let defaultPath = '';
  59. Vue.prototype.routerLoad = {
  60. findOne(arr) {
  61. return arr.map((v) => {
  62. if (v.children) {
  63. return this.findOne(v.children);
  64. } else {
  65. return {
  66. path: '/' + v.linkPath,
  67. name: v.name
  68. };
  69. }
  70. });
  71. },
  72. findMen(arr, indexPath) {
  73. let status = false;
  74. arr.map((v) => {
  75. if (v.children) {
  76. this.findMen(v.children);
  77. } else {
  78. if ('/' + v.linkPath === indexPath) {
  79. status = true;
  80. }
  81. }
  82. });
  83. return status;
  84. },
  85. close() {
  86. let activeRout = localStorage.getItem('path');
  87. let tagsList = store.getters['getTagsList'];
  88. tagsList.forEach((item, index) => {
  89. if (item.path == activeRout) {
  90. tagsList.splice(index, 1);
  91. return true;
  92. }
  93. });
  94. },
  95. // 获取菜单
  96. loadMenus() {
  97. http.get('/sc-user-center/user/findUserMenu', { appId: '1002' }).then(({ status, data, msg }) => {
  98. if (0 === status) {
  99. store.commit('setMenuList', data[0].children);
  100. store.commit('setThisDetai', data[0]);
  101. }
  102. });
  103. }
  104. };
  105. //使用钩子函数对路由进行权限跳转
  106. // router.beforeEach((to, from, next) => {
  107. // debugger;
  108. // if (localStorage.getItem("SC_token")) {
  109. // let menuList = window.sessionStorage.getItem("operationMuen")
  110. // let newAr = [];
  111. // if (menuList === null || menuList === undefined) {
  112. // http.get('/sc-user-center/user/findUserMenu', { appId: '1002' }).then(({ status, data, msg }) => {
  113. // if (0 == status) {
  114. // let datas = data[0].children
  115. // window.sessionStorage.setItem('operationMuen', JSON.stringify(datas))
  116. // // funcRouter(newAr, datas, router)
  117. // // next({ ...to, replace: true })
  118. // } else {
  119. // this.$message.error(msg);
  120. // }
  121. // })
  122. // } else {
  123. // if (router.options.routes[0].children.length === 0) {
  124. // // funcRouter(newAr, JSON.parse(menuList), router)
  125. // next({ ...to, replace: true })
  126. // } else {
  127. // next()
  128. // }
  129. // }
  130. // } else {
  131. // next();
  132. // }
  133. // });
  134. router.beforeEach((to, from, next) => {
  135. if (to.path !== '/404') {
  136. // console.log()
  137. let PermissionsRouter = Vue.prototype.routerLoad.findMen(store.getters.getMenuList, to.fullPath);
  138. if (PermissionsRouter) {
  139. next();
  140. } else {
  141. next({ path: 404 });
  142. }
  143. // 跳转时存储路由
  144. localStorage.setItem('path', to.fullPath);
  145. } else {
  146. next();
  147. }
  148. });
  149. new Vue({
  150. router,
  151. store,
  152. render: (h) => h(App),
  153. created() {
  154. if (localStorage.getItem('SC_token')) {
  155. this.routerLoad.loadMenus();
  156. }
  157. }
  158. }).$mount('#app');
  159. Vue.prototype.$http = http;
  160. Vue.prototype.$api = apiService(http);