main.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import Vue from 'vue';
  2. import './public-path';
  3. import App from './App.vue';
  4. import store from './store';
  5. import router from './router';
  6. import permission from './utils/permission';
  7. import { MAP_KEY, LICENSE_CODE } from '@/config/setting';
  8. import EleAdmin from 'ele-admin';
  9. import VueClipboard from 'vue-clipboard2';
  10. import i18n from './i18n';
  11. import './styles/index.scss';
  12. import DictSelection from '@/components/Dict/DictSelection';
  13. import HeaderTitle from '@/components/header-title';
  14. import initParentStore from '../qiankun_config/store';
  15. import { create, all } from 'mathjs'; // 引入mathjs工具并初始化
  16. const config = {
  17. number: 'BigNumber',
  18. precision: 64
  19. };
  20. Vue.prototype.$math = create(all, config);
  21. Vue.component('HeaderTitle', HeaderTitle);
  22. // // register globally
  23. import '@/icons';
  24. Vue.component('DictSelection', DictSelection);
  25. Vue.config.productionTip = false;
  26. Vue.use(EleAdmin, {
  27. response: {
  28. dataName: 'list'
  29. },
  30. mapKey: MAP_KEY,
  31. license: LICENSE_CODE,
  32. i18n: (key, value) => i18n.t(key, value)
  33. });
  34. Vue.use(permission);
  35. Vue.use(VueClipboard);
  36. let instance = null;
  37. function render(props = {}) {
  38. const { container, routerBase } = props;
  39. // const router = new VueRouter({
  40. // base: window.__POWERED_BY_QIANKUN__ ? routerBase : process.env.BASE_URL,
  41. // mode: 'history',
  42. // routes
  43. // });
  44. instance = new Vue({
  45. router,
  46. store,
  47. i18n,
  48. render: (h) => h(App)
  49. }).$mount(container ? container.querySelector('#app') : '#app');
  50. }
  51. if (!window.__POWERED_BY_QIANKUN__) {
  52. // 这里是子应用独立运行的环境,实现子应用的登录逻辑
  53. render();
  54. }
  55. export async function bootstrap() {
  56. console.log('[vue] vue app bootstraped');
  57. }
  58. export async function mount(props) {
  59. console.log('[vue] props from main framework', props);
  60. initParentStore(props.store);
  61. props.onGlobalStateChange((state, prev) => {
  62. // state: 变更后的状态; prev 变更前的状态
  63. initParentStore(state);
  64. });
  65. render(props);
  66. }
  67. export async function unmount() {
  68. instance.$destroy();
  69. instance.$el.innerHTML = '';
  70. instance = null;
  71. }