main.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import Vue from 'vue';
  2. import App from './App.vue';
  3. import router from './router';
  4. import { funcRouter } from './router/dynamicMuen';
  5. import Vuex from 'vuex';
  6. import ElementUI from 'element-ui';
  7. import commonComponents from './components/common';
  8. import 'element-ui/lib/theme-chalk/index.css'; // 默认主题
  9. import moment from 'moment';
  10. moment.locale('zh-cn');
  11. import './assets/css/icon.css';
  12. import './assets/css/main.scss';
  13. import './assets/css/element-variables.scss';
  14. import '@utils/rem.js';
  15. import '@utils/AmapSearch.js';
  16. import directiveInit from '@utils/directives';
  17. import http from '@utils/http.js';
  18. import apiService from './api/index';
  19. import store from './store/store.js';
  20. import '@utils/utils.js';
  21. import 'babel-polyfill';
  22. Vue.prototype.$moment = moment;
  23. Vue.config.productionTip = false;
  24. Vue.use(Vuex);
  25. Vue.use(commonComponents);
  26. Vue.use(directiveInit);
  27. Vue.use(ElementUI, {
  28. size: 'small'
  29. });
  30. window.onresize = () => {
  31. let size = document.body.clientWidth / 1920;
  32. store.commit("setScale", size);
  33. };
  34. Vue.prototype.routerLoad = {
  35. findOne(arr) {
  36. return arr.map(v => {
  37. if (v.children) {
  38. return this.findOne(v.children)
  39. } else {
  40. return {
  41. path: "/" + v.linkPath,
  42. name: v.name
  43. }
  44. }
  45. })
  46. },
  47. findMen(arr, indexPath) {
  48. let status = false;
  49. arr.map(v => {
  50. if (v.children) {
  51. this.findMen(v.children)
  52. } else {
  53. if (('/' + v.linkPath) === indexPath) {
  54. status = true
  55. }
  56. }
  57. })
  58. return status
  59. },
  60. close() {
  61. let activeRout = localStorage.getItem('path');
  62. let tagsList = store.getters['getTagsList'];
  63. tagsList.forEach((item, index) => {
  64. if (item.path == activeRout) {
  65. tagsList.splice(index, 1);
  66. return true;
  67. }
  68. });
  69. },
  70. };
  71. router.beforeEach((to, from, next) => {
  72. document.title = store.getters['getThisDetai'].name || !!window.sessionStorage.getItem('setThisDetai') ? JSON.parse(window.sessionStorage.getItem('setThisDetai')).name : ''
  73. if (localStorage.getItem("SC_token")) {
  74. let menuList = window.sessionStorage.getItem("SC_listMuen")
  75. let newAr = [];
  76. if (menuList == null || menuList == undefined) {
  77. http.get('/sc-user-center/user/findUserMenu', { appId: '1003' }).then(({ status, data, msg }) => {
  78. if (0 == status) {
  79. let datas = data[0].children
  80. window.sessionStorage.setItem('SC_listMuen', JSON.stringify(datas))
  81. window.sessionStorage.setItem('setThisDetai', JSON.stringify(data[0]))
  82. store.commit('setThisDetai', data[0]);
  83. funcRouter(newAr, datas, router)
  84. next({ ...to, replace: true })
  85. } else {
  86. this.$message.error(msg);
  87. }
  88. })
  89. } else {
  90. if (router.options.routes[0].children.length == 0) {
  91. funcRouter(newAr, JSON.parse(menuList), router)
  92. next({ ...to, replace: true })
  93. } else {
  94. let thisAll = JSON.parse(menuList)[0];
  95. if (to.path == '/') {
  96. if (!!thisAll.children) {
  97. next({ path: `/${thisAll.children[0].linkPath}` })
  98. } else {
  99. next({ path: `/${thisAll.linkPath}` })
  100. }
  101. } else {
  102. next()
  103. }
  104. }
  105. }
  106. } else {
  107. next();
  108. }
  109. });
  110. new Vue({
  111. router,
  112. store,
  113. render: h => h(App),
  114. }).$mount('#app');
  115. Vue.prototype.$http = http;
  116. Vue.prototype.$api = apiService(http);