main.js 2.8 KB

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