show.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <template>
  2. <template v-if="workEnable">
  3. <LoadingLogo />
  4. <Opening :coverData="coverInfo" v-if="coverInfo.isShowCover && !hasPasswordLock" />
  5. <Password @pass="handlePass" />
  6. <Share />
  7. <div class="ui-view-layout" :class="{ show: show }">
  8. <Pano />
  9. <Tags />
  10. <UiGather />
  11. <TitieSlide />
  12. </div>
  13. </template>
  14. <Error v-else />
  15. </template>
  16. <script setup>
  17. import { debounce } from "lodash";
  18. const _ = window.ResizeObserver;
  19. window.ResizeObserver = class ResizeObserver extends _ {
  20. constructor(callback) {
  21. callback = debounce(callback, 100);
  22. super(callback);
  23. }
  24. };
  25. import Pano from "@/components/Pano";
  26. import Tags from "@/components/assembly/Tags";
  27. import Password from "@/components/assembly/Password";
  28. import Share from "@/components/assembly/Share";
  29. import Error from "@/components/assembly/Error";
  30. import TitieSlide from "@/components/assembly/titieSlide";
  31. import UiGather from "@/components/UIGather/";
  32. import LoadingLogo from "@/components/assembly/Loading";
  33. import Opening from "@/components/assembly/Opening";
  34. import { createApp } from "@/app";
  35. import { Dialog } from "@/global_components";
  36. import { ref, onMounted, computed, watch, nextTick, unref } from "vue";
  37. import { getPanoInfo, checkWork, exchangeId, getWorkInfo } from "@/apis";
  38. import { useStore } from "vuex";
  39. import config from "@/utils/config";
  40. import browser from "@/utils/browser";
  41. import { useAudio } from "@/hooks/useAudio";
  42. import { useI18n, getLocale } from "@/i18n";
  43. const { t } = useI18n({ useScope: "global" });
  44. const store = useStore();
  45. const show = ref(false);
  46. const workEnable = ref(true);
  47. const coverInfo = ref({});
  48. const hasPasswordLock = ref(false);
  49. const lang = getLocale();
  50. const currentScene = computed(() => store.getters["scene/currentScene"]);
  51. const currentCatalogRoot = computed(() => store.getters["scene/currentCatalogRoot"]);
  52. const isAutoRotate = computed(() => store.getters["functions/isAutoRotate"]);
  53. const earthMask = computed(() => store.getters["scene/earthMask"]);
  54. const skyMask = computed(() => store.getters["scene/skyMask"]);
  55. const hotspotTypeList = computed(() => store.getters["tags/hotspotTypeList"]);
  56. const hotspotIconTypeList = computed(() => store.getters["tags/hotspotIconTypeList"]);
  57. const dataType = computed(() => store.getters["tags/dataType"]);
  58. const hotspots = computed(() => store.getters["tags/hotspots"]);
  59. const isShowOpeningAnimation = ref(0);
  60. onMounted(async () => {
  61. if (browser.isMobile()) {
  62. window.location.href = window.location.href.replace("show.html", "showMobile.html");
  63. return;
  64. }
  65. const idRes = await exchangeId({
  66. id: config.projectNum,
  67. });
  68. const { id, num, calcStatus } = idRes.data;
  69. config.projectNum = id;
  70. if (calcStatus === 0) {
  71. Dialog.alert({
  72. title: t("common.tips"),
  73. content: t("common.calcing"),
  74. okText: t("common.confirm"),
  75. });
  76. return;
  77. }
  78. let res = await checkWork();
  79. if (!res.data) {
  80. workEnable.value = res.data;
  81. return;
  82. }
  83. // getWorkInfo().then((res) => {
  84. // console.error(res);
  85. // });
  86. // getPanoInfo().then(async (data) => {
  87. getWorkInfo().then(async (res) => {
  88. let data = res.data;
  89. let { workOpeningAnimation, work, navigationTrees, workVisualAngleList, workCustomMaskList, workHotList } = data;
  90. store.commit("tags/setData", { hotspots: workHotList });
  91. isShowOpeningAnimation.value = workOpeningAnimation.isShowOpeningAnimation ? Number(workOpeningAnimation.isShowOpeningAnimation) : 0;
  92. //TODO 兼容1.2.0或以下数据
  93. if (!("isShowOpeningAnimation" in workOpeningAnimation) && "openingAnimationType" in workOpeningAnimation && workOpeningAnimation.openingAnimationType.length > 0) {
  94. console.log("小行星没有开关,但有openingAnimationType强制开启");
  95. isShowOpeningAnimation.value = 1;
  96. }
  97. let scenes = [];
  98. navigationTrees.forEach((item) => {
  99. item.children.forEach((s_item) => {
  100. if (s_item.type != "group") {
  101. scenes.push(s_item);
  102. }
  103. s_item.children.forEach((t_item) => {
  104. if (t_item.type != "group") {
  105. scenes.push(t_item);
  106. }
  107. });
  108. });
  109. });
  110. store.commit("scene/setScenes", scenes);
  111. store.commit("scene/setPassword", work.password === "" ? false : work.password);
  112. if (work.password.length > 0) {
  113. hasPasswordLock.value = true;
  114. }
  115. store.commit("scene/setMetaData", data);
  116. // document.title = data.name || t("common.no_title");
  117. let firstScene = "";
  118. if (config.sceneNum) {
  119. firstScene = scenes.find((item) => item.sceneCode == config.sceneNum);
  120. } else if (data.firstScene) {
  121. firstScene = scenes.find((item) => item.sceneCode == data.firstScene.sceneCode);
  122. }
  123. // 所有audio入口
  124. const currentSceneData = firstScene || scenes[0];
  125. store.dispatch("audio/initNormalBGM", data.workBackgroundMusic ? data.workBackgroundMusic.ossPath : "");
  126. store.commit("scene/setCurrentScene", currentSceneData);
  127. console.error(currentSceneData);
  128. let activeScene = null;
  129. navigationTrees.forEach((item, index) => {
  130. activeScene = item.children.find((pano) => pano.id == currentSceneData.id);
  131. if (activeScene) {
  132. store.commit("scene/setCurrentScenesList", item.children);
  133. store.commit("scene/setData", { currentSecondId: null, currentRootId: item.id });
  134. // throw new Error("LoopTerminated");
  135. }
  136. item = item.children.forEach((s_item, s_index) => {
  137. activeScene = s_item.children.find((pano) => pano.id == currentSceneData.id);
  138. if (activeScene) {
  139. store.commit("scene/setCurrentScenesList", s_item.children);
  140. store.commit("scene/setData", { currentSecondId: s_item.id, currentRootId: item.id });
  141. // throw new Error("LoopTerminated");
  142. }
  143. s_item = s_item.children.forEach((t_item, t_index) => {
  144. activeScene = t_item.children.find((pano) => pano.id == currentSceneData.id);
  145. if (activeScene) {
  146. store.commit("scene/setCurrentScenesList", s_item.children);
  147. store.commit("scene/setData", { currentSecondId: s_item.id, currentRootId: item.id });
  148. // throw new Error("LoopTerminated");
  149. }
  150. });
  151. });
  152. });
  153. // 过滤空分组
  154. // let ttt = data.catalogRoot.filter((item) => {
  155. // let flag = "";
  156. // if (item.children) {
  157. // item.children.some((sub) => {
  158. // flag = data.scenes.some((son) => {
  159. // // console.log(String(son.category).toLowerCase(), String(sub).toLowerCase());
  160. // return String(son.category).toLowerCase() == String(sub).toLowerCase();
  161. // });
  162. // return flag;
  163. // });
  164. // }
  165. // return flag;
  166. // });
  167. // data.catalogRoot = ttt;
  168. // let catalog = data.catalogs.find((item) => item.id == currentScene.value.category);
  169. // // 查询初始场景的所在1级分组
  170. // data.catalogRoot.forEach((item) => {
  171. // let temp = item.children && item.children.find((sub) => sub == catalog.id);
  172. // if (temp) {
  173. // store.commit("scene/setCurrentCatalogRoot", item);
  174. // return;
  175. // }
  176. // });
  177. // // 查询初始场景的所在2级分组
  178. // store.commit("scene/setCurrentSecondary", catalog);
  179. store.commit("functions/setAutoRotate", !!work.isAuto);
  180. show.value = true;
  181. let isHavePano = scenes.some((item) => item.type == "pano");
  182. let currnetVisual = workVisualAngleList.find((item) => item.navigationId == currentScene.value.id);
  183. // if (!currnetVisual) {
  184. // currnetVisual = {
  185. // hlookat: 0,
  186. // icon: currentScene.value.icon,
  187. // vlookat: 0,
  188. // vlookatmax: 90,
  189. // vlookatmin: -90,
  190. // navigationId: currentScene.value.id,
  191. // };
  192. // }
  193. // store.commit("scene/setCurrnetVisual", currnetVisual);
  194. const app = createApp({
  195. // xml: "%HTMLPATH%/static/template/tour.xml",
  196. xml: `${process.env.VUE_APP_CDN}/720yun_fd_manage/${config.projectNum}/tour.xml?rnd=${Math.random()}`,
  197. swf: "%HTMLPATH%/showviewer/lib/krpano/tour.swf",
  198. target: "pano",
  199. html5: "auto",
  200. mobilescale: 1,
  201. isHavePano,
  202. vars: {
  203. startscene: "scene_" + currentScene.value.sceneCode,
  204. "view.org_vlookat": currnetVisual ? currnetVisual.vlookat : 0,
  205. "view.org_hlookat": currnetVisual ? currnetVisual.hlookat : 0,
  206. "view.vlookat": currnetVisual ? currnetVisual.vlookat : 0,
  207. "view.hlookat": currnetVisual ? currnetVisual.hlookat : 0,
  208. "autorotate.enabled": !!work.isAuto,
  209. "skin_settings.littleplanetintro": typeof workOpeningAnimation.openingAnimationType === "number" ? workOpeningAnimation.openingAnimationType : 1,
  210. "skin_settings.lptswitch": unref(isShowOpeningAnimation),
  211. },
  212. passQueryParameters: true,
  213. });
  214. if (app) {
  215. coverInfo.value = data.workCoverType || {};
  216. app.Scene.lock();
  217. //如果不需要开场封面就直接渲染
  218. if (!coverInfo.value?.isShowCover) {
  219. app.render();
  220. }
  221. if (isHavePano) {
  222. console.error("isHavePano", hotspots.value);
  223. app.Scene.on("sceneReady", () => {
  224. if (app.krpanoDom) {
  225. let customMask = workCustomMaskList.find((item) => item.navigationId == currentScene.value.id);
  226. // const { sky, earth } = currentScene.value.customMask;
  227. const { sky, earth } = customMask.data;
  228. handleMasksUpdate(sky, earth, app);
  229. app.krpanoDom.set(`layer[webvr_exitbutton].html`, t("common.exit_vr"));
  230. }
  231. // let hotspots = [];
  232. // if (currentScene.value.someData) {
  233. // hotspots = typeof currentScene.value.someData == "string" ? JSON.parse(currentScene.value.someData).hotspots : currentScene.value.someData.hotspots;
  234. // }
  235. console.error("sceneReady", hotspots.value);
  236. let currentHotspots = hotspots.value.filter((item) => item.navigationId == currentScene.value.id);
  237. if (currentHotspots.length) {
  238. // hotspots.forEach((item, index) => {
  239. // if (item.content) {
  240. // let hotSpotType = item.hotspotType;
  241. // for (let key in hotspotTypeList.value) {
  242. // let data = hotspotTypeList.value[key];
  243. // if (key == hotSpotType && item.content[data]) {
  244. // item[data] = item.content[data];
  245. // } else if (data) {
  246. // item[data] = dataType.value[data];
  247. // }
  248. // }
  249. // let hotSpotIconType = item.hotspotIconType;
  250. // for (let key in hotspotIconTypeList.value) {
  251. // let data = hotspotIconTypeList.value[key];
  252. // if (key == hotSpotIconType && item.content[data]) {
  253. // item[data] = item.content[data];
  254. // } else if (data) {
  255. // item[data] = dataType.value[data];
  256. // }
  257. // }
  258. // }
  259. // });
  260. app.Tags.initHotspot(currentHotspots, false);
  261. }
  262. // app.Tags.initHotspot(hotspots, false);
  263. handleVisualLimit(app, currentScene.value, workVisualAngleList);
  264. });
  265. }
  266. const { initDefaultAudio } = useAudio();
  267. initDefaultAudio();
  268. }
  269. });
  270. });
  271. const handlePass = () => {
  272. hasPasswordLock.value = false;
  273. };
  274. const handleVisualLimit = (app, currentScene, workVisualAngleList) => {
  275. let currnetVisual = workVisualAngleList.find((item) => item.navigationId == currentScene.id);
  276. // const { vlookatmax, vlookatmin } = currentScene.initVisual;
  277. // console.log('initVisual',currentScene.initVisual)
  278. console.error("视角", currnetVisual.vlookatmin, currnetVisual.vlookatmax);
  279. app.krpanoDom.set(`view.limitview`, "lookat");
  280. app.krpanoDom.set(`view.vlookatmin`, currnetVisual.vlookatmin || -90);
  281. app.krpanoDom.set(`view.vlookatmax`, currnetVisual.vlookatmax || 90);
  282. };
  283. const handleMasksUpdate = (skyMask, earthMask, app) => {
  284. const lang = getLocale();
  285. let defaultMask = `%SWFPATH%/skin/masking_${lang}.png`;
  286. console.log("defaultMask", defaultMask);
  287. if (skyMask) {
  288. if ("isShow" in skyMask) {
  289. app.krpanoDom.set(`hotspot[peaklogo].visible`, Boolean(skyMask.isShow));
  290. }
  291. if (skyMask.icon) {
  292. app.krpanoDom.set(`hotspot[peaklogo].url`, skyMask.icon);
  293. } else {
  294. app.krpanoDom.set(`hotspot[peaklogo].url`, defaultMask);
  295. }
  296. if ("scale" in skyMask) {
  297. app.krpanoDom.set(`hotspot[peaklogo].scale`, skyMask.scale);
  298. }
  299. if ("antidistorted" in skyMask) {
  300. app.krpanoDom.set(`hotspot[peaklogo].distorted`, skyMask.antidistorted);
  301. if (!skyMask.antidistorted) {
  302. app.krpanoDom.set(`hotspot[peaklogo].scale`, skyMask.scale * 0.5);
  303. }
  304. }
  305. }
  306. if (earthMask) {
  307. if ("isShow" in earthMask) {
  308. app.krpanoDom.set(`hotspot[nadirlogo].visible`, Boolean(earthMask.isShow));
  309. }
  310. if (earthMask.icon) {
  311. app.krpanoDom.set(`hotspot[nadirlogo].url`, earthMask.icon);
  312. }
  313. if ("scale" in earthMask) {
  314. app.krpanoDom.set(`hotspot[nadirlogo].scale`, earthMask.scale);
  315. }
  316. if ("antidistorted" in earthMask) {
  317. app.krpanoDom.set(`hotspot[nadirlogo].distorted`, earthMask.antidistorted);
  318. if (!earthMask.antidistorted) {
  319. app.krpanoDom.set(`hotspot[nadirlogo].scale`, earthMask.scale * 0.5);
  320. }
  321. }
  322. }
  323. };
  324. </script>
  325. <style lang="scss" scoped>
  326. .ui-view-layout {
  327. position: relative;
  328. z-index: 0;
  329. }
  330. </style>