main.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // The Vue build version to load with the `import` command
  2. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
  3. import Vue from 'vue';
  4. import ElementUI from 'element-ui';
  5. // import Viewer from 'v-viewer'
  6. // import 'viewerjs/dist/viewer.css'
  7. import 'element-ui/lib/theme-chalk/index.css';
  8. import store from './store';
  9. import axios from 'axios';
  10. import VueBus from 'vue-bus'
  11. import config from './common/config.js'
  12. import dataSource from './common/data.source.js'
  13. import formTags from './common/form.tags.js'
  14. import formAction from './common/form.action.js'
  15. import './assets/icon/iconfont.css'
  16. import { postUserLogin } from '@/api/sysUser';
  17. import QRCode from 'qrcode'
  18. import ElTreeGrid from 'element-tree-grid'
  19. import importComponents from './importComponents';
  20. import ADialog from '@/components/common/a-dialog'
  21. import App from './App';
  22. import router from './router';
  23. Vue.component('a-dialog', ADialog);
  24. Vue.component(ElTreeGrid.name,ElTreeGrid)
  25. Vue.use(QRCode);
  26. Vue.use(VueBus);
  27. Vue.use(dataSource);
  28. Vue.use(formAction);
  29. Vue.prototype.$axios = axios;
  30. Vue.prototype.config = config;
  31. Vue.prototype.$eventBus = new Vue();
  32. importComponents(Vue)
  33. // Vue.use(Viewer)
  34. // Vue.use(Viewer, {
  35. // defaultOptions: {
  36. // zIndex: 9999,
  37. // title: false
  38. // }
  39. // })
  40. Vue.config.productionTip = false;
  41. Vue.use(ElementUI);
  42. Vue.use(require('vue-moment'));
  43. router.beforeEach((to, from, next) => {
  44. let userInfo = JSON.parse(localStorage.getItem('loginInfo'))
  45. if(userInfo) {
  46. if(userInfo.erp) { //ERP报表跳转DUP
  47. postUserLogin(
  48. {
  49. LoginCode: userInfo.LoginCode,
  50. PassWord: userInfo.PassWord,
  51. response: '0697056754B0C13C745662D33E1AC555',
  52. os: 'erp'
  53. },
  54. (response) => {
  55. sessionStorage.setItem('sysUserInfo', JSON.stringify(response));
  56. localStorage.removeItem('loginInfo')
  57. // next()
  58. next({ path: '/welcome' })
  59. },
  60. (error) => {
  61. next({ path: '/login' });
  62. },
  63. (exception) => {
  64. next({ path: '/login' });
  65. })
  66. return
  67. }
  68. }
  69. if(to.query.erp) { //ERP报表跳转DUP
  70. postUserLogin(
  71. {
  72. LoginCode: to.query.LoginCode,
  73. PassWord: to.query.PassWord,
  74. response: '0697056754B0C13C745662D33E1AC555',
  75. os: 'erp'
  76. },
  77. (response) => {
  78. sessionStorage.setItem('sysUserInfo', JSON.stringify(response));
  79. // next()
  80. next({ path: to.path })
  81. },
  82. (error) => {
  83. next({ path: '/login' });
  84. },
  85. (exception) => {
  86. next({ path: '/login' });
  87. })
  88. return
  89. }
  90. const sysUserInfo = JSON.parse(sessionStorage.getItem('sysUserInfo'));
  91. if(to.name == 'login') {
  92. if(sysUserInfo != {} && sysUserInfo != undefined && sysUserInfo != null){
  93. next({ path: '/welcome' });
  94. }else{
  95. sessionStorage.setItem('tongyitype', '1');
  96. next()
  97. }
  98. } else {
  99. if(sysUserInfo == null){
  100. // next(false)
  101. let tongyi=sessionStorage.getItem('tongyitype')
  102. if(tongyi){
  103. window.sessionStorage.removeItem('tongyitype');
  104. next()
  105. }else{
  106. next({ path: '/login' });
  107. }
  108. } else{
  109. next()
  110. }
  111. }
  112. })
  113. Vue.directive('right',{
  114.   update:function (el,binding) {
  115.     let key = binding.value.btnKey
  116.     const sysUserInfo = JSON.parse(sessionStorage.getItem('sysUserInfo'));
  117.     let showStatus = false
  118.     sysUserInfo.userFunctions.forEach(item => {
  119.       if(item.code === key) {
  120.         showStatus = item.enable
  121.         return
  122.       }
  123.     })
  124.     if(!showStatus){
  125.       if(el.parentNode) {
  126.         el.parentNode.removeChild(el)
  127.       }
  128.     }
  129.   }
  130. })
  131. /* eslint-disable no-new */
  132. new Vue({
  133. el: '#app',
  134. router,
  135. store,
  136. template: '<App/>',
  137. components: { App },
  138. });