index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <div id="pano" v-show="currentScene.type != '4dkk'"></div>
  3. <Fdkk v-if="currentScene.type == '4dkk' && hadGetInfo" />
  4. </template>
  5. <script setup>
  6. import { ref, onMounted, computed, watch, nextTick, unref } from "vue";
  7. import { useStore } from "vuex";
  8. import { useApp, getApp } from "@/app";
  9. import Fdkk from "../Fdkk";
  10. import { getFdkkInfo } from "@/apis";
  11. // import { useMusicPlayer, useSoundPlayer } from "@/utils/sound";
  12. import browser from "@/utils/browser";
  13. import config from "@/utils/config";
  14. const store = useStore();
  15. const isMobile = computed(() => browser.isMobile());
  16. const lang = computed(() => config.lang);
  17. const currentScene = computed(() => store.getters["scene/currentScene"]);
  18. const isHasNormalBGM = computed(() => store.getters["audio/isHasNormalBGM"]);
  19. const scenesList = computed(() => store.getters["scene/list"]);
  20. const metadata = computed(() => store.getters["scene/metadata"]);
  21. const currentPlaying = computed(
  22. () => store.getters["functions/currentPlaying"]
  23. );
  24. const hadGetInfo = ref(false);
  25. const loadScene = async (currentScene) => {
  26. let app = await getApp();
  27. // await new Promise((r) => setTimeout(r, 10000));
  28. console.error("loadScene", unref(currentScene));
  29. if (app.krpanoDom) {
  30. let { sceneCode, initVisual, someData } = currentScene;
  31. app.krpanoDom.call(
  32. `skin_loadscene('scene_${sceneCode}',${
  33. initVisual ? initVisual.vlookat : "0"
  34. },${initVisual ? initVisual.hlookat : "0"})`
  35. );
  36. console.log(sceneCode, someData);
  37. if (someData && someData.hotspots && someData.hotspots.length > 0) {
  38. app.Tags.initHotspot(someData.hotspots, false);
  39. }
  40. }
  41. };
  42. watch(
  43. currentScene,
  44. (newVal, oldVal) => {
  45. console.log(lang.value);
  46. history.replaceState(
  47. null,
  48. null,
  49. ""
  50. .concat(window.location.pathname, "?")
  51. .concat(
  52. `id=${metadata.value.id}&vr=${newVal.sceneCode}&lang=${lang.value}`
  53. )
  54. );
  55. //默认版本是v4
  56. store.commit("scene/setFdkkCurrentVersion", "v4");
  57. hadGetInfo.value = false;
  58. //恢复默认状态
  59. store.commit("fdkk/setV3FdkkBGM", "");
  60. store.commit("fdkk/setV3BGMStatus", "");
  61. if (newVal.type == "pano") {
  62. //如果当前背景音乐是v4则重置
  63. console.log(store.getters["fdkk/fdkkBGM"]);
  64. if (store.getters["fdkk/fdkkBGM"]) {
  65. store.commit("fdkk/setFdkkBGM", "");
  66. }
  67. nextTick(() => {
  68. loadScene(newVal);
  69. console.log(newVal, "newVal");
  70. });
  71. } else {
  72. getFdkkInfo({ num: newVal.sceneCode }).then((data) => {
  73. hadGetInfo.value = true;
  74. if (data.data.isUpgrade != void 0) {
  75. store.commit(
  76. "scene/setFdkkCurrentVersion",
  77. data.data.isUpgrade !== 0 ? "v4" : "v3"
  78. );
  79. // v3
  80. if (data.data.isUpgrade === 0) {
  81. store.dispatch("audio/pauseBGM");
  82. let flag =
  83. data.data.bgMusic &&
  84. data.data.bgMusic != "0" &&
  85. data.data.bgMusic != "noMusic";
  86. store.commit("fdkk/setV3FdkkBGM", flag);
  87. if (!unref(isHasNormalBGM) && !flag) {
  88. store.dispatch("audio/pauseBGM");
  89. }
  90. }
  91. }
  92. });
  93. }
  94. },
  95. {
  96. deep: true,
  97. }
  98. );
  99. const updateListPosi = () => {
  100. let catalog = metadata.value.catalogs.find(
  101. (item) => item.id == currentScene.value.category
  102. );
  103. // 查询初始场景的所在1级分组
  104. metadata.value.catalogRoot.forEach((item) => {
  105. let temp = item.children && item.children.find((sub) => sub == catalog.id);
  106. if (temp) {
  107. store.commit("scene/setCurrentCatalogRoot", item);
  108. return;
  109. }
  110. });
  111. // 查询初始场景的所在2级分组
  112. store.commit("scene/setCurrentSecondary", catalog);
  113. };
  114. useApp().then((app) => {
  115. app.Tags.on("clickHotspot", (data) => {
  116. let { id } = data;
  117. let hotspot = unref(currentScene).someData.hotspots.find(
  118. (item) => item.name.toLowerCase() === id.toLowerCase()
  119. );
  120. if (hotspot) {
  121. const isNotclickType = ["tag"];
  122. if (!isNotclickType.includes(hotspot.hotspotType)) {
  123. console.log("click", hotspot);
  124. store.commit("functions/setPauseFrom", "");
  125. if (hotspot.hotspotType == "phone" && unref(isMobile)) {
  126. window.open(`tel:${hotspot.phoneInfo.phone}`, "_self");
  127. return;
  128. }
  129. if (hotspot.hotspotType == "scene") {
  130. store.commit(
  131. "scene/setCurrentScene",
  132. scenesList.value.find((item) => item.id == hotspot.secne.id)
  133. );
  134. updateListPosi();
  135. } else if (hotspot.hotspotType == "link") {
  136. if (hotspot.linkOpenType == "newTab") {
  137. window.open(hotspot.hyperlink, "_blank");
  138. } else {
  139. store.commit("tags/setCurrentTag", hotspot);
  140. }
  141. } else {
  142. store.commit("tags/setCurrentTag", hotspot);
  143. if (
  144. hotspot.hotspotType == "audio" ||
  145. hotspot.hotspotType == "video"
  146. ) {
  147. store.commit("functions/setPauseFrom", currentPlaying.value);
  148. }
  149. }
  150. }
  151. }
  152. });
  153. });
  154. </script>
  155. <style lang="scss" scoped>
  156. #pano {
  157. width: 100%;
  158. height: 100%;
  159. }
  160. .novisible {
  161. opacity: 0;
  162. visibility: hidden;
  163. }
  164. </style>