createSubApp.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <component :is="component" />
  3. </template>
  4. <script setup lang="ts">
  5. import { ref, onBeforeUnmount, onBeforeMount, watch, nextTick } from 'vue';
  6. import { useRoute } from 'vue-router';
  7. import { getActions } from '/@/qiankun/state';
  8. import { activeApps } from '/@/qiankun/index';
  9. const route = useRoute();
  10. const component = ref<any>(null);
  11. async function resetComponent() {
  12. component.value = null;
  13. return nextTick(() => {
  14. return setTimeout(async () => {
  15. const appType = route.path.split('/')[1];
  16. if (appType === 'micro-need-air') {
  17. component.value = (await import('./needAir.vue')).default;
  18. } else if (appType === 'micro-vent-doc') {
  19. component.value = (await import('./ventDoc.vue')).default;
  20. } else if (appType === 'micro-vent-3dModal' || appType === 'micro-vent-2dModal') {
  21. if (route.query['isNoReverse'] != '1') {
  22. if (VENT_PARAM['is2DModel']) {
  23. component.value = (await import('./ventModal2D.vue')).default;
  24. } else {
  25. component.value = (await import('./ventModal.vue')).default;
  26. }
  27. } else if (appType === 'micro-vent-3dModal') {
  28. component.value = (await import('./ventModal.vue')).default;
  29. } else if (appType === 'micro-vent-2dModal') {
  30. component.value = (await import('./ventModal2D.vue')).default;
  31. }
  32. }
  33. }, 0);
  34. });
  35. }
  36. watch(
  37. () => [route.query, route.path],
  38. async ([newQuery, newPath], [oldQuery, oldPath]) => {
  39. debugger;
  40. // 这里判断
  41. if (newPath !== oldPath) {
  42. await resetComponent();
  43. } else if (newQuery !== oldQuery) {
  44. let isRefresh = false;
  45. if (Object.keys(oldQuery).length == 0 || Object.keys(newQuery).length == 0) {
  46. isRefresh = true;
  47. } else {
  48. for (const key in newQuery) {
  49. if (newQuery[key] !== oldQuery[key]) {
  50. isRefresh = true;
  51. break;
  52. }
  53. }
  54. }
  55. if (isRefresh) {
  56. const actions = getActions();
  57. actions.setGlobalState({ currentRouter: route });
  58. }
  59. }
  60. }
  61. );
  62. onBeforeMount(async () => {
  63. await resetComponent();
  64. });
  65. onBeforeUnmount(() => {
  66. component.value = null;
  67. });
  68. </script>