main.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import './public-path';
  2. import Vue from 'vue';
  3. import EleAdmin from 'ele-admin';
  4. import VueClipboard from 'vue-clipboard2';
  5. import App from './App.vue';
  6. import router, { resetRouter } from './router';
  7. import store from './store';
  8. import permission from './utils/permission';
  9. import initParentStore from '../qiankun_config/store';
  10. import i18n from './i18n';
  11. import { MAP_KEY, LICENSE_CODE, SYSTEM_NAME } from '@/config/setting';
  12. import { installMessageGuard } from '@/utils/message';
  13. import HeaderTitle from '@/components/header-title';
  14. import DictSelection from '@/components/Dict/DictSelection';
  15. import fileMain from '@/components/addDoc/index.vue';
  16. import clickOnce from '@/utils/clickOnce';
  17. import MyPD from '@/components/bpmnProcessDesigner/package/index.js';
  18. import '@/components/bpmnProcessDesigner/package/theme/viewer.scss';
  19. import 'bpmn-js/dist/assets/diagram-js.css';
  20. import 'bpmn-js/dist/assets/bpmn-font/css/bpmn.css';
  21. import 'bpmn-js/dist/assets/bpmn-font/css/bpmn-codes.css';
  22. import 'bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css';
  23. import 'nprogress/nprogress.css';
  24. import './styles/index.scss';
  25. // 独立运行标记:样式仅在该 class 下接管 html/body,避免乾坤冲掉主应用侧栏
  26. if (!window.__POWERED_BY_QIANKUN__) {
  27. document.documentElement.classList.add('hr-standalone');
  28. }
  29. Vue.config.productionTip = false;
  30. Vue.directive('click-once', clickOnce);
  31. Vue.component('HeaderTitle', HeaderTitle);
  32. Vue.component('DictSelection', DictSelection);
  33. Vue.component('fileMain', fileMain);
  34. Vue.use(MyPD);
  35. Vue.use(permission);
  36. Vue.use(EleAdmin, {
  37. response: {
  38. dataName: 'list',
  39. },
  40. mapKey: MAP_KEY,
  41. license: LICENSE_CODE,
  42. i18n: (key, value) => i18n.t(key, value),
  43. });
  44. Vue.use(VueClipboard);
  45. installMessageGuard(Vue);
  46. function disableOverlayClose(componentName) {
  47. const component = Vue.options.components[componentName];
  48. if (!component) return;
  49. const options = component.options || component;
  50. const props = options.props;
  51. if (!props) return;
  52. if (props.closeOnClickModal) props.closeOnClickModal.default = false;
  53. if (props.wrapperClosable) props.wrapperClosable.default = false;
  54. }
  55. ['ElDialog', 'ElDrawer', 'EleModal'].forEach(disableOverlayClose);
  56. function wrapMessageBox(method) {
  57. const original = Vue.prototype[method];
  58. if (typeof original !== 'function') return;
  59. Vue.prototype[method] = function (message, title, options) {
  60. if (title !== null && typeof title === 'object') {
  61. options = title;
  62. title = undefined;
  63. }
  64. const nextOptions = { ...(options || {}), closeOnClickModal: false };
  65. if (title === undefined) {
  66. return original.call(this, message, nextOptions);
  67. }
  68. return original.call(this, message, title, nextOptions);
  69. };
  70. }
  71. ['$msgbox', '$confirm', '$prompt'].forEach(wrapMessageBox);
  72. let instance = null;
  73. function render(props = {}) {
  74. const { container, parentWindow } = props;
  75. if (parentWindow) {
  76. window.parentWindow = parentWindow;
  77. }
  78. instance = new Vue({
  79. router,
  80. store,
  81. i18n,
  82. render: (h) => h(App),
  83. }).$mount(container ? container.querySelector('#app') : '#app');
  84. }
  85. if (!window.__POWERED_BY_QIANKUN__) {
  86. render();
  87. }
  88. export async function bootstrap() {
  89. console.info('[page-hr] bootstrap');
  90. }
  91. export async function mount(props) {
  92. console.log('[page-hr] props from main framework', props);
  93. Vue.prototype.$portalStore = props.store;
  94. // 与 EOM 一致:只同步主题/用户,绝不改门户 menus
  95. initParentStore(props.store?.state || props.store);
  96. if (typeof props.onGlobalStateChange === 'function') {
  97. props.onGlobalStateChange((state) => {
  98. initParentStore(state);
  99. });
  100. }
  101. // 乾坤下强制校正 router base 为 /page-hr/
  102. if (
  103. window.__POWERED_BY_QIANKUN__ &&
  104. !String(router.options?.base || '').includes(`page-${SYSTEM_NAME}`)
  105. ) {
  106. resetRouter();
  107. }
  108. render(props);
  109. }
  110. export async function unmount() {
  111. if (instance) {
  112. instance.$destroy();
  113. instance.$el.innerHTML = '';
  114. }
  115. instance = null;
  116. }