fuse-edit.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <template v-if="loaded" style="height: 100%">
  3. <Header></Header>
  4. <GlobalSearch :enable="fuseModels.length === 0 ? 'map-' : undefined" />
  5. <template v-if="fuseModels.length">
  6. <router-view v-slot="{ Component }">
  7. <!-- <keep-alive> -->
  8. <component :is="Component" />
  9. <!-- </keep-alive> -->
  10. </router-view>
  11. </template>
  12. <SelectModel v-else>
  13. <ui-button type="primary" class="add-fuse-model">
  14. <ui-icon type="add" />添加数据
  15. </ui-button>
  16. </SelectModel>
  17. </template>
  18. </template>
  19. <script lang="ts" setup>
  20. import { ref, watch, watchEffect, nextTick } from "vue";
  21. import { back, currentMeta, router, RoutesName } from "@/router";
  22. import { showLeftPanoStack, showRightPanoStack } from "@/env";
  23. import { asyncTimeout, togetherCallback } from "@/utils";
  24. import { loadModel, fuseModel } from "@/model";
  25. import GlobalSearch from "@/components/global-search/index.vue";
  26. import {
  27. enterEdit,
  28. isOld,
  29. save,
  30. fuseModels,
  31. initialFuseModels,
  32. initialScenes,
  33. initialTaggingStyles,
  34. initialTaggings,
  35. initialGuides,
  36. initialMeasures,
  37. fuseModelsLoaded,
  38. initialPaths,
  39. initMonitors,
  40. } from "@/store";
  41. import Header from "./header/index.vue";
  42. import SelectModel from "./scene-select.vue";
  43. import { initialAnimationModels } from "@/store/animation";
  44. const loaded = ref(false);
  45. const initialSys = async () => {
  46. await Promise.all([initialFuseModels(), initialScenes()]);
  47. await Promise.all([
  48. initialTaggingStyles(),
  49. initialTaggings(),
  50. initialGuides(),
  51. initialPaths(),
  52. initialMeasures(),
  53. initMonitors(),
  54. initialAnimationModels(),
  55. ]);
  56. await loadModel(fuseModel);
  57. const stop = watchEffect(() => {
  58. if (fuseModelsLoaded.value) {
  59. loaded.value = true;
  60. nextTick(() => stop());
  61. }
  62. });
  63. };
  64. initialSys();
  65. router.beforeEach(async (to, from, next) => {
  66. if (to.params.save && isOld.value) {
  67. await save();
  68. }
  69. next();
  70. });
  71. const routes: any[] = [];
  72. watch(
  73. router.currentRoute,
  74. (_n, _, onClean) => {
  75. const meta = currentMeta.value;
  76. if (meta && "full" in meta && (meta as any).full) {
  77. enterEdit(() => {
  78. back();
  79. });
  80. onClean(
  81. togetherCallback([
  82. showLeftPanoStack.push(ref(false)),
  83. showRightPanoStack.push(ref(false)),
  84. ])
  85. );
  86. }
  87. },
  88. { flush: "post", immediate: true }
  89. );
  90. watchEffect((onCleanup) => {
  91. if (!fuseModels.value.length) {
  92. onCleanup(showRightPanoStack.push(ref(false)));
  93. }
  94. });
  95. </script>
  96. <style lang="scss" scoped>
  97. .add-fuse-model {
  98. position: absolute;
  99. left: 50%;
  100. transform: translateX(-50%);
  101. width: 160px;
  102. z-index: 3;
  103. bottom: 10px;
  104. .icon {
  105. margin-right: 4px;
  106. }
  107. }
  108. </style>