index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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, currentScene: currentScene.value }).then(async (data) => {
  137. hadGetInfo.value = true;
  138. let isVersion = 0;
  139. if (config.isOfflineMode) {
  140. if (unref(currentScene).version && unref(currentScene).version == "V4") {
  141. isVersion = isUpgradeAdapter(data.isUpgrade);
  142. } else {
  143. isVersion = isUpgradeAdapter(data && data.isUpgrade ? data.data.isUpgrade : 0);
  144. }
  145. } else {
  146. isVersion = isUpgradeAdapter(data.data && data.data.isUpgrade ? data.data.isUpgrade : 0);
  147. }
  148. console.log("当前-version", isVersion);
  149. store.dispatch("audio/setLock", true);
  150. store.commit("scene/setFdkkCurrentVersion", isVersion);
  151. // v3
  152. if (isVersion === "V3") {
  153. let flag = "";
  154. // 离线包模式,接口返回的是data,没有嵌套.data
  155. if (config.isOfflineMode) {
  156. flag = data.bgMusic && data.bgMusic != "0" && data.bgMusic != "Cheerful" && data.bgMusic != "noMusic";
  157. } else {
  158. flag = data.data.bgMusic && data.data.bgMusic != "0" && data.data.bgMusic != "Cheerful" && data.data.bgMusic != "noMusic";
  159. }
  160. console.error("是否有V3--BGM", flag);
  161. store.commit("fdkk/setV3FdkkBGM", flag);
  162. store.dispatch("audio/initV3BGM", flag);
  163. if (!flag) {
  164. if (unref(isHasNormalBGM)) {
  165. console.log("不存在V3并存在普通bgm");
  166. // store.dispatch("audio/playBGM", 0);
  167. store.dispatch("audio/pauseBGM");
  168. }
  169. } else {
  170. setTimeout(() => store.dispatch("audio/pauseBGM"), 100);
  171. }
  172. }
  173. });
  174. }
  175. },
  176. {
  177. deep: true,
  178. }
  179. );
  180. const updateListPosi = () => {
  181. let catalog = metadata.value.catalogs.find((item) => item.id == currentScene.value.category);
  182. // 查询初始场景的所在1级分组
  183. metadata.value.catalogRoot.forEach((item) => {
  184. let temp = item.children && item.children.find((sub) => sub == catalog.id);
  185. if (temp) {
  186. store.commit("scene/setCurrentCatalogRoot", item);
  187. return;
  188. }
  189. });
  190. // 查询初始场景的所在2级分组
  191. store.commit("scene/setCurrentSecondary", catalog);
  192. };
  193. useApp().then((app) => {
  194. app.Tags.on("clickHotspot", (data) => {
  195. let { id } = data;
  196. // let hotspot = unref(currentScene).someData.hotspots.find((item) => item.name.toLowerCase() === id.toLowerCase());
  197. let hotspot = hotspots.value.find((item) => item.name.toLowerCase() === id.toLowerCase());
  198. if (hotspot) {
  199. const isNotclickType = ["tag"];
  200. if (!isNotclickType.includes(hotspot.hotspotType)) {
  201. console.log("click", hotspot);
  202. // store.commit("functions/setPauseFrom", "");
  203. // store.dispatch("audio/pauseBGM");
  204. if (hotspot.hotspotType == "phone" && unref(isMobile)) {
  205. window.open(`tel:${hotspot.phoneInfo.phone}`, "_self");
  206. return;
  207. }
  208. if (hotspot.hotspotType == "scene") {
  209. store.commit(
  210. "scene/setCurrentScene",
  211. scenesList.value.find((item) => item.id == hotspot.scene.id)
  212. );
  213. // store.commit("scene/setCurrentScenesList", sceneList);
  214. updateListPosi();
  215. } else if (hotspot.hotspotType == "link") {
  216. if (hotspot.linkOpenType == "newTab") {
  217. window.open(hotspot.hyperlink, "_blank");
  218. } else {
  219. store.commit("tags/setCurrentTag", hotspot);
  220. }
  221. } else {
  222. store.commit("tags/setCurrentTag", hotspot);
  223. if (hotspot.hotspotType == "audio" || hotspot.hotspotType == "imageText" || hotspot.hotspotType == "video") {
  224. store.dispatch("audio/pauseBGM");
  225. // store.commit("functions/setPauseFrom", currentPlaying.value);
  226. }
  227. }
  228. }
  229. }
  230. });
  231. });
  232. onMounted(() => {
  233. watchEffect(() => {
  234. if (metadata.value.name === "") {
  235. document.title = t("common.no_title");
  236. }
  237. });
  238. });
  239. const handleMasksUpdate = (skyMask, earthMask, app) => {
  240. const lang = getLocale();
  241. let defaultMask = `%SWFPATH%/skin/masking_${lang}.png`;
  242. if (skyMask) {
  243. if ("isShow" in skyMask) {
  244. app.krpanoDom.set(`hotspot[peaklogo].visible`, Boolean(skyMask.isShow));
  245. }
  246. if (skyMask.icon) {
  247. app.krpanoDom.set(`hotspot[peaklogo].url`, skyMask.icon);
  248. } else {
  249. app.krpanoDom.set(`hotspot[peaklogo].url`, defaultMask);
  250. }
  251. if ("scale" in skyMask) {
  252. app.krpanoDom.set(`hotspot[peaklogo].scale`, skyMask.scale);
  253. }
  254. if ("antidistorted" in skyMask) {
  255. app.krpanoDom.set(`hotspot[peaklogo].distorted`, skyMask.antidistorted);
  256. if (!skyMask.antidistorted) {
  257. // app.krpanoDom.set(`hotspot[peaklogo].scale`, skyMask.scale * 0.9);
  258. app.krpanoDom.set(`hotspot[peaklogo].scale`, skyMask.scale * 0.5);
  259. }
  260. }
  261. }
  262. if (earthMask) {
  263. console.error("earthMask");
  264. if ("isShow" in earthMask) {
  265. app.krpanoDom.set(`hotspot[nadirlogo].visible`, Boolean(earthMask.isShow));
  266. }
  267. if (earthMask.icon) {
  268. app.krpanoDom.set(`hotspot[nadirlogo].url`, earthMask.icon);
  269. } else {
  270. app.krpanoDom.set(`hotspot[nadirlogo].url`, defaultMask);
  271. }
  272. if ("scale" in earthMask) {
  273. app.krpanoDom.set(`hotspot[nadirlogo].scale`, earthMask.scale);
  274. }
  275. if ("antidistorted" in earthMask) {
  276. app.krpanoDom.set(`hotspot[nadirlogo].distorted`, earthMask.antidistorted);
  277. if (!earthMask.antidistorted) {
  278. // app.krpanoDom.set(`hotspot[nadirlogo].scale`, earthMask.scale * 0.9);
  279. app.krpanoDom.set(`hotspot[nadirlogo].scale`, earthMask.scale * 0.5);
  280. }
  281. }
  282. }
  283. };
  284. const handlePanoClick = () => {
  285. store.commit("functions/setShowScenesList", false);
  286. };
  287. </script>
  288. <style lang="scss" scoped>
  289. #pano {
  290. width: 100%;
  291. height: 100%;
  292. }
  293. .novisible {
  294. opacity: 0;
  295. visibility: hidden;
  296. }
  297. </style>