SMG.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. <template>
  2. <Password />
  3. <LoadingLogo :thumb="true" />
  4. <Guide />
  5. <div class="ui-view-layout" :class="{ show: show }" is-mobile="true">
  6. <div class="scene" ref="scene$"></div>
  7. <template v-if="dataLoaded">
  8. <Information />
  9. <Control />
  10. <teleport v-if="refMiniMap && player.showWidgets" :to="refMiniMap">
  11. <span class="button-switch" @click.stop="toggleMap">
  12. <ui-icon type="show_map_collect"></ui-icon>
  13. </span>
  14. <p
  15. class="change"
  16. v-if="controls.showDollhouse"
  17. @click.stop="changeMode('dollhouse')"
  18. >
  19. <ui-icon type="show_3d_normal"></ui-icon>
  20. {{ $t("mode.dollhouseModel") }}
  21. </p>
  22. </teleport>
  23. <template v-if="refMiniMap">
  24. <div
  25. :class="{ disabled: flying }"
  26. v-show="mode != 'panorama'"
  27. v-if="controls.showFloorplan && controls.showDollhouse"
  28. class="tab-layer"
  29. >
  30. <div class="tabs" v-if="controls.showMap">
  31. <span
  32. :class="{ active: mode === 'floorplan' }"
  33. ref="floorplan_ref"
  34. @click="changeMode('floorplan', $event)"
  35. >
  36. <ui-icon
  37. :type="
  38. mode == 'floorplan'
  39. ? 'show_plane_selected'
  40. : 'show_plane_normal'
  41. "
  42. ></ui-icon>
  43. {{ $t("mode.floorplan") }}
  44. </span>
  45. <span
  46. :class="{ active: mode === 'dollhouse' }"
  47. ref="dollhouse_ref"
  48. @click="changeMode('dollhouse', $event)"
  49. >
  50. <ui-icon
  51. :type="
  52. mode == 'dollhouse' ? 'show_3d_selected' : 'show_3d_normal'
  53. "
  54. ></ui-icon>
  55. {{ $t("mode.dollhouse") }}
  56. </span>
  57. <div class="background" ref="background"></div>
  58. </div>
  59. </div>
  60. </template>
  61. </template>
  62. <UiTags />
  63. </div>
  64. </template>
  65. <script setup>
  66. import UiTags from "@/components/Tags";
  67. import { listenMessage } from "@/utils/messageHandler";
  68. import { Dialog } from "@/global_components";
  69. import Information from "@/components/Information";
  70. import Control from "@/components/Controls/Control.Mobile.vue";
  71. import LoadingLogo from "@/components/shared/Loading.vue";
  72. import OpenVideo from "@/components/openVideo/";
  73. import Guide from "@/components/shared/Guide.vue";
  74. import Password from "@/components/shared/Password.vue";
  75. import { createApp } from "@/app";
  76. import { ref, onMounted, computed, nextTick, watch, unref } from "vue";
  77. import { useStore } from "vuex";
  78. import browser from "@/utils/browser";
  79. import { useApp, getApp } from "@/app";
  80. import { useI18n, getLocale } from "@/i18n";
  81. import { useAppHeight } from "@/utils/globalViewHeight";
  82. const { t } = useI18n({ useScope: "global" });
  83. useAppHeight();
  84. let app = null;
  85. onMounted(async () => {
  86. if (!browser.isMobile()) {
  87. window.location.href = window.location.href.replace(
  88. "smg.html",
  89. "spg.html"
  90. );
  91. console.warn('重跳后::',window.location.href);
  92. return;
  93. }
  94. });
  95. const autoPlayMedia = (player) => {
  96. function onclick() {
  97. window.parent.postMessage(
  98. {
  99. source: "qjkankan",
  100. event: "autoPlayBgm",
  101. params: {
  102. status: true,
  103. },
  104. },
  105. "*"
  106. );
  107. $player.removeEventListener("click", onclick);
  108. $player.removeEventListener("touchstart", onclick);
  109. }
  110. const $player = document.querySelector(".player");
  111. $player.addEventListener("click", onclick);
  112. $player.addEventListener("touchstart", onclick);
  113. };
  114. listenMessage();
  115. const closetagtype = () => {
  116. store.commit("tag/setTagClickType", {
  117. type: "",
  118. data: {},
  119. });
  120. };
  121. const store = useStore();
  122. const tags = computed(() => {
  123. return store.getters["tag/tags"] || [];
  124. });
  125. const player = computed(() => store.getters["player"]);
  126. const flying = computed(() => store.getters["flying"]);
  127. const metadata = computed(() => store.getters["scene/metadata"]);
  128. const controls = computed(() => {
  129. return metadata.value.controls;
  130. });
  131. const mode = computed(() => store.getters["mode"]);
  132. const showNavigations = computed(() => store.getters["showNavigations"]);
  133. const scene$ = ref(null);
  134. const show = ref(false);
  135. const dataLoaded = ref(false);
  136. const refMiniMap = ref(null);
  137. const isCollapse = ref(false);
  138. const background = ref(null);
  139. const resize = () => {
  140. if (
  141. this.$refs.background &&
  142. (this.mode == "floorplan" || this.mode == "dollhouse")
  143. ) {
  144. this.$nextTick(() => {
  145. let $active = $(this.$el).find(".tabs .active");
  146. background.value.style.width =
  147. $active[0].getBoundingClientRect().width + "px";
  148. background.value.style.left = $active.position().left + "px";
  149. });
  150. }
  151. };
  152. watch(
  153. () => player.value.showMap,
  154. (val, old) => {
  155. if (!isCollapse.value) {
  156. let $minmap = document.querySelector("[xui_min_map]");
  157. if ($minmap) {
  158. if (val) {
  159. $minmap.classList.remove("collapse");
  160. } else {
  161. $minmap.classList.add("collapse");
  162. }
  163. }
  164. }
  165. },
  166. {
  167. deep: true,
  168. }
  169. );
  170. watch(
  171. () => player.value.showWidgets,
  172. (val, old) => {
  173. let $minmap = document.querySelector("[xui_min_map]");
  174. if ($minmap) {
  175. if (val) {
  176. $minmap.classList.remove("collapse");
  177. } else {
  178. $minmap.classList.add("collapse");
  179. }
  180. }
  181. },
  182. {
  183. deep: true,
  184. }
  185. );
  186. watch(
  187. () => mode.value,
  188. (val, old) => {
  189. console.error("mode", unref(val));
  190. let timer = setTimeout(() => {
  191. clearTimeout(timer);
  192. if (unref(val) == "floorplan") {
  193. if (floorplan_ref.value && floorplan_ref.value) {
  194. background.value.style.width =
  195. floorplan_ref.value.getBoundingClientRect().width + "px";
  196. background.value.style.left = floorplan_ref.value.offsetLeft + "px";
  197. }
  198. } else if (unref(val) == "dollhouse") {
  199. if (dollhouse_ref.value && dollhouse_ref.value) {
  200. background.value.style.width =
  201. dollhouse_ref.value.getBoundingClientRect().width + "px";
  202. background.value.style.left = dollhouse_ref.value.offsetLeft + "px";
  203. }
  204. }
  205. }, 0);
  206. },
  207. {
  208. deep: true,
  209. }
  210. );
  211. const floorplan_ref = ref(null);
  212. const dollhouse_ref = ref(null);
  213. const changeMode = (name, e) => {
  214. if (e) {
  215. if (!flying.value) {
  216. // background.value.style.width = e.srcElement.getBoundingClientRect().width + 'px'
  217. // background.value.style.left = e.srcElement.offsetLeft + 'px'
  218. store.commit("setMode", name);
  219. }
  220. } else {
  221. // let t = setTimeout(() => {
  222. // background.value.style.width = dollhouse_ref.value.getBoundingClientRect().width + 'px'
  223. // background.value.style.left = dollhouse_ref.value.offsetLeft + 'px'
  224. store.commit("setMode", name);
  225. // }, 0)
  226. }
  227. };
  228. // console.dir(document.querySelector(".tabs>span:last-of-type"));
  229. const toggleMap = () => {
  230. isCollapse.value = !isCollapse.value;
  231. let $minmap = document.querySelector("[xui_min_map]");
  232. if ($minmap) {
  233. if (!isCollapse.value) {
  234. $minmap.classList.remove("collapse");
  235. } else {
  236. $minmap.classList.add("collapse");
  237. }
  238. }
  239. };
  240. const onClickTagInfo = (el) => {
  241. el.stopPropagation();
  242. let item = tags.value.find((item) => item.sid == el.target.dataset.id);
  243. if (item.type == "commodity") {
  244. store.commit("tag/setTagClickType", {
  245. type: "goodlist",
  246. data: item,
  247. });
  248. }
  249. };
  250. onMounted(() => {
  251. window.changeMode = changeMode;
  252. const app = createApp({
  253. num: browser.getURLParam("m"),
  254. dom: scene$.value,
  255. mobile: true,
  256. });
  257. app.Scene.lock();
  258. app.use("MinMap", { theme: { camera_fillStyle: "#0076f6" } });
  259. app.use("Tag");
  260. app.use("TourPlayer");
  261. app.Scene.on("ready", () => {
  262. show.value = true;
  263. });
  264. app.Scene.on("error", (data) => {
  265. switch (data.code) {
  266. case 5033:
  267. window.location.replace(
  268. `/5033.html?m=${browser.getURLParam("m")}&lang=${browser.getURLParam(
  269. "lang"
  270. )}`
  271. );
  272. break;
  273. case 5034:
  274. window.location.replace( `/5034.html?m=${browser.getURLParam("m")}&lang=${browser.getURLParam(
  275. "lang"
  276. )}`);
  277. break;
  278. case 5009:
  279. window.location.replace( `/5034.html?m=${browser.getURLParam("m")}&lang=${browser.getURLParam(
  280. "lang"
  281. )}`);
  282. break;
  283. case 5005:
  284. // Dialog.toast({
  285. // content: t('guide.no_scene'),
  286. // type: 'error',
  287. // })
  288. window.location.replace( `/5033.html?m=${browser.getURLParam("m")}&lang=${browser.getURLParam(
  289. "lang"
  290. )}`);
  291. break;
  292. }
  293. });
  294. app.Scene.on("loaded", (pano) => {
  295. refMiniMap.value = "[xui_min_map]";
  296. let music = store.getters["scene/musicURL"];
  297. window.parent.postMessage(
  298. {
  299. source: "qjkankan",
  300. event: "fdkkBgmLink",
  301. params: {
  302. music,
  303. },
  304. },
  305. "*"
  306. );
  307. autoPlayMedia();
  308. });
  309. app.Scene.on("panorama.videorenderer.resumerender", () => {
  310. window.parent.postMessage(
  311. {
  312. source: "qjkankan",
  313. event: "togglefdkkBGM",
  314. params: {
  315. play: false,
  316. },
  317. },
  318. "*"
  319. );
  320. window.parent.postMessage(
  321. {
  322. source: "qjkankan",
  323. event: "toggleBgmStatus",
  324. params: {
  325. status: false,
  326. },
  327. },
  328. "*"
  329. );
  330. });
  331. app.Scene.on("panorama.videorenderer.suspendrender", async () => {
  332. let player = await getApp().TourManager.player;
  333. if (!player.isPlaying) {
  334. window.parent.postMessage(
  335. {
  336. source: "qjkankan",
  337. event: "togglefdkkBGM",
  338. params: {
  339. play: true,
  340. },
  341. },
  342. "*"
  343. );
  344. window.parent.postMessage(
  345. {
  346. source: "qjkankan",
  347. event: "toggleBgmStatus",
  348. params: {
  349. status: true,
  350. },
  351. },
  352. "*"
  353. );
  354. }
  355. });
  356. app.store.on("metadata", (metadata) => {
  357. let div = document.createElement("div");
  358. div.innerHTML = metadata.description;
  359. store.commit("scene/load", metadata);
  360. if (!metadata.controls.showMap) {
  361. app.MinMap.hide(true);
  362. }
  363. dataLoaded.value = true;
  364. });
  365. app.store.on("tags", (tags) => {
  366. store.commit("tag/load", tags);
  367. });
  368. app.Camera.on("mode.beforeChange", ({ fromMode, toMode, floorIndex }) => {
  369. if (fromMode) {
  370. store.commit("setFlying", true);
  371. }
  372. });
  373. app.Camera.on("mode.afterChange", ({ toMode, floorIndex }) => {
  374. store.commit("setFlying", false);
  375. });
  376. app.Camera.on("flying.started", (pano) => {
  377. store.commit("setFlying", true);
  378. });
  379. app.Camera.on("flying.ended", ({ targetPano }) => {
  380. store.commit("setFlying", false);
  381. store.commit("setPanoId", targetPano.id);
  382. });
  383. app.TourManager.on("loaded", async (tour) => {
  384. let tours = JSON.parse(
  385. JSON.stringify(app.TourManager.tours, (key, val) => {
  386. if (key === "audio") {
  387. return null;
  388. } else {
  389. return val;
  390. }
  391. })
  392. );
  393. store.commit("tour/setData", {
  394. tours: tours,
  395. });
  396. window.parent.postMessage(
  397. {
  398. source: "qjkankan",
  399. event: "toursList",
  400. params: {
  401. tours,
  402. },
  403. },
  404. "*"
  405. );
  406. store.commit("tour/setBackUp", {
  407. tours: JSON.parse(
  408. JSON.stringify(app.TourManager.tours, (key, val) => {
  409. if (key === "audio") {
  410. return null;
  411. } else {
  412. return val;
  413. }
  414. })
  415. ),
  416. });
  417. });
  418. app.store.on("floorcad", (floor) =>
  419. store.commit("scene/loadFloorData", floor)
  420. );
  421. app.store.on("flooruser", (floor) =>
  422. store.commit("scene/loadFloorData", floor)
  423. ); //4.7以后新楼层方式
  424. app.render();
  425. });
  426. </script>
  427. <style lang="scss">
  428. .tab-layer {
  429. width: 100%;
  430. text-align: center;
  431. display: flex;
  432. justify-content: center;
  433. align-items: center;
  434. z-index: 10;
  435. position: fixed;
  436. left: 50%;
  437. transform: translateX(-50%);
  438. top: 2.3rem;
  439. pointer-events: none;
  440. }
  441. .tabs {
  442. pointer-events: auto;
  443. position: relative;
  444. display: flex;
  445. background: #222222;
  446. border-radius: 6px;
  447. padding: 2px;
  448. justify-content: center;
  449. align-items: center;
  450. border: 1px solid rgba(255, 255, 255, 0.1);
  451. box-shadow: inset 0px 0px 6px 0px rgba(0, 0, 0, 0.5);
  452. .background {
  453. position: absolute;
  454. left: 2px;
  455. top: 2px;
  456. bottom: 2px;
  457. width: 50%;
  458. border-radius: 4px;
  459. background: #444444;
  460. box-shadow: 2px 0px 4px 0px rgba(0, 0, 0, 0.3);
  461. z-index: 0;
  462. transition: left 0.3s;
  463. }
  464. span {
  465. flex: 1;
  466. color: #fff;
  467. opacity: 0.5;
  468. border-radius: 6px;
  469. height: 0.94737rem;
  470. font-size: 0.36842rem;
  471. transition: all 0.3s ease;
  472. display: flex;
  473. align-items: center;
  474. justify-content: center;
  475. padding-left: 10px;
  476. padding-right: 10px;
  477. white-space: nowrap;
  478. z-index: 1;
  479. i {
  480. font-size: 0.47368rem;
  481. margin-right: 4px;
  482. pointer-events: none;
  483. }
  484. }
  485. span.active {
  486. opacity: 1;
  487. }
  488. }
  489. [xui_tags_view] {
  490. .tag-body {
  491. /* display: none; */
  492. position: absolute;
  493. left: 50%;
  494. bottom: 50px;
  495. transform: translateX(-50%) scale(0);
  496. transform-origin: bottom;
  497. transition: all 0.3s cubic-bezier(0.35, 0.32, 0.65, 0.63);
  498. // pointer-events: none;
  499. .tag-commodity {
  500. min-width: 230px;
  501. height: 76px;
  502. background: rgba(255, 255, 255, 0.8);
  503. box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.16);
  504. border-radius: 2px;
  505. position: relative;
  506. margin-bottom: 30px;
  507. &::before {
  508. content: "";
  509. display: inline-block;
  510. left: 50%;
  511. transform: translateX(-50%);
  512. width: 2px;
  513. height: 28px;
  514. bottom: -30px;
  515. background: linear-gradient(
  516. 145deg,
  517. rgba(255, 255, 255, 0.8),
  518. rgba(255, 255, 255, 0)
  519. );
  520. position: absolute;
  521. }
  522. .tag-avatar {
  523. position: absolute;
  524. z-index: 99;
  525. width: 80px;
  526. height: 80px;
  527. background: #ffffff;
  528. box-shadow: 0px 3px 6px 0px rgb(0 0 0 / 16%);
  529. border-radius: 2px;
  530. top: -14px;
  531. left: -12px;
  532. background-size: cover;
  533. pointer-events: none;
  534. }
  535. > p {
  536. color: #131d34;
  537. font-size: 16px;
  538. pointer-events: none;
  539. }
  540. .tag-title {
  541. padding: 10px 10px 10px 76px;
  542. overflow: hidden;
  543. text-overflow: ellipsis;
  544. white-space: nowrap;
  545. width: 240px;
  546. }
  547. .tag-info {
  548. padding: 0 20px 0 76px;
  549. font-size: 12px;
  550. overflow: hidden;
  551. text-overflow: ellipsis;
  552. white-space: nowrap;
  553. }
  554. }
  555. &.show {
  556. transform: translateX(-50%) scale(1);
  557. }
  558. }
  559. .coupon {
  560. width: 64px !important;
  561. height: 64px !important;
  562. &::after {
  563. content: "發現好禮";
  564. width: 100%;
  565. color: #ed5d18;
  566. position: absolute;
  567. bottom: -24px;
  568. text-align: center;
  569. font-size: 14px;
  570. }
  571. }
  572. .waterfall {
  573. width: 70px !important;
  574. height: 70px !important;
  575. }
  576. .applet_link {
  577. width: 64px !important;
  578. height: 64px !important;
  579. border-radius: 50%;
  580. background-color: #fff;
  581. border: 1px solid #ed5d18;
  582. position: relative;
  583. overflow: hidden;
  584. &::after {
  585. content: "直播中";
  586. width: 100%;
  587. height: 20px;
  588. background: #ed5d18;
  589. position: absolute;
  590. bottom: 0;
  591. text-align: center;
  592. line-height: 1.2;
  593. font-size: 12px;
  594. border-radius: 26%;
  595. }
  596. }
  597. }
  598. @media (orientation: landscape) {
  599. .tab-layer {
  600. top: 1.2rem;
  601. .tabs {
  602. height: 0.7rem;
  603. > span {
  604. height: 0.7rem;
  605. font-size: 0.25rem;
  606. }
  607. }
  608. }
  609. }
  610. </style>