index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 { isUpgradeAdapter } from "@/utils/fixVersion";
  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(async (data) => {
  73. hadGetInfo.value = true;
  74. const isVersion = isUpgradeAdapter(data.data.isUpgrade);
  75. console.log("当前-version", isVersion);
  76. store.commit("scene/setFdkkCurrentVersion", isVersion);
  77. // v3
  78. if (isVersion === "V3") {
  79. store.dispatch("audio/setLock", true);
  80. let flag =
  81. data.data.bgMusic &&
  82. data.data.bgMusic != "0" &&
  83. data.data.bgMusic != "noMusic";
  84. console.error("是否有V3--BGM", flag);
  85. store.commit("fdkk/setV3FdkkBGM", flag);
  86. store.dispatch("audio/initV3BGM", flag);
  87. if (!flag) {
  88. if (unref(isHasNormalBGM)) {
  89. console.log("不存在V3并存在普通bgm");
  90. await store.dispatch("audio/setLock", false);
  91. store.dispatch("audio/playBGM", 0);
  92. }
  93. } else {
  94. setTimeout(() => store.dispatch("audio/pauseBGM"), 100);
  95. }
  96. }
  97. });
  98. }
  99. },
  100. {
  101. deep: true,
  102. }
  103. );
  104. const updateListPosi = () => {
  105. let catalog = metadata.value.catalogs.find(
  106. (item) => item.id == currentScene.value.category
  107. );
  108. // 查询初始场景的所在1级分组
  109. metadata.value.catalogRoot.forEach((item) => {
  110. let temp = item.children && item.children.find((sub) => sub == catalog.id);
  111. if (temp) {
  112. store.commit("scene/setCurrentCatalogRoot", item);
  113. return;
  114. }
  115. });
  116. // 查询初始场景的所在2级分组
  117. store.commit("scene/setCurrentSecondary", catalog);
  118. };
  119. useApp().then((app) => {
  120. app.Tags.on("clickHotspot", (data) => {
  121. let { id } = data;
  122. let hotspot = unref(currentScene).someData.hotspots.find(
  123. (item) => item.name.toLowerCase() === id.toLowerCase()
  124. );
  125. if (hotspot) {
  126. const isNotclickType = ["tag"];
  127. if (!isNotclickType.includes(hotspot.hotspotType)) {
  128. console.log("click", hotspot);
  129. // store.commit("functions/setPauseFrom", "");
  130. // store.dispatch("audio/pauseBGM");
  131. if (hotspot.hotspotType == "phone" && unref(isMobile)) {
  132. window.open(`tel:${hotspot.phoneInfo.phone}`, "_self");
  133. return;
  134. }
  135. if (hotspot.hotspotType == "scene") {
  136. store.commit(
  137. "scene/setCurrentScene",
  138. scenesList.value.find((item) => item.id == hotspot.secne.id)
  139. );
  140. updateListPosi();
  141. } else if (hotspot.hotspotType == "link") {
  142. if (hotspot.linkOpenType == "newTab") {
  143. window.open(hotspot.hyperlink, "_blank");
  144. } else {
  145. store.commit("tags/setCurrentTag", hotspot);
  146. }
  147. } else {
  148. store.commit("tags/setCurrentTag", hotspot);
  149. if (
  150. hotspot.hotspotType == "audio" ||
  151. hotspot.hotspotType == "video"
  152. ) {
  153. store.dispatch("audio/pauseBGM");
  154. // store.commit("functions/setPauseFrom", currentPlaying.value);
  155. }
  156. }
  157. }
  158. }
  159. });
  160. });
  161. </script>
  162. <style lang="scss" scoped>
  163. #pano {
  164. width: 100%;
  165. height: 100%;
  166. }
  167. .novisible {
  168. opacity: 0;
  169. visibility: hidden;
  170. }
  171. </style>