show.vue 7.1 KB

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