showMobile.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <LoadingLogo v-if="workEnable" />
  3. <template v-if="workEnable">
  4. <Opening
  5. :coverData="coverInfo"
  6. v-if="coverInfo.isShowCover && !hasPasswordLock"
  7. />
  8. <Password @pass="handlePass" />
  9. <Share />
  10. <div class="ui-view-layout" :class="{ show: show }">
  11. <Pano />
  12. <Tags />
  13. <UiGather />
  14. <TitieSlide />
  15. </div>
  16. </template>
  17. <Error v-else />
  18. </template>
  19. <script setup>
  20. import Pano from "@/components/Pano";
  21. import Tags from "@/components/assembly/MobileTags";
  22. import Password from "@/components/assembly/Password";
  23. import Share from "@/components/assembly/Share";
  24. import Error from "@/components/assembly/Error";
  25. import UiGather from "@/components/UIGather/mobile";
  26. import TitieSlide from "@/components/assembly/titieSlide";
  27. import Opening from "@/components/assembly/OpeningMobile";
  28. import LoadingLogo from "@/components/assembly/Loading";
  29. import { createApp } from "@/app";
  30. import { ref, onMounted, computed, unref, watch, nextTick } from "vue";
  31. import { getPanoInfo, checkWork } from "@/apis";
  32. import { useStore } from "vuex";
  33. import config from "@/utils/config";
  34. import browser from "@/utils/browser";
  35. import { useApp } from "@/app";
  36. import { useWxShared } from "@/hooks/useWxshared";
  37. import { useI18n, getLocale } from "@/i18n";
  38. const { t } = useI18n({ useScope: "global" });
  39. const { initWxShare } = useWxShared();
  40. initWxShare();
  41. const coverInfo = ref({});
  42. const fixOpening = {
  43. opa1: 1,
  44. opa2: 2,
  45. opa3: 3,
  46. opa4: 4,
  47. opa5: 5,
  48. };
  49. const store = useStore();
  50. const show = ref(false);
  51. const workEnable = ref(true);
  52. const lang = getLocale();
  53. const hasPasswordLock = ref(false);
  54. const currentScene = computed(() => store.getters["scene/currentScene"]);
  55. const currentCatalogRoot = computed(
  56. () => store.getters["scene/currentCatalogRoot"]
  57. );
  58. const isAutoRotate = computed(() => store.getters["functions/isAutoRotate"]);
  59. const earthMask = computed(() => store.getters["scene/earthMask"]);
  60. const skyMask = computed(() => store.getters["scene/skyMask"]);
  61. const isShowOpeningAnimation = ref(0);
  62. onMounted(async () => {
  63. if (!browser.isMobile()) {
  64. window.location.href = window.location.href.replace(
  65. "showMobile.html",
  66. "show.html"
  67. );
  68. return;
  69. }
  70. let res = await checkWork();
  71. if (!res.data) {
  72. workEnable.value = res.data;
  73. return;
  74. }
  75. getPanoInfo().then(async (data) => {
  76. isShowOpeningAnimation.value = data.isShowOpeningAnimation
  77. ? Number(data.isShowOpeningAnimation)
  78. : 0;
  79. //TODO 兼容1.2.0或以下数据
  80. if (
  81. !("isShowOpeningAnimation" in data) &&
  82. "openingAnimationType" in data &&
  83. data.openingAnimationType.length > 0
  84. ) {
  85. console.log("小行星没有开关,但有openingAnimationType强制开启");
  86. isShowOpeningAnimation.value = 1;
  87. }
  88. store.commit("scene/setScenes", data.scenes);
  89. store.commit(
  90. "scene/setPassword",
  91. data.password === "" ? false : data.password
  92. );
  93. if (data.password.length > 0) {
  94. hasPasswordLock.value = true;
  95. }
  96. store.commit("scene/setMetaData", data);
  97. document.title = data.name || t("common.no_title");
  98. let firstScene = "";
  99. if (config.sceneNum) {
  100. console.log(config.sceneNum);
  101. firstScene = data.scenes.find(
  102. (item) => item.sceneCode == config.sceneNum
  103. );
  104. } else if (data.firstScene) {
  105. firstScene = data.scenes.find(
  106. (item) => item.sceneCode == data.firstScene.sceneCode
  107. );
  108. }
  109. store.commit("scene/setCurrentScene", firstScene || data.scenes[0]);
  110. // 过滤空分组
  111. let ttt = data.catalogRoot.filter((item) => {
  112. let flag = "";
  113. if (item.children) {
  114. item.children.some((sub) => {
  115. flag = data.scenes.some((son) => {
  116. // console.log(String(son.category).toLowerCase(), String(sub).toLowerCase());
  117. return (
  118. String(son.category).toLowerCase() == String(sub).toLowerCase()
  119. );
  120. });
  121. return flag;
  122. });
  123. }
  124. return flag;
  125. });
  126. data.catalogRoot = ttt;
  127. let catalog = data.catalogs.find(
  128. (item) => item.id == currentScene.value.category
  129. );
  130. // 查询初始场景的所在1级分组
  131. data.catalogRoot.forEach((item) => {
  132. let temp =
  133. item.children && item.children.find((sub) => sub == catalog.id);
  134. if (temp) {
  135. store.commit("scene/setCurrentCatalogRoot", item);
  136. return;
  137. }
  138. });
  139. // 查询初始场景的所在2级分组
  140. store.commit("scene/setCurrentSecondary", catalog);
  141. store.commit("functions/setAutoRotate", !!data.isAuto);
  142. show.value = true;
  143. let isHavePano = data.scenes.some((item) => item.type == "pano");
  144. document.body.setAttribute("is-mobile", true);
  145. const app = createApp({
  146. // xml: "%HTMLPATH%/static/template/tour.xml",
  147. xml: `${process.env.VUE_APP_CDN}/720yun_fd_manage/${
  148. config.projectNum
  149. }/tour.xml?rnd=${Math.random()}`,
  150. swf: "%HTMLPATH%/showviewer/lib/krpano/tour.swf",
  151. target: "pano",
  152. html5: "auto",
  153. mobilescale: 1,
  154. isHavePano,
  155. vars: {
  156. startscene: "scene_" + currentScene.value.sceneCode,
  157. "view.vlookat": currentScene.value.initVisual
  158. ? currentScene.value.initVisual.vlookat
  159. : 0,
  160. "view.hlookat": currentScene.value.initVisual
  161. ? currentScene.value.initVisual.hlookat
  162. : 0,
  163. "autorotate.enabled": !!data.isAuto,
  164. "skin_settings.littleplanetintro":
  165. fixOpening[data.openingAnimationType] || 1,
  166. "skin_settings.lptswitch": unref(isShowOpeningAnimation),
  167. },
  168. passQueryParameters: true,
  169. });
  170. coverInfo.value = data.coverInfo || {};
  171. app.Scene.lock();
  172. //如果不需要开场封面就直接渲染
  173. if (!coverInfo.value?.isShowCover) {
  174. app.render();
  175. }
  176. if (isHavePano) {
  177. app.Scene.on("sceneReady", () => {
  178. if (app.krpanoDom) {
  179. let defaultMask = `%SWFPATH%/skin/masking_${lang}.png`;
  180. if (earthMask.value) {
  181. app.krpanoDom.set(`hotspot[nadirlogo].url`, defaultMask);
  182. app.krpanoDom.set(
  183. `hotspot[nadirlogo].visible`,
  184. Boolean(earthMask.value.isShow)
  185. );
  186. if (earthMask.value.icon) {
  187. app.krpanoDom.set(`hotspot[nadirlogo].url`, earthMask.value.icon);
  188. }
  189. }
  190. if (skyMask.value) {
  191. app.krpanoDom.set(`hotspot[peaklogo].url`, defaultMask);
  192. app.krpanoDom.set(
  193. `hotspot[peaklogo].visible`,
  194. Boolean(skyMask.value.isShow)
  195. );
  196. if (skyMask.value.icon) {
  197. app.krpanoDom.set(`hotspot[peaklogo].url`, skyMask.value.icon);
  198. }
  199. }
  200. app.krpanoDom.set(
  201. `layer[webvr_exitbutton].html`,
  202. t("common.exit_vr")
  203. );
  204. }
  205. let hotspots = [];
  206. if (currentScene.value.someData) {
  207. hotspots =
  208. typeof currentScene.value.someData == "string"
  209. ? JSON.parse(currentScene.value.someData).hotspots
  210. : currentScene.value.someData.hotspots;
  211. }
  212. app.Tags.initHotspot(hotspots, false);
  213. });
  214. }
  215. });
  216. });
  217. const handlePass = () => {
  218. hasPasswordLock.value = false;
  219. };
  220. </script>
  221. <style lang="scss" scoped>
  222. .ui-view-layout {
  223. position: relative;
  224. }
  225. </style>