main.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // eslint-disable-next-line no-undef
  2. __webpack_nonce__ = '*NONCE_TOKEN*';
  3. import { createApp, defineAsyncComponent } from 'vue';
  4. //import { createApp, defineAsyncComponent } from 'vue/dist/vue.runtime.esm-browser.prod.js';
  5. import Antd from 'ant-design-vue';
  6. // import 'ant-design-vue/dist/antd.css';
  7. import './assets/common.css';
  8. import './assets/common1.css';
  9. import { createI18n } from 'vue-i18n';
  10. import { createRouter, createWebHashHistory } from 'vue-router';
  11. //import { createI18n } from 'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js';
  12. //import { createI18n } from 'vue-i18n/dist/vue-i18n.runtime.esm-browser.js';
  13. import * as PcClientComponent from 'pc-component-v3';
  14. import 'pc-component-v3/dist/pc-component-v3.css';
  15. import App from '../src/App.vue';
  16. import VTooltip from 'v-tooltip';
  17. import 'v-tooltip/dist/v-tooltip.css';
  18. import * as dd from 'dingtalk-jsapi';
  19. window.dd = dd;
  20. import routes from './routes/main_routes.js';
  21. // console.log(window.$);
  22. // import $ from 'jquery';
  23. // console.log(window.$);
  24. //$ = window.$;
  25. // console.log($);
  26. import store from './store/index.js';
  27. import langZhCn from './locales/zh-CN.json';
  28. import langEnUs from './locales/en-US.json';
  29. import { Notify } from 'pc-component-v3/dist/pc-component-v3.js';
  30. window.Notify = Notify;
  31. const i18n = createI18n({
  32. locale: 'zh-CN',
  33. messages: {
  34. 'zh-CN': langZhCn,
  35. 'en-US': langEnUs,
  36. },
  37. });
  38. window.CRUDId = -2147483640;
  39. import Common from './common/Common.js';
  40. window.Common = Common;
  41. // 报NavigationDuplicated: Avoided redundant navigation to current location: "/" 的错
  42. //获取原型对象上的push函数
  43. // const originalPush = VueRouter.prototype.push;
  44. //修改原型对象中的push方法
  45. // VueRouter.prototype.push = function push(location) {
  46. // return originalPush.call(this, location).catch(err => err);
  47. // };
  48. // const config = {
  49. // errorBagName: 'errors', // change if property conflicts.
  50. // fieldsBagName: 'fieldsBagName',
  51. // delay: 0,
  52. // locale: 'en',
  53. // dictionary: null,
  54. // strict: true,
  55. // enableAutoClasses: false,
  56. // classNames: {
  57. // touched: 'touched', // the control has been blurred
  58. // untouched: 'untouched', // the control hasn't been blurred
  59. // valid: 'valid', // model is valid
  60. // invalid: 'invalid', // model is invalid
  61. // pristine: 'pristine', // control has not been interacted with
  62. // dirty: 'dirty', // control has been interacted with
  63. // },
  64. // events: 'input|blur',
  65. // inject: true,
  66. // };
  67. // Vue.use(config);
  68. const router = createRouter({
  69. history: createWebHashHistory(),
  70. base: '/',
  71. mode: 'hash',
  72. routes: routes,
  73. });
  74. const app = createApp(App);
  75. app.use(Antd);
  76. app.use(i18n);
  77. app.use(router);
  78. app.use(VTooltip);
  79. app.use(store);
  80. // PC Client 组件
  81. app.use(PcClientComponent);
  82. app.mount('#app');
  83. window.app = app;
  84. /**
  85. * 路由钩子
  86. * @param {[type]} (to, from, next [description]
  87. * @return {[type]} [description]
  88. */
  89. router.beforeEach((to, from, next) => {
  90. let funtionAccessDtos = [];
  91. if (to.matched.some(function (item) {
  92. // 判断是否需要登录才可以访问
  93. if (item.meta.loginRequired) {
  94. if (item.meta.functionAccessArray != undefined || item.meta.functionAccessArray != null) {
  95. funtionAccessDtos = item.meta.functionAccessArray;
  96. }
  97. if (funtionAccessDtos != null) {
  98. funtionAccessDtos.forEach(funtionAccessDto => {
  99. if (typeof (funtionAccessDto.itemNo) === 'string') {
  100. funtionAccessDto.itemNo = [funtionAccessDto.itemNo];
  101. }
  102. });
  103. }
  104. }
  105. return item.meta.loginRequired;
  106. })) {
  107. // 判断是否已登录
  108. var token = localStorage.getItem('#token');
  109. if (token == undefined || token.length == 0) {
  110. // 如果没有登录则直接返回
  111. next('/login');
  112. } else {
  113. // 判断该路由需要具备”xxx”功能-“x1”功能项,”xxx”功能-“x2“功能项,”yyy”功能-“y1”功能项访问权限的用户才可以访问
  114. $.ajax({
  115. url: Common.getApiURL(
  116. 'RoleResourceV3/canVisitFunctionAccess',
  117. ),
  118. type: 'post',
  119. dataType: 'json',
  120. contentType: 'application/json',
  121. data: JSON.stringify(funtionAccessDtos),
  122. beforeSend: function (request) {
  123. Common.addTokenToRequest(request);
  124. },
  125. success: function (data) {
  126. if (data.errorCode === 0 && data.data === true) {
  127. next();
  128. return;
  129. } else {
  130. next('/desktop/no-role');
  131. return;
  132. }
  133. },
  134. error: function (XMLHttpRequest, textStatus, errorThrown) {
  135. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  136. },
  137. });
  138. }
  139. } else {
  140. next();
  141. return;
  142. }
  143. });