index.vue 10 KB

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