main.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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-sensor-v3/dist/client-sensor-v3.css';
  25. import { store } from './store.js';
  26. import { i18n } from './lang.js';
  27. import { router } from './routes/index.js';
  28. import { App, Common, PushMessage } from 'client-base-v4/dist/client-base-v4.js';
  29. import { Notify } from 'pc-component-v3/dist/pc-component-v3.js';
  30. window.Common = Common;
  31. window.Notify = Notify;
  32. const menuColor = {
  33. logoWidth: 152, // logo宽度 (80)
  34. mainColor: '#2a3f54', // 菜单栏主题色 ('#277fd0')
  35. secondLevelColor: 'linear-gradient(#334556, #2c4257), #2a3f54', // 二级菜单颜色 ('#2e8ee7')
  36. threeLevelColor: '#495d70', // 三级菜单悬浮颜色 ('#6db0ee')
  37. searchInputColor: '#1c3e4b', // 菜单搜索框颜色 ('#1673c0')
  38. }
  39. localStorage.setItem('menuSetting',JSON.stringify(menuColor))
  40. const app = createApp(App);
  41. app.use(Antd);
  42. app.use(i18n);
  43. app.use(router);
  44. app.use(VTooltip);
  45. app.use(store);
  46. app.use(PcClientComponent);
  47. app.use(router);
  48. app.mount('#app');
  49. window.app = app;
  50. // 当页面刷新后重新打开声音提示
  51. if (window.performance.navigation.type == 1) {
  52. localStorage.setItem('allowSound', false)
  53. }
  54. /**
  55. * 路由钩子
  56. * @param {[type]} (to, from, next [description]
  57. * @return {[type]} [description]
  58. */
  59. router.beforeEach((to, from, next) => {
  60. let allowSound = localStorage.getItem('allowSound')
  61. // 不是登录页才进行消息推送
  62. if (to.fullPath !== '/login' && !to.path.includes('login') && !to.path.includes('Login')) {
  63. PushMessage.openWebSocket()
  64. if (allowSound && allowSound == 'false') {
  65. PushMessage.messageModal()
  66. }
  67. } else {
  68. PushMessage.closeWebsocket()
  69. }
  70. let funtionAccessDtos = [];
  71. if (to.matched.some(function (item) {
  72. // 判断是否需要登录才可以访问
  73. if (item.meta.loginRequired) {
  74. if (item.meta.functionAccessArray != undefined || item.meta.functionAccessArray != null) {
  75. funtionAccessDtos = item.meta.functionAccessArray;
  76. }
  77. if (funtionAccessDtos != null) {
  78. funtionAccessDtos.forEach(funtionAccessDto => {
  79. if (typeof (funtionAccessDto.itemNo) === 'string') {
  80. funtionAccessDto.itemNo = [funtionAccessDto.itemNo];
  81. }
  82. });
  83. }
  84. }
  85. return item.meta.loginRequired;
  86. })) {
  87. // 判断是否已登录
  88. var token = localStorage.getItem('#token');
  89. if (token == undefined || token.length == 0) {
  90. // 如果没有登录则直接返回
  91. next('/login');
  92. } else {
  93. // 判断该路由需要具备”xxx”功能-“x1”功能项,”xxx”功能-“x2“功能项,”yyy”功能-“y1”功能项访问权限的用户才可以访问
  94. $.ajax({
  95. url: Common.getApiURL(
  96. 'RoleResourceV3/canVisitFunctionAccess',
  97. ),
  98. type: 'post',
  99. dataType: 'json',
  100. contentType: 'application/json',
  101. data: JSON.stringify(funtionAccessDtos),
  102. beforeSend: function (request) {
  103. Common.addTokenToRequest(request);
  104. },
  105. success: function (data) {
  106. if (data.errorCode === 0 && data.data === true) {
  107. next();
  108. return;
  109. } else {
  110. next('/desktop/no-role');
  111. return;
  112. }
  113. },
  114. error: function (XMLHttpRequest, textStatus, errorThrown) {
  115. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  116. },
  117. });
  118. }
  119. } else {
  120. next();
  121. return;
  122. }
  123. });