main.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import Vue from 'vue'
  2. import App from './App'
  3. import VueRouter from 'vue-router'
  4. import ElementUI from 'element-ui'
  5. import 'element-ui/lib/theme-chalk/index.css'
  6. //import 'element-ui/lib/theme-default/index.css'
  7. //import './assets/theme/theme-green/index.css'
  8. import store from './vuex/store'
  9. import Vuex from 'vuex'
  10. //import NProgress from 'nprogress'
  11. //import 'nprogress/nprogress.css'
  12. import routes from './routes'
  13. // import Mock from './mock'
  14. // Mock.bootstrap();
  15. import $ from 'jquery'
  16. import http from './http'
  17. Vue.prototype.http = http
  18. import port from './port'
  19. Vue.prototype.port = port
  20. import 'font-awesome/css/font-awesome.min.css'
  21. import './assets/iconfont/iconfont.css'
  22. Vue.use(ElementUI)
  23. Vue.use(VueRouter)
  24. Vue.use(Vuex)
  25. const router = new VueRouter({
  26. routes
  27. })
  28. router.beforeEach((to, from, next) => {
  29. if (to.path == '/login') {
  30. sessionStorage.removeItem('user');
  31. }
  32. let user = JSON.parse(sessionStorage.getItem('user'));
  33. if (!user && to.path != '/login') {
  34. next({ path: '/login' })
  35. } else {
  36. if(user){
  37. for(var i in routes){
  38. if(routes[i].name == "基础管理" && user.parentId != 0){
  39. routes[i].hidden = true
  40. } else if(routes[i].name == "基础管理"){
  41. routes[i].hidden = false
  42. }
  43. if(routes[i].name == "项目管理" && user.parentId > 1){
  44. var children = routes[i].children;
  45. for(var j in children){
  46. if(children[j].name == "人员管理" && user.isManager == 0){
  47. children[j].hidden = true
  48. }
  49. if(children[j].name == "权限管理" && user.isManager == 0){
  50. children[j].hidden = true
  51. }
  52. }
  53. } else if(routes[i].name == "项目管理") {
  54. var children = routes[i].children;
  55. for(var j in children){
  56. if(children[j].name != "项目详情"){
  57. children[j].hidden = false
  58. }
  59. }
  60. }
  61. }
  62. }
  63. next()
  64. }
  65. })
  66. // router.afterEach(transition => {
  67. // NProgress.done();
  68. // });
  69. new Vue({
  70. //el: '#app',
  71. //template: '<App/>',
  72. router,
  73. store,
  74. //components: { App }
  75. render: h => h(App)
  76. }).$mount('#app')