main.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // eslint-disable-next-line no-undef
  2. //__webpack_nonce__ = '*NONCE_TOKEN*';
  3. // eslint-disable-next-line no-undef
  4. __webpack_nonce__ = window.nonce_token;
  5. import { createApp, defineAsyncComponent } from 'vue';
  6. //import { createApp, defineAsyncComponent } from 'vue/dist/vue.runtime.esm-browser.prod.js';
  7. // 修复异步组件中AntV控件不能打开的BUG。
  8. // import Antd from 'ant-design-vue';
  9. import * as Antd from 'ant-design-vue';
  10. import 'ant-design-vue/dist/reset.css';
  11. window.Antd = Antd;
  12. //console.log(Antd);
  13. // 修复异步组件中AntV控件不能打开的BUG。
  14. import * as AntdComponents from 'ant-design-vue';
  15. window.Antd = AntdComponents;
  16. import { createRouter, createWebHashHistory } from 'vue-router';
  17. import { createStore } from 'vuex';
  18. import * as PcComponentV3 from 'pc-component-v3';
  19. import 'pc-component-v3/dist/pc-component-v3.css';
  20. window.PcComponentV3 = PcComponentV3;
  21. import VTooltip from 'v-tooltip';
  22. import 'v-tooltip/dist/v-tooltip.css';
  23. import * as dd from 'dingtalk-jsapi';
  24. window.dd = dd;
  25. import 'jquery';
  26. import 'client-base-v4/dist/client-base-v4.css';
  27. import 'client-role-v3/dist/client-role-v3.css';
  28. // import 'client-dictionary-v3/dist/client-dictionary-v3.css';
  29. import 'client-dic-v3/dist/client-dic-v3.css';
  30. import 'client-eam-v3/dist/client-eam-v3.css';
  31. import 'client-wms-v3/dist/client-wms-v3.css';
  32. import 'client-sensor-v3/dist/client-sensor-v3.css';
  33. import { store } from './store.js';
  34. import { i18n } from './lang.js';
  35. import { router } from './routes/index.js';
  36. import { App, Common, PushMessage, CurdWindowModal, AuthImage } from 'client-base-v4/dist/client-base-v4.js';
  37. import { Notify } from 'pc-component-v3/dist/pc-component-v3.js';
  38. window.Common = Common;
  39. window.Notify = Notify;
  40. import * as AntDesignIconsVue from '@ant-design/icons-vue';
  41. window.AntDesignIconsVue = AntDesignIconsVue;
  42. const app = createApp(App);
  43. app.use(Antd);
  44. app.use(i18n);
  45. app.use(router);
  46. app.use(VTooltip);
  47. app.use(store);
  48. app.use(PcComponentV3);
  49. app.use(router);
  50. app.mount('#app');
  51. // 全局注册组件, CURD窗口模态框编辑器
  52. app.component('CurdWindowModal', CurdWindowModal);
  53. // 图片显示
  54. app.component('AuthImage', AuthImage);
  55. window.app = app;
  56. // 当页面刷新后重新打开声音提示
  57. if (window.performance.navigation.type == 1) {
  58. localStorage.setItem('allowSound', false)
  59. }
  60. /**
  61. * 路由钩子
  62. * @param {[type]} (to, from, next [description]
  63. * @return {[type]} [description]
  64. */
  65. router.beforeEach((to, from, next) => {
  66. let allowSound = localStorage.getItem('allowSound')
  67. // 不是登录页才进行消息推送
  68. if (to.fullPath !== '/login' && !to.path.includes('login') && !to.path.includes('Login')) {
  69. PushMessage.openWebSocket()
  70. if (allowSound && allowSound == 'false') {
  71. PushMessage.messageModal()
  72. }
  73. } else {
  74. PushMessage.closeWebsocket()
  75. }
  76. let funtionAccessDtos = [];
  77. if (to.matched.some(function (item) {
  78. // 判断是否需要登录才可以访问
  79. if (item.meta.loginRequired) {
  80. if (item.meta.functionAccessArray != undefined || item.meta.functionAccessArray != null) {
  81. funtionAccessDtos = item.meta.functionAccessArray;
  82. }
  83. if (funtionAccessDtos != null) {
  84. funtionAccessDtos.forEach(funtionAccessDto => {
  85. if (typeof (funtionAccessDto.itemNo) === 'string') {
  86. funtionAccessDto.itemNo = [funtionAccessDto.itemNo];
  87. }
  88. });
  89. }
  90. }
  91. return item.meta.loginRequired;
  92. })) {
  93. // 判断是否已登录
  94. var token = localStorage.getItem('#token');
  95. if (token == undefined || token.length == 0) {
  96. // 如果没有登录则直接返回
  97. next('/login');
  98. } else {
  99. // 判断该路由需要具备”xxx”功能-“x1”功能项,”xxx”功能-“x2“功能项,”yyy”功能-“y1”功能项访问权限的用户才可以访问
  100. $.ajax({
  101. url: Common.getApiURL(
  102. 'RoleResourceV3/canVisitFunctionAccess',
  103. ),
  104. type: 'post',
  105. dataType: 'json',
  106. contentType: 'application/json',
  107. data: JSON.stringify(funtionAccessDtos),
  108. beforeSend: function (request) {
  109. Common.addTokenToRequest(request);
  110. },
  111. success: function (data) {
  112. if (data.errorCode === 0 && data.data === true) {
  113. next();
  114. return;
  115. } else {
  116. next('/desktop/no-role');
  117. return;
  118. }
  119. },
  120. error: function (XMLHttpRequest, textStatus, errorThrown) {
  121. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  122. },
  123. });
  124. }
  125. } else {
  126. next();
  127. return;
  128. }
  129. });