index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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, watchEffect } 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. import { useI18n, getLocale } from "@/i18n";
  15. const { t } = useI18n({ useScope: "global" });
  16. const store = useStore();
  17. const isMobile = computed(() => browser.isMobile());
  18. const lang = computed(() => config.lang);
  19. const hotspots = computed(() => store.getters["tags/hotspots"]);
  20. const currentScene = computed(() => store.getters["scene/currentScene"]);
  21. const isHasNormalBGM = computed(() => store.getters["audio/isHasNormalBGM"]);
  22. const scenesList = computed(() => store.getters["scene/list"]);
  23. const metadata = computed(() => store.getters["scene/metadata"]);
  24. const currentPlaying = computed(() => store.getters["functions/currentPlaying"]);
  25. const hadGetInfo = ref(false);
  26. const loadScene = async (currentScene) => {
  27. let app = await getApp();
  28. // await new Promise((r) => setTimeout(r, 10000));
  29. console.error("loadScene", unref(currentScene).id);
  30. if (app.krpanoDom) {
  31. let { sceneCode, initVisual, someData } = currentScene;
  32. let currnetVisual = metadata.value.workVisualAngleList.forEach((item) => {
  33. item.navigationId == currentScene.id;
  34. });
  35. app.krpanoDom.call(`skin_loadscene('scene_${sceneCode}',${currnetVisual ? currnetVisual.vlookat : "0"},${currnetVisual ? currnetVisual.hlookat : "0"})`);
  36. if (hotspots.value.length) {
  37. let currentHotspots = hotspots.value.filter((item) => item.navigationId == currentScene.id);
  38. if (currentHotspots.length) {
  39. // hotspots.forEach((item, index) => {
  40. // if (item.content) {
  41. // let hotSpotType = item.hotspotType;
  42. // for (let key in hotspotTypeList.value) {
  43. // let data = hotspotTypeList.value[key];
  44. // if (key == hotSpotType && item.content[data]) {
  45. // item[data] = item.content[data];
  46. // } else if (data) {
  47. // item[data] = dataType.value[data];
  48. // }
  49. // }
  50. // let hotSpotIconType = item.hotspotIconType;
  51. // for (let key in hotspotIconTypeList.value) {
  52. // let data = hotspotIconTypeList.value[key];
  53. // if (key == hotSpotIconType && item.content[data]) {
  54. // item[data] = item.content[data];
  55. // } else if (data) {
  56. // item[data] = dataType.value[data];
  57. // }
  58. // }
  59. // }
  60. // });
  61. app.Tags.initHotspot(currentHotspots, false);
  62. }
  63. }
  64. // const { vlookat, hlookat, vlookatmax, vlookatmin } =
  65. // currentScene.initVisual;
  66. app.krpanoDom.set(`view.limitview`, "lookat");
  67. app.krpanoDom.set(`view.vlookat`, currnetVisual ? currnetVisual.vlookat : 0);
  68. app.krpanoDom.set(`view.hlookat`, currnetVisual ? currnetVisual.hlookat : 0);
  69. app.krpanoDom.set(`view.vlookatmin`, currnetVisual ? currnetVisual.vlookatmin : -90);
  70. app.krpanoDom.set(`view.vlookatmax`, currnetVisual ? currnetVisual.vlookatmax : 90);
  71. // console.log("customMasks", currentScene.customMask);
  72. // const { earth, sky } = currentScene.customMask;
  73. let customMask = metadata.value.workCustomMaskList.find((item) => item.navigationId == currentScene.id);
  74. if (!customMask) {
  75. customMask = {
  76. data: {
  77. earth: {
  78. antidistorted: true,
  79. fodderId: null,
  80. icon: "",
  81. isShow: false,
  82. navigationId: currentScene.id,
  83. scale: 1,
  84. type: "earth",
  85. },
  86. sky: {
  87. antidistorted: true,
  88. fodderId: null,
  89. icon: "",
  90. isShow: true,
  91. navigationId: currentScene.id,
  92. scale: 1,
  93. type: "sky",
  94. },
  95. },
  96. navigationId: currentScene.id,
  97. };
  98. }
  99. // const { sky, earth } = currentScene.value.customMask;
  100. const { sky, earth } = customMask.data;
  101. handleMasksUpdate(sky, earth, app);
  102. }
  103. };
  104. watch(
  105. currentScene,
  106. (newVal, oldVal) => {
  107. console.log(lang.value);
  108. const vlog = browser.getURLParam("vlog");
  109. history.replaceState(
  110. null,
  111. null,
  112. ""
  113. .concat(window.location.pathname, "?")
  114. .concat(`id=${metadata.value.workId}&vr=${newVal.sceneCode}&lang=${lang.value}`)
  115. .concat(`${vlog ? "&vlog=" + vlog : ""} `)
  116. );
  117. //默认版本是v4
  118. store.commit("scene/setFdkkCurrentVersion", "V4");
  119. hadGetInfo.value = false;
  120. //恢复默认状态
  121. // store.commit("fdkk/setV3FdkkBGM", "");
  122. // store.commit("fdkk/setV3BGMStatus", "");
  123. if (newVal.type == "pano") {
  124. //如果当前背景音乐是v4则重置
  125. // console.log(store.getters["fdkk/fdkkBGM"]);
  126. // if (store.getters["fdkk/fdkkBGM"]) {
  127. // store.commit("fdkk/setFdkkBGM", "");
  128. // }
  129. store.dispatch("audio/setLock", false);
  130. nextTick(() => {
  131. loadScene(newVal);
  132. // console.log(newVal, "newVal");
  133. });
  134. } else {
  135. getFdkkInfo({ num: newVal.sceneCode }).then(async (data) => {
  136. hadGetInfo.value = true;
  137. const isVersion = isUpgradeAdapter(data.data.isUpgrade);
  138. console.log("当前-version", isVersion);
  139. store.dispatch("audio/setLock", true);
  140. store.commit("scene/setFdkkCurrentVersion", isVersion);
  141. // v3
  142. if (isVersion === "V3") {
  143. let flag = data.data.bgMusic && data.data.bgMusic != "0" && data.data.bgMusic != "Cheerful" && data.data.bgMusic != "noMusic";
  144. console.error("是否有V3--BGM", flag);
  145. store.commit("fdkk/setV3FdkkBGM", flag);
  146. store.dispatch("audio/initV3BGM", flag);
  147. if (!flag) {
  148. if (unref(isHasNormalBGM)) {
  149. console.log("不存在V3并存在普通bgm");
  150. // store.dispatch("audio/playBGM", 0);
  151. store.dispatch("audio/pauseBGM");
  152. }
  153. } else {
  154. setTimeout(() => store.dispatch("audio/pauseBGM"), 100);
  155. }
  156. }
  157. });
  158. }
  159. },
  160. {
  161. deep: true,
  162. }
  163. );
  164. const updateListPosi = () => {
  165. let catalog = metadata.value.catalogs.find((item) => item.id == currentScene.value.category);
  166. // 查询初始场景的所在1级分组
  167. metadata.value.catalogRoot.forEach((item) => {
  168. let temp = item.children && item.children.find((sub) => sub == catalog.id);
  169. if (temp) {
  170. store.commit("scene/setCurrentCatalogRoot", item);
  171. return;
  172. }
  173. });
  174. // 查询初始场景的所在2级分组
  175. store.commit("scene/setCurrentSecondary", catalog);
  176. };
  177. useApp().then((app) => {
  178. app.Tags.on("clickHotspot", (data) => {
  179. let { id } = data;
  180. // let hotspot = unref(currentScene).someData.hotspots.find((item) => item.name.toLowerCase() === id.toLowerCase());
  181. let hotspot = hotspots.value.find((item) => item.name.toLowerCase() === id.toLowerCase());
  182. if (hotspot) {
  183. const isNotclickType = ["tag"];
  184. if (!isNotclickType.includes(hotspot.hotspotType)) {
  185. console.log("click", hotspot);
  186. // store.commit("functions/setPauseFrom", "");
  187. // store.dispatch("audio/pauseBGM");
  188. if (hotspot.hotspotType == "phone" && unref(isMobile)) {
  189. window.open(`tel:${hotspot.phoneInfo.phone}`, "_self");
  190. return;
  191. }
  192. if (hotspot.hotspotType == "scene") {
  193. store.commit(
  194. "scene/setCurrentScene",
  195. scenesList.value.find((item) => item.id == hotspot.scene.id)
  196. );
  197. updateListPosi();
  198. } else if (hotspot.hotspotType == "link") {
  199. if (hotspot.linkOpenType == "newTab") {
  200. window.open(hotspot.hyperlink, "_blank");
  201. } else {
  202. store.commit("tags/setCurrentTag", hotspot);
  203. }
  204. } else {
  205. store.commit("tags/setCurrentTag", hotspot);
  206. if (hotspot.hotspotType == "audio" || hotspot.hotspotType == "imageText" || hotspot.hotspotType == "video") {
  207. store.dispatch("audio/pauseBGM");
  208. // store.commit("functions/setPauseFrom", currentPlaying.value);
  209. }
  210. }
  211. }
  212. }
  213. });
  214. });
  215. onMounted(() => {
  216. watchEffect(() => {
  217. if (metadata.value.name === "") {
  218. document.title = t("common.no_title");
  219. }
  220. });
  221. });
  222. const handleMasksUpdate = (skyMask, earthMask, app) => {
  223. const lang = getLocale();
  224. let defaultMask = `%SWFPATH%/skin/masking_${lang}.png`;
  225. if (skyMask) {
  226. if ("isShow" in skyMask) {
  227. app.krpanoDom.set(`hotspot[peaklogo].visible`, Boolean(skyMask.isShow));
  228. }
  229. if (skyMask.icon) {
  230. app.krpanoDom.set(`hotspot[peaklogo].url`, skyMask.icon);
  231. } else {
  232. app.krpanoDom.set(`hotspot[peaklogo].url`, defaultMask);
  233. }
  234. if ("scale" in skyMask) {
  235. app.krpanoDom.set(`hotspot[peaklogo].scale`, skyMask.scale);
  236. }
  237. if ("antidistorted" in skyMask) {
  238. app.krpanoDom.set(`hotspot[peaklogo].distorted`, skyMask.antidistorted);
  239. if (!skyMask.antidistorted) {
  240. app.krpanoDom.set(`hotspot[peaklogo].scale`, skyMask.scale * 0.9);
  241. }
  242. }
  243. }
  244. if (earthMask) {
  245. if ("isShow" in earthMask) {
  246. app.krpanoDom.set(`hotspot[nadirlogo].visible`, Boolean(earthMask.isShow));
  247. }
  248. if (earthMask.icon) {
  249. app.krpanoDom.set(`hotspot[nadirlogo].url`, earthMask.icon);
  250. }
  251. if ("scale" in earthMask) {
  252. app.krpanoDom.set(`hotspot[nadirlogo].scale`, earthMask.scale);
  253. }
  254. if ("antidistorted" in earthMask) {
  255. app.krpanoDom.set(`hotspot[nadirlogo].distorted`, earthMask.antidistorted);
  256. if (!earthMask.antidistorted) {
  257. app.krpanoDom.set(`hotspot[nadirlogo].scale`, earthMask.scale * 0.9);
  258. }
  259. }
  260. }
  261. };
  262. </script>
  263. <style lang="scss" scoped>
  264. #pano {
  265. width: 100%;
  266. height: 100%;
  267. }
  268. .novisible {
  269. opacity: 0;
  270. visibility: hidden;
  271. }
  272. </style>