main.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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(arrList, arr, indexPath) {
  73. arr.map((v) => {
  74. // if ('/' + v.linkPath !== indexPath) {
  75. // if (!!v.children) {
  76. // this.findMen(arrList, item.children, indexPath);
  77. // } else {
  78. // arrList.push(true)
  79. // }
  80. // } else {
  81. // }
  82. if (v.children) {
  83. this.findMen(arrList, v.children, indexPath);
  84. } else {
  85. if ('/' + v.linkPath == indexPath) {
  86. arrList.push(true)
  87. }
  88. }
  89. });
  90. },
  91. close() {
  92. let activeRout = localStorage.getItem('path');
  93. let tagsList = store.getters['getTagsList'];
  94. tagsList.forEach((item, index) => {
  95. if (item.path == activeRout) {
  96. tagsList.splice(index, 1);
  97. return true;
  98. }
  99. });
  100. },
  101. // 获取菜单
  102. loadMenus() {
  103. http.get('/sc-user-center/user/findUserMenu', { appId: '1002' }).then(({ status, data, msg }) => {
  104. if (0 === status) {
  105. store.commit('setMenuList', data[0].children);
  106. if (data[0].children[0].children == null) {
  107. router.push({
  108. path: '/' + data[0].children[0].linkPath
  109. });
  110. } else {
  111. router.push({
  112. path: '/' + data[0].children[0].children[0].linkPath
  113. });
  114. }
  115. store.commit('setThisDetai', data[0]);
  116. }
  117. });
  118. }
  119. };
  120. //使用钩子函数对路由进行权限跳转
  121. // router.beforeEach((to, from, next) => {
  122. // debugger;
  123. // if (localStorage.getItem("SC_token")) {
  124. // let menuList = window.sessionStorage.getItem("operationMuen")
  125. // let newAr = [];
  126. // if (menuList === null || menuList === undefined) {
  127. // http.get('/sc-user-center/user/findUserMenu', { appId: '1002' }).then(({ status, data, msg }) => {
  128. // if (0 == status) {
  129. // let datas = data[0].children
  130. // window.sessionStorage.setItem('operationMuen', JSON.stringify(datas))
  131. // // funcRouter(newAr, datas, router)
  132. // // next({ ...to, replace: true })
  133. // } else {
  134. // this.$message.error(msg);
  135. // }
  136. // })
  137. // } else {
  138. // if (router.options.routes[0].children.length === 0) {
  139. // // funcRouter(newAr, JSON.parse(menuList), router)
  140. // next({ ...to, replace: true })
  141. // } else {
  142. // next()
  143. // }
  144. // }
  145. // } else {
  146. // next();
  147. // }
  148. // });
  149. router.beforeEach((to, from, next) => {
  150. if (to.path !== '/404') {
  151. // console.log()
  152. let newa = [];
  153. console.log()
  154. Vue.prototype.routerLoad.findMen(newa, store.getters.getMenuList, to.fullPath);
  155. if (newa.length) {
  156. next();
  157. } else {
  158. next({ path: '404' });
  159. }
  160. next();
  161. // 跳转时存储路由
  162. localStorage.setItem('path', to.fullPath);
  163. } else {
  164. next();
  165. }
  166. });
  167. new Vue({
  168. router,
  169. store,
  170. render: (h) => h(App),
  171. created() {
  172. if (localStorage.getItem('SC_token')) {
  173. this.routerLoad.loadMenus();
  174. }
  175. }
  176. }).$mount('#app');
  177. Vue.prototype.$http = http;
  178. Vue.prototype.$api = apiService(http);