main.js 1.9 KB

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