main.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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/element-variables.scss";
  20. import './assets/css/main.scss';
  21. import './assets/css/element-variables.scss';
  22. import '@utils/rem.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. import "./assets/common.styl";
  30. import "./assets/v2.styl";
  31. import "./assets/zz.styl";
  32. import "./assets/ucd.styl";
  33. // import VueAMap from 'vue-amap';
  34. import { funcRouter } from "./router/dynamicMuen";
  35. Vue.prototype.$moment = moment;
  36. Vue.config.productionTip = false;
  37. Vue.use(Vuex);
  38. Vue.use(commonComponents);
  39. Vue.use(directiveInit);
  40. Vue.use(ElementUI, {
  41. size: 'small'
  42. });
  43. // Vue.use(VueAMap);
  44. //
  45. // // 初始化vue-amap
  46. // VueAMap.initAMapApiLoader({
  47. // // 高德的key
  48. // key: 'def65c683e32ae89dd7f8982b433b7f8',
  49. // // 插件集合
  50. // plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'],
  51. // // 高德 sdk 版本,默认为 1.4.4
  52. // v: '1.4.4'
  53. // });
  54. Vue.prototype.$http = http;
  55. Vue.prototype.$api = apiService(http);
  56. let defaultPath = '';
  57. Vue.prototype.routerLoad = {
  58. findOne(arr) {
  59. return arr.map(v => {
  60. if (v.children) {
  61. return this.findOne(v.children)
  62. } else {
  63. return {
  64. path: "/" + v.linkPath,
  65. name: v.name
  66. }
  67. }
  68. })
  69. },
  70. // 获取菜单
  71. loadMenus() {
  72. http.get('/user/findUserMenu', { appId: '1002' }).then(({ status, data, msg }) => {
  73. if (0 === status) {
  74. let routerArr = this.findOne(data[0].children);
  75. if (routerArr[0].length) {
  76. defaultPath = routerArr[0][0].path;
  77. } else {
  78. defaultPath = routerArr[0].path;
  79. }
  80. if (localStorage.getItem('path') == '/') {
  81. localStorage.setItem('path', defaultPath)
  82. }
  83. router.push({ path: localStorage.getItem('path') })
  84. }
  85. });
  86. }
  87. };
  88. //使用钩子函数对路由进行权限跳转
  89. router.beforeEach((to, from, next) => {
  90. // if (to.path != '/404') {
  91. // // 跳转时存储路由
  92. // localStorage.setItem('path', to.fullPath)
  93. // }
  94. // next();
  95. if (localStorage.getItem("SC_token")) {
  96. let menuList = window.sessionStorage.getItem("operationMuen")
  97. let newAr = [];
  98. if (menuList === null || menuList === undefined) {
  99. http.get('/sc-user-center/user/findUserMenu', { appId: '1002' }).then(({ status, data, msg }) => {
  100. if (0 == status) {
  101. let datas = data[0].children
  102. window.sessionStorage.setItem('operationMuen', JSON.stringify(datas))
  103. funcRouter(newAr, datas, router)
  104. next({ ...to, replace: true })
  105. } else {
  106. this.$message.error(msg);
  107. }
  108. })
  109. } else {
  110. if (router.options.routes[0].children.length === 0) {
  111. funcRouter(newAr, JSON.parse(menuList), router)
  112. next({ ...to, replace: true })
  113. } else {
  114. next()
  115. }
  116. }
  117. } else {
  118. next();
  119. }
  120. });
  121. new Vue({
  122. router,
  123. store,
  124. render: h => h(App),
  125. created() {
  126. // if (localStorage.getItem('SC_token')) {
  127. // this.routerLoad.loadMenus();
  128. // }
  129. }
  130. }).$mount('#app');