main.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 { store } from './store.js';
  26. import { i18n } from './lang.js';
  27. import { router } from './routes/index.js';
  28. import { App, Common } from 'client-base-v4/dist/client-base-v4.js';
  29. window.Common = Common;
  30. const app = createApp(App);
  31. app.use(Antd);
  32. app.use(i18n);
  33. app.use(router);
  34. app.use(VTooltip);
  35. app.use(store);
  36. app.use(PcClientComponent);
  37. app.use(router);
  38. app.mount('#app');
  39. window.app = app;
  40. /**
  41. * 路由钩子
  42. * @param {[type]} (to, from, next [description]
  43. * @return {[type]} [description]
  44. */
  45. router.beforeEach((to, from, next) => {
  46. let funtionAccessDtos = [];
  47. if (to.matched.some(function (item) {
  48. // 判断是否需要登录才可以访问
  49. if (item.meta.loginRequired) {
  50. if (item.meta.functionAccessArray != undefined || item.meta.functionAccessArray != null) {
  51. funtionAccessDtos = item.meta.functionAccessArray;
  52. }
  53. if (funtionAccessDtos != null) {
  54. funtionAccessDtos.forEach(funtionAccessDto => {
  55. if (typeof (funtionAccessDto.itemNo) === 'string') {
  56. funtionAccessDto.itemNo = [funtionAccessDto.itemNo];
  57. }
  58. });
  59. }
  60. }
  61. return item.meta.loginRequired;
  62. })) {
  63. // 判断是否已登录
  64. var token = localStorage.getItem('#token');
  65. if (token == undefined || token.length == 0) {
  66. // 如果没有登录则直接返回
  67. next('/login');
  68. } else {
  69. // 判断该路由需要具备”xxx”功能-“x1”功能项,”xxx”功能-“x2“功能项,”yyy”功能-“y1”功能项访问权限的用户才可以访问
  70. $.ajax({
  71. url: Common.getApiURL(
  72. 'RoleResourceV3/canVisitFunctionAccess',
  73. ),
  74. type: 'post',
  75. dataType: 'json',
  76. contentType: 'application/json',
  77. data: JSON.stringify(funtionAccessDtos),
  78. beforeSend: function (request) {
  79. Common.addTokenToRequest(request);
  80. },
  81. success: function (data) {
  82. if (data.errorCode === 0 && data.data === true) {
  83. next();
  84. return;
  85. } else {
  86. next('/desktop/no-role');
  87. return;
  88. }
  89. },
  90. error: function (XMLHttpRequest, textStatus, errorThrown) {
  91. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  92. },
  93. });
  94. }
  95. } else {
  96. next();
  97. return;
  98. }
  99. });