index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 != "Cheerful" &&
  95. data.data.bgMusic != "noMusic";
  96. console.error("是否有V3--BGM", flag);
  97. store.commit("fdkk/setV3FdkkBGM", flag);
  98. store.dispatch("audio/initV3BGM", flag);
  99. if (!flag) {
  100. if (unref(isHasNormalBGM)) {
  101. console.log("不存在V3并存在普通bgm");
  102. // store.dispatch("audio/playBGM", 0);
  103. store.dispatch("audio/pauseBGM");
  104. }
  105. } else {
  106. setTimeout(() => store.dispatch("audio/pauseBGM"), 100);
  107. }
  108. }
  109. });
  110. }
  111. },
  112. {
  113. deep: true,
  114. }
  115. );
  116. const updateListPosi = () => {
  117. let catalog = metadata.value.catalogs.find(
  118. (item) => item.id == currentScene.value.category
  119. );
  120. // 查询初始场景的所在1级分组
  121. metadata.value.catalogRoot.forEach((item) => {
  122. let temp = item.children && item.children.find((sub) => sub == catalog.id);
  123. if (temp) {
  124. store.commit("scene/setCurrentCatalogRoot", item);
  125. return;
  126. }
  127. });
  128. // 查询初始场景的所在2级分组
  129. store.commit("scene/setCurrentSecondary", catalog);
  130. };
  131. useApp().then((app) => {
  132. app.Tags.on("clickHotspot", (data) => {
  133. let { id } = data;
  134. let hotspot = unref(currentScene).someData.hotspots.find(
  135. (item) => item.name.toLowerCase() === id.toLowerCase()
  136. );
  137. if (hotspot) {
  138. const isNotclickType = ["tag"];
  139. if (!isNotclickType.includes(hotspot.hotspotType)) {
  140. console.log("click", hotspot);
  141. // store.commit("functions/setPauseFrom", "");
  142. // store.dispatch("audio/pauseBGM");
  143. if (hotspot.hotspotType == "phone" && unref(isMobile)) {
  144. window.open(`tel:${hotspot.phoneInfo.phone}`, "_self");
  145. return;
  146. }
  147. if (hotspot.hotspotType == "scene") {
  148. store.commit(
  149. "scene/setCurrentScene",
  150. scenesList.value.find((item) => item.id == hotspot.secne.id)
  151. );
  152. updateListPosi();
  153. } else if (hotspot.hotspotType == "link") {
  154. if (hotspot.linkOpenType == "newTab") {
  155. window.open(hotspot.hyperlink, "_blank");
  156. } else {
  157. store.commit("tags/setCurrentTag", hotspot);
  158. }
  159. } else {
  160. store.commit("tags/setCurrentTag", hotspot);
  161. if (
  162. hotspot.hotspotType == "audio" ||
  163. hotspot.hotspotType == "imageText" ||
  164. hotspot.hotspotType == "video"
  165. ) {
  166. store.dispatch("audio/pauseBGM");
  167. // store.commit("functions/setPauseFrom", currentPlaying.value);
  168. }
  169. }
  170. }
  171. }
  172. });
  173. });
  174. onMounted(() => {
  175. watchEffect(() => {
  176. if (metadata.value.name === "") {
  177. document.title = t("common.no_title");
  178. }
  179. });
  180. });
  181. </script>
  182. <style lang="scss" scoped>
  183. #pano {
  184. width: 100%;
  185. height: 100%;
  186. }
  187. .novisible {
  188. opacity: 0;
  189. visibility: hidden;
  190. }
  191. </style>