main.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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/css/main.scss';
  20. import './assets/css/element-variables.scss';
  21. import '@utils/rem.js';
  22. import directiveInit from '@utils/directives';
  23. import http from '@utils/http.js';
  24. import apiService from './api/index';
  25. import store from './store/store.js';
  26. import '@utils/utils.js';
  27. import 'babel-polyfill';
  28. Vue.prototype.$moment = moment;
  29. Vue.config.productionTip = false;
  30. Vue.use(Vuex);
  31. Vue.use(commonComponents);
  32. Vue.use(directiveInit);
  33. Vue.use(ElementUI, {
  34. size: 'small'
  35. });
  36. Vue.prototype.$http = http;
  37. Vue.prototype.$api = apiService(http);
  38. let defaultPath='';
  39. Vue.prototype.routerLoad = {
  40. findOne(arr){
  41. return arr.map(v=>{
  42. if(v.children){
  43. return this.findOne(v.children)
  44. }else{
  45. return {
  46. path:"/"+v.linkPath,
  47. name:v.name
  48. }
  49. }
  50. })
  51. },
  52. // 获取菜单
  53. loadMenus() {
  54. http.get('/user/findUserMenu', { appId: '1001' }).then(({ status, data, msg }) => {
  55. if (0 === status) {
  56. let routerArr = this.findOne(data[0].children);
  57. if(routerArr[0].length){
  58. defaultPath = routerArr[0][0].path;
  59. }else{
  60. defaultPath = routerArr[0].path;
  61. }
  62. if (localStorage.getItem('path') == '/') {
  63. localStorage.setItem('path', defaultPath)
  64. }
  65. router.push({ path: localStorage.getItem('path') })
  66. }
  67. });
  68. }
  69. };
  70. //使用钩子函数对路由进行权限跳转
  71. router.beforeEach((to, from, next) => {
  72. if (to.path != '/404') {
  73. // 跳转时存储路由
  74. localStorage.setItem('path', to.fullPath)
  75. }
  76. next();
  77. });
  78. new Vue({
  79. router,
  80. store,
  81. render: h => h(App),
  82. created() {
  83. if (localStorage.getItem('SC_token')) {
  84. this.routerLoad.loadMenus();
  85. }
  86. }
  87. }).$mount('#app');