container.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <div class="canvas-layout">
  3. <p v-if="currentMeterPerPixel" class="meterPerPixel">1: {{ currentMeterPerPixel }}</p>
  4. <div class="scene-canvas" ref="sceneLayoutRef" />
  5. </div>
  6. </template>
  7. <script setup lang="ts">
  8. import { onActivated, onDeactivated, onMounted, ref, watchEffect } from "vue";
  9. import { customMap, disabledMap, setupLaser, useLoading, useParams } from "@/hook";
  10. import { store } from "@/store";
  11. import { currentApp } from "@/store/app";
  12. import { Loading } from "@kankan/components/index";
  13. import { LaserSDK, Mode, SeSceneCropSetting } from "@/sdk";
  14. import { api } from "@/store/sync";
  15. import { sceneSeting } from "@/store/sceneSeting";
  16. const emit = defineEmits<{ (e: "loaded"): void }>();
  17. const sceneLayoutRef = ref<HTMLCanvasElement>();
  18. const active = ref(true);
  19. onActivated(() => (active.value = true));
  20. onDeactivated(() => (active.value = false));
  21. const handlerSDK = (sdk: LaserSDK) => {
  22. watchEffect(() => {
  23. sdk.scene.emit("visible", active.value);
  24. });
  25. };
  26. const currentMeterPerPixel = ref(0);
  27. onMounted(async () => {
  28. const sdk = await useLoading(
  29. setupLaser({
  30. sceneSelector: sceneLayoutRef.value,
  31. num: useParams().m,
  32. store: store,
  33. isDebug: useParams().test,
  34. getFileUrl: api.getFile,
  35. webSite: "",
  36. axios: null,
  37. basePath: currentApp.basePath,
  38. })
  39. );
  40. emit("loaded");
  41. sdk.scene.on("posChange", (pos) => {
  42. currentMeterPerPixel.value = pos.meterPerPixel
  43. ? Math.round(1 / pos.meterPerPixel)
  44. : null;
  45. });
  46. watchEffect(() => {
  47. if (sceneSeting.value) {
  48. sdk.scene.setSceneCropSetting({
  49. top: { value: sceneSeting.value.top },
  50. rotate: { value: sceneSeting.value.rotate },
  51. scale: { value: sceneSeting.value.scale },
  52. });
  53. } else {
  54. const setting = sdk.scene.getSceneCropSetting();
  55. console.log(setting);
  56. sceneSeting.value = {
  57. top: setting.top.value,
  58. rotate: setting.rotate.value,
  59. scale: setting.scale.value,
  60. };
  61. }
  62. });
  63. // 156 170
  64. // 90
  65. setTimeout(() => {
  66. watchEffect(() => {
  67. const doms = Array.from(
  68. sceneLayoutRef.value.querySelectorAll("#navCube, #home")
  69. ) as HTMLElement[];
  70. if (!disabledMap.mode) {
  71. if (customMap.mode === Mode.pano) {
  72. doms.forEach((dom) => {
  73. dom.style.display = "none";
  74. });
  75. } else {
  76. doms.forEach((dom) => {
  77. dom.style.display = "block";
  78. });
  79. }
  80. }
  81. handlerSDK(sdk);
  82. });
  83. Loading.hideAll();
  84. }, 1000);
  85. });
  86. </script>
  87. <style scoped lang="scss">
  88. .canvas-layout {
  89. width: 100%;
  90. height: 100%;
  91. position: relative;
  92. z-index: 0;
  93. }
  94. .scene-canvas {
  95. width: 100%;
  96. height: 100%;
  97. }
  98. .dire-canvas {
  99. position: absolute;
  100. right: 0;
  101. top: 0;
  102. }
  103. </style>
  104. <style lang="scss">
  105. .canvas-layout {
  106. .meterPerPixel,
  107. #navCube {
  108. position: absolute !important;
  109. right: calc(var(--boundMargin) + 10px) !important;
  110. top: calc(var(--boundMargin) + 10px) !important;
  111. // z-index: 1;
  112. }
  113. #home {
  114. position: absolute !important;
  115. right: var(--boundMargin) !important;
  116. top: var(--boundMargin) !important;
  117. display: flex;
  118. align-items: center;
  119. justify-content: center;
  120. width: 20px !important;
  121. height: 20px !important;
  122. font-family: "iconfont" !important;
  123. font-size: 20px;
  124. color: #fff;
  125. font-style: normal;
  126. -webkit-font-smoothing: antialiased;
  127. background: none !important;
  128. z-index: 2;
  129. color: #fff;
  130. transition: all 0.3s ease;
  131. &:before {
  132. content: "\e73e";
  133. pointer-events: none;
  134. }
  135. &:active {
  136. color: #3290ff;
  137. }
  138. }
  139. .meterPerPixel {
  140. text-align: center;
  141. width: 100px;
  142. color: #fff;
  143. margin-top: 100px;
  144. z-index: 999;
  145. pointer-events: none;
  146. font-weight: 400;
  147. line-height: 23px;
  148. font-size: 20px;
  149. text-shadow: 0px 1px 0px rgba(0, 0, 0, 0.5);
  150. }
  151. }
  152. </style>