show.vue 9.1 KB

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