main.js 5.8 KB

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