index.vue 5.9 KB

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