showMobile.vue 12 KB

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