fuse-edit.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <template v-if="loaded" style="height: 100%">
  3. <Header></Header>
  4. <template v-if="fuseModels.length">
  5. <router-view v-slot="{ Component }">
  6. <!-- <keep-alive> -->
  7. <component :is="Component" />
  8. <!-- </keep-alive> -->
  9. </router-view>
  10. <GlobalSearch />
  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 { 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. watch(
  72. router.currentRoute,
  73. (_n, _, onClean) => {
  74. const meta = currentMeta.value;
  75. if (meta && "full" in meta && (meta as any).full) {
  76. enterEdit(() => {
  77. if (!history.state.back) {
  78. router.replace({ name: RoutesName.merge });
  79. } else {
  80. router.back();
  81. }
  82. });
  83. onClean(
  84. togetherCallback([
  85. showLeftPanoStack.push(ref(false)),
  86. showRightPanoStack.push(ref(false)),
  87. ])
  88. );
  89. }
  90. },
  91. { flush: "post", immediate: true }
  92. );
  93. watchEffect((onCleanup) => {
  94. if (!fuseModels.value.length) {
  95. onCleanup(showRightPanoStack.push(ref(false)));
  96. }
  97. });
  98. </script>
  99. <style lang="scss" scoped>
  100. .add-fuse-model {
  101. position: absolute;
  102. left: 50%;
  103. transform: translateX(-50%);
  104. width: 160px;
  105. z-index: 3;
  106. bottom: 10px;
  107. .icon {
  108. margin-right: 4px;
  109. }
  110. }
  111. </style>