index.vue 5.7 KB

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