main.js 5.2 KB

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