main.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. Vue.prototype.$moment = moment;
  38. Vue.config.productionTip = false;
  39. Vue.use(Vuex);
  40. Vue.use(commonComponents);
  41. Vue.use(directiveInit);
  42. Vue.use(directived);
  43. Vue.use(ElementUI, {
  44. size: 'small'
  45. });
  46. window.onresize = () => {
  47. let size = document.body.clientWidth / 1920;
  48. store.commit("setScale", size);
  49. };
  50. let defaultPath = '';
  51. Vue.prototype.routerLoad = {
  52. findOne(arr) {
  53. return arr.map((v) => {
  54. if (v.children) {
  55. return this.findOne(v.children);
  56. } else {
  57. return {
  58. path: '/' + v.linkPath,
  59. name: v.name
  60. };
  61. }
  62. });
  63. },
  64. findMen(arrList, arr, indexPath) {
  65. arr.map((v) => {
  66. if (v.children) {
  67. this.findMen(arrList, v.children, indexPath);
  68. } else {
  69. if ('/' + v.linkPath == indexPath) {
  70. arrList.push(true)
  71. }
  72. }
  73. });
  74. },
  75. close() {
  76. let activeRout = localStorage.getItem('path');
  77. let tagsList = store.getters['getTagsList'];
  78. tagsList.forEach((item, index) => {
  79. if (item.path == activeRout) {
  80. tagsList.splice(index, 1);
  81. return true;
  82. }
  83. });
  84. },
  85. };
  86. //使用钩子函数对路由进行权限跳转
  87. router.beforeEach((to, from, next) => {
  88. document.title = store.getters['getThisDetai'].name || !!window.sessionStorage.getItem('setThisDetai') ? JSON.parse(window.sessionStorage.getItem('setThisDetai')).name : ''
  89. if (localStorage.getItem("SC_token")) {
  90. let menuList = window.sessionStorage.getItem("SC_listMuen")
  91. let newAr = [];
  92. if (menuList == null || menuList == undefined) {
  93. http.get('/sc-user-center/user/findUserMenu', { appId: '1002' }).then(({ status, data, msg }) => {
  94. if (0 == status) {
  95. let datas = data[0].children
  96. window.sessionStorage.setItem('SC_listMuen', JSON.stringify(datas))
  97. window.sessionStorage.setItem('setThisDetai', JSON.stringify(data[0]))
  98. store.commit('setThisDetai', data[0]);
  99. funcRouter(newAr, datas, router)
  100. next({ ...to, replace: true })
  101. } else {
  102. this.$message.error(msg);
  103. }
  104. })
  105. } else {
  106. if (router.options.routes[0].children.length == 0) {
  107. funcRouter(newAr, JSON.parse(menuList), router)
  108. next({ ...to, replace: true })
  109. } else {
  110. let thisAll = JSON.parse(menuList)[0];
  111. if (to.path == '/') {
  112. if (!!thisAll.children) {
  113. next({ path: `/${thisAll.children[0].linkPath}` })
  114. } else {
  115. next({ path: `/${thisAll.linkPath}` })
  116. }
  117. } else {
  118. next()
  119. }
  120. }
  121. }
  122. } else {
  123. next();
  124. }
  125. });
  126. new Vue({
  127. router,
  128. store,
  129. render: (h) => h(App),
  130. }).$mount('#app');
  131. Vue.prototype.$http = http;
  132. Vue.prototype.$api = apiService(http);