main.js 4.0 KB

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