main.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 directived from '@utils/directived';
  18. import http from '@utils/http.js';
  19. import apiService from './api/index';
  20. import store from './store/store.js';
  21. import '@utils/utils.js';
  22. import 'babel-polyfill';
  23. window.onresize = (e) => {
  24. store.commit('setScale', e.timeStamp);
  25. };
  26. var _ = require('lodash')
  27. import filter from './utils/filters';
  28. Object.keys(filter).forEach((key) => Vue.filter(key, filter[key]));
  29. // 滚动条
  30. import GeminiScrollbar from 'vue-gemini-scrollbar';
  31. Vue.use(GeminiScrollbar);
  32. Vue.prototype.$moment = moment;
  33. Vue.config.productionTip = false;
  34. Vue.use(Vuex);
  35. Vue.use(commonComponents);
  36. Vue.use(directiveInit);
  37. Vue.use(directived);
  38. Vue.use(ElementUI, {
  39. size: 'small'
  40. });
  41. //使用钩子函数对路由进行权限跳转
  42. router.beforeEach((to, from, next) => {
  43. document.title = store.getters['getThisDetai'].name || !!window.sessionStorage.getItem('setThisDetai') ? JSON.parse(window.sessionStorage.getItem('setThisDetai')).name : ''
  44. if (localStorage.getItem("SC_token")) {
  45. let menuList = window.sessionStorage.getItem("SC_listMuen")
  46. let newAr = [];
  47. if (menuList == null || menuList == undefined) {
  48. http.get('/sc-user-center/user/findUserMenu', { appId: '1013' }).then(({ status, data, msg }) => {
  49. if (0 == status) {
  50. let datas = data[0].children
  51. window.sessionStorage.setItem('SC_listMuen', JSON.stringify(datas))
  52. window.sessionStorage.setItem('setThisDetai', JSON.stringify(data[0]))
  53. store.commit('setThisDetai', data[0]);
  54. funcRouter(newAr, datas, router)
  55. next({ ...to, replace: true })
  56. } else {
  57. this.$message.error(msg);
  58. }
  59. })
  60. } else {
  61. if (router.options.routes[0].children.length == 0) {
  62. funcRouter(newAr, JSON.parse(menuList), router)
  63. next({ ...to, replace: true })
  64. } else {
  65. let thisAll = JSON.parse(menuList)[0];
  66. if (to.path == '/') {
  67. if (!!thisAll.children) {
  68. next({ path: `/${thisAll.children[0].linkPath}` })
  69. } else {
  70. next({ path: `/${thisAll.linkPath}` })
  71. }
  72. } else {
  73. next()
  74. }
  75. }
  76. }
  77. } else {
  78. next();
  79. }
  80. });
  81. new Vue({
  82. router,
  83. store,
  84. render: h => h(App),
  85. }).$mount('#app')
  86. Vue.prototype.$http = http;
  87. Vue.prototype.$api = apiService(http);