main.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { createApp } from "vue";
  2. import App from "@/App.vue";
  3. import router from "@/router";
  4. import store from "@/store";
  5. import { isMicroApp } from "@/config";
  6. import microApp from "@micro-zoe/micro-app";
  7. // @kasite/intelmt-plus 弹窗和loading单独引入
  8. import { ElMessage, ElLoading } from "@kasite/element-plus";
  9. import "@kasite/element-plus/theme-chalk/base.css";
  10. import "@kasite/element-plus/theme-chalk/display.css";
  11. import "@kasite/element-plus/theme-chalk/el-overlay.css";
  12. import "@kasite/element-plus/theme-chalk/el-message.css";
  13. import "@kasite/element-plus/theme-chalk/el-message-box.css";
  14. import "@kasite/element-plus/theme-chalk/el-loading.css";
  15. import ZyAdminComponents from "@kasite/intelmt-admin/components";
  16. import toolEntry from "@/utils/tool-entry";
  17. import interfaceEntry from "@/service/interface-entry";
  18. // px转rem
  19. import "@kasite/intelmt-admin/utils/tool/px2rem";
  20. const app = createApp(App);
  21. app.config.globalProperties.$ELEMENT = { size: "default" };
  22. app.config.globalProperties.$message = ElMessage;
  23. app.config.globalProperties.$messageBox = toolEntry.common.messageBox;;
  24. app.config.globalProperties.$loading = ElLoading;
  25. app.config.globalProperties.$store = store;
  26. app.config.globalProperties.$toolEntry = toolEntry;
  27. app.config.globalProperties.$interfaceEntry = interfaceEntry;
  28. import * as ElementPlusIconsVue from "@element-plus/icons-vue";
  29. for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  30. app.component(`el-icon${key.replace(/([A-Z])/g, "-$1").toLowerCase()}`, component as any);
  31. }
  32. app.use(store).use(router).use(ZyAdminComponents).mount("#app");
  33. // 启用微前端嵌入别的页面
  34. if (isMicroApp) {
  35. microApp.start({
  36. tagName: `micro-app-demo`
  37. });
  38. }
  39. // 如果是微前端
  40. if (window.__MICRO_APP_ENVIRONMENT__) {
  41. // eslint-disable-next-line
  42. __webpack_public_path__ = window.__MICRO_APP_PUBLIC_PATH__;
  43. // 重定向
  44. const data = window.microApp.getData();
  45. if(data.redirect) {
  46. // 如果绑定的重定向数据发生变化,路由进行跳转
  47. window.microApp.addDataListener(() => {
  48. const {redirect} = window.microApp.getData()
  49. redirect && router.push({ path: redirect });
  50. })
  51. }
  52. router.push({ path: data.redirect || window.config.index });
  53. // 监听卸载操作
  54. window.addEventListener("unmount", function () {
  55. app.unmount();
  56. });
  57. }
  58. // 如果是iframe
  59. else {
  60. window.addEventListener("load", () => {
  61. setTimeout(() => {
  62. if (window.__INTERMT_IFRAME__) {
  63. app.config.globalProperties.$frameEntry = window.$frameEntry;
  64. }
  65. }, 0);
  66. });
  67. }