show.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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 { useAudio } from "@/hooks/useAudio";
  36. import { useI18n, getLocale } from "@/i18n";
  37. const { t } = useI18n({ useScope: "global" });
  38. const store = useStore();
  39. const show = ref(false);
  40. const workEnable = ref(true);
  41. const coverInfo = ref({});
  42. const hasPasswordLock = ref(false);
  43. const lang = getLocale();
  44. const currentScene = computed(() => store.getters["scene/currentScene"]);
  45. const currentCatalogRoot = computed(
  46. () => store.getters["scene/currentCatalogRoot"]
  47. );
  48. const isAutoRotate = computed(() => store.getters["functions/isAutoRotate"]);
  49. const earthMask = computed(() => store.getters["scene/earthMask"]);
  50. const skyMask = computed(() => store.getters["scene/skyMask"]);
  51. const isShowOpeningAnimation = ref(0);
  52. onMounted(async () => {
  53. if (browser.isMobile()) {
  54. window.location.href = window.location.href.replace(
  55. "show.html",
  56. "showMobile.html"
  57. );
  58. return;
  59. }
  60. let res = await checkWork();
  61. if (!res.data) {
  62. workEnable.value = res.data;
  63. return;
  64. }
  65. getPanoInfo().then(async (data) => {
  66. isShowOpeningAnimation.value = data.isShowOpeningAnimation
  67. ? Number(data.isShowOpeningAnimation)
  68. : 0;
  69. //TODO 兼容1.2.0或以下数据
  70. if (
  71. !("isShowOpeningAnimation" in data) &&
  72. "openingAnimationType" in data &&
  73. data.openingAnimationType.length > 0
  74. ) {
  75. console.log("小行星没有开关,但有openingAnimationType强制开启");
  76. isShowOpeningAnimation.value = 1;
  77. }
  78. store.commit("scene/setScenes", data.scenes);
  79. store.commit(
  80. "scene/setPassword",
  81. data.password === "" ? false : data.password
  82. );
  83. if (data.password.length > 0) {
  84. hasPasswordLock.value = true;
  85. }
  86. store.commit("scene/setMetaData", data);
  87. // document.title = data.name || t("common.no_title");
  88. let firstScene = "";
  89. if (config.sceneNum) {
  90. firstScene = data.scenes.find(
  91. (item) => item.sceneCode == config.sceneNum
  92. );
  93. } else if (data.firstScene) {
  94. firstScene = data.scenes.find(
  95. (item) => item.sceneCode == data.firstScene.sceneCode
  96. );
  97. }
  98. // 所有audio入口
  99. const currentSceneData = firstScene || data.scenes[0];
  100. store.dispatch(
  101. "audio/initNormalBGM",
  102. data.backgroundMusic ? data.backgroundMusic.ossPath : ""
  103. );
  104. store.commit("scene/setCurrentScene", currentSceneData);
  105. // 过滤空分组
  106. let ttt = data.catalogRoot.filter((item) => {
  107. let flag = "";
  108. if (item.children) {
  109. item.children.some((sub) => {
  110. flag = data.scenes.some((son) => {
  111. // console.log(String(son.category).toLowerCase(), String(sub).toLowerCase());
  112. return (
  113. String(son.category).toLowerCase() == String(sub).toLowerCase()
  114. );
  115. });
  116. return flag;
  117. });
  118. }
  119. return flag;
  120. });
  121. data.catalogRoot = ttt;
  122. let catalog = data.catalogs.find(
  123. (item) => item.id == currentScene.value.category
  124. );
  125. // 查询初始场景的所在1级分组
  126. data.catalogRoot.forEach((item) => {
  127. let temp =
  128. item.children && item.children.find((sub) => sub == catalog.id);
  129. if (temp) {
  130. store.commit("scene/setCurrentCatalogRoot", item);
  131. return;
  132. }
  133. });
  134. // 查询初始场景的所在2级分组
  135. store.commit("scene/setCurrentSecondary", catalog);
  136. store.commit("functions/setAutoRotate", !!data.isAuto);
  137. show.value = true;
  138. let isHavePano = data.scenes.some((item) => item.type == "pano");
  139. const app = createApp({
  140. // xml: "%HTMLPATH%/static/template/tour.xml",
  141. xml: `${process.env.VUE_APP_CDN}/720yun_fd_manage/${
  142. config.projectNum
  143. }/tour.xml?rnd=${Math.random()}`,
  144. swf: "%HTMLPATH%/showviewer/lib/krpano/tour.swf",
  145. target: "pano",
  146. html5: "auto",
  147. mobilescale: 1,
  148. isHavePano,
  149. vars: {
  150. startscene: "scene_" + currentScene.value.sceneCode,
  151. "view.org_vlookat": currentScene.value.initVisual
  152. ? currentScene.value.initVisual.vlookat
  153. : 0,
  154. "view.org_hlookat": currentScene.value.initVisual
  155. ? currentScene.value.initVisual.hlookat
  156. : 0,
  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. typeof data.openingAnimationType === "number"
  166. ? data.openingAnimationType
  167. : 1,
  168. "skin_settings.lptswitch": unref(isShowOpeningAnimation),
  169. },
  170. passQueryParameters: true,
  171. });
  172. if (app) {
  173. coverInfo.value = data.coverInfo || {};
  174. app.Scene.lock();
  175. //如果不需要开场封面就直接渲染
  176. if (!coverInfo.value?.isShowCover) {
  177. app.render();
  178. }
  179. if (isHavePano) {
  180. app.Scene.on("sceneReady", () => {
  181. if (app.krpanoDom) {
  182. const { sky, earth } = currentScene.value.customMask;
  183. handleMasksUpdate(sky, earth, app);
  184. app.krpanoDom.set(
  185. `layer[webvr_exitbutton].html`,
  186. t("common.exit_vr")
  187. );
  188. }
  189. let hotspots = [];
  190. if (currentScene.value.someData) {
  191. hotspots =
  192. typeof currentScene.value.someData == "string"
  193. ? JSON.parse(currentScene.value.someData).hotspots
  194. : currentScene.value.someData.hotspots;
  195. }
  196. app.Tags.initHotspot(hotspots, false);
  197. handleVisualLimit(app, currentScene.value);
  198. });
  199. }
  200. const { initDefaultAudio } = useAudio();
  201. initDefaultAudio();
  202. }
  203. });
  204. });
  205. const handlePass = () => {
  206. hasPasswordLock.value = false;
  207. };
  208. const handleVisualLimit = (app, currentScene) => {
  209. const { vlookatmax, vlookatmin } = currentScene.initVisual;
  210. // console.log('initVisual',currentScene.initVisual)
  211. app.krpanoDom.set(`view.limitview`, "lookat");
  212. app.krpanoDom.set(`view.vlookatmin`, vlookatmin);
  213. app.krpanoDom.set(`view.vlookatmax`, vlookatmax);
  214. };
  215. const handleMasksUpdate = (skyMask, earthMask, app) => {
  216. const lang = getLocale();
  217. let defaultMask = `%SWFPATH%/skin/masking_${lang}.png`;
  218. console.log("defaultMask", defaultMask);
  219. if (skyMask) {
  220. if ("isShow" in skyMask) {
  221. app.krpanoDom.set(`hotspot[peaklogo].visible`, Boolean(skyMask.isShow));
  222. }
  223. if (skyMask.icon) {
  224. app.krpanoDom.set(`hotspot[peaklogo].url`, skyMask.icon);
  225. } else {
  226. app.krpanoDom.set(`hotspot[peaklogo].url`, defaultMask);
  227. }
  228. if ("scale" in skyMask) {
  229. app.krpanoDom.set(`hotspot[peaklogo].scale`, skyMask.scale);
  230. }
  231. if ("antidistorted" in skyMask) {
  232. app.krpanoDom.set(`hotspot[peaklogo].distorted`, skyMask.antidistorted);
  233. if (!skyMask.antidistorted) {
  234. app.krpanoDom.set(`hotspot[peaklogo].scale`, skyMask.scale * 0.50);
  235. }
  236. }
  237. }
  238. if (earthMask) {
  239. if ("isShow" in earthMask) {
  240. app.krpanoDom.set(
  241. `hotspot[nadirlogo].visible`,
  242. Boolean(earthMask.isShow)
  243. );
  244. }
  245. if (earthMask.icon) {
  246. app.krpanoDom.set(`hotspot[nadirlogo].url`, earthMask.icon);
  247. }
  248. if ("scale" in earthMask) {
  249. app.krpanoDom.set(`hotspot[nadirlogo].scale`, earthMask.scale);
  250. }
  251. if ("antidistorted" in earthMask) {
  252. app.krpanoDom.set(
  253. `hotspot[nadirlogo].distorted`,
  254. earthMask.antidistorted
  255. );
  256. if (!earthMask.antidistorted) {
  257. app.krpanoDom.set(`hotspot[nadirlogo].scale`, earthMask.scale * 0.50);
  258. }
  259. }
  260. }
  261. };
  262. </script>
  263. <style lang="scss" scoped>
  264. .ui-view-layout {
  265. position: relative;
  266. z-index: 0;
  267. }
  268. </style>