main.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import Vue from 'vue'
  2. import App from './App.vue'
  3. import router from './router'
  4. import store from '$project/store'
  5. //引入mui
  6. import mui from '$project/assets/js/mui.js'
  7. import '$project/assets/css/mui.min.css'
  8. import Vconsole from 'vconsole'
  9. window.mui = mui;
  10. window.mui.init();
  11. if (location.hostname === 'localhost') {
  12. Vue.prototype.HTTPLOCAT = ''
  13. } else {
  14. const http = window.location.protocol + '//' + location.hostname + ':' + location.port
  15. Vue.prototype.HTTPLOCAT = http + ''
  16. }
  17. Vue.config.productionTip = false
  18. //图片预览
  19. import VueDirectiveImagePreviewer from 'vue-directive-image-previewer'
  20. import 'vue-directive-image-previewer/dist/assets/style.css'
  21. Vue.use(VueDirectiveImagePreviewer, {
  22. background: {
  23. color: '#000'
  24. },
  25. // transition
  26. animate: {
  27. duration: 600,
  28. delay: 500
  29. },
  30. // loading (not supported)
  31. loading: {
  32. image: ''
  33. },
  34. // cursor(css)
  35. cursor: 'pointer',
  36. clickMethod: 'doubleClick'
  37. })
  38. //获取纯权限路由数组
  39. let funList = [];
  40. let fun_list = store.state.fun_list;
  41. if (fun_list && fun_list.length > 0) {
  42. fun_list.forEach(function(item) {
  43. item.list.forEach(function(iten) {
  44. funList.push(iten.iconRoute);
  45. if (iten.iconSubRouteList) {
  46. iten.iconSubRouteList.forEach(function(iteb) {
  47. funList.push(iteb)
  48. })
  49. }
  50. })
  51. })
  52. }
  53. //console.log(funList)
  54. router.beforeEach((to, from, next) => {
  55. if (to.query.test) {
  56. if (to.query.test == 'test') {
  57. let vConsole = new Vconsole()
  58. }
  59. }
  60. if (to.meta != null && to.meta.requireAuth) {
  61. if (store.state.person_data) {
  62. if ((to.meta.form != null && to.meta.form) || (to.meta.mode != null && to.meta.mode)) {
  63. //验证
  64. if (funList.indexOf(to.name) > -1) {
  65. next();
  66. } else {
  67. //测试环境不验证权限
  68. if (process.env.VUE_APP_NODE_NAME == 'devlopment') {
  69. next();
  70. } else {
  71. mui.toast('无权访问');
  72. }
  73. }
  74. } else {
  75. //不验证
  76. next();
  77. }
  78. } else {
  79. window.location.href = '../home/#/user/login';
  80. }
  81. } else {
  82. next();
  83. }
  84. })
  85. new Vue({
  86. router,
  87. store,
  88. render: h => h(App)
  89. }).$mount('#app')