app.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. <template>
  2. <LoadingLogo v-if="hadVideo" :thumb="true" />
  3. <OpenVideo v-else @close="hadVideo = true" />
  4. <div class="ui-view-layout" :class="{ show: show }" is-mobile="true">
  5. <div class="scene" ref="scene$"></div>
  6. <template v-if="dataLoaded">
  7. <Information />
  8. <Control />
  9. <teleport v-if="refMiniMap && player.showWidgets" :to="refMiniMap">
  10. <span class="button-switch" @click.stop="toggleMap">
  11. <ui-icon type="show_map_collect"></ui-icon>
  12. </span>
  13. <p class="change" @click="changeMode('dollhouse', $event, 'focus3d')">
  14. <ui-icon type="show_3d_normal"></ui-icon>
  15. 3D模型
  16. </p>
  17. </teleport>
  18. <template v-if="refMiniMap && player.showWidgets">
  19. <div :class="{ disabled: flying }" v-show="mode != 'panorama'" v-if="controls.showFloorplan && controls.showDollhouse" class="tab-layer">
  20. <div class="tabs" v-if="controls.showMap">
  21. <span :class="{ active: mode === 'floorplan' }" @click="changeMode('floorplan', $event)">
  22. <ui-icon :type="mode == 'floorplan' ? 'show_plane_selected' : 'show_plane_normal'"></ui-icon>
  23. 二維
  24. </span>
  25. <span :class="{ active: mode === 'dollhouse' }" @click="changeMode('dollhouse', $event)">
  26. <ui-icon :type="mode == 'dollhouse' ? 'show_3d_selected' : 'show_3d_normal'"></ui-icon>
  27. 三維
  28. </span>
  29. <div class="background" ref="background"></div>
  30. </div>
  31. </div>
  32. </template>
  33. </template>
  34. <!-- <UiTags /> -->
  35. </div>
  36. <GoodsList @close="closetagtype" />
  37. <Treasure @close="closetagtype" />
  38. <Waterfall @close="closetagtype" />
  39. </template>
  40. <script setup>
  41. import { useMusicPlayer } from "@/utils/sound";
  42. // import UiTags from "@/components/Tags";
  43. import GoodsList from "@/components/Tags/goods-list.vue";
  44. import Treasure from "@/components/Tags/treasure.vue";
  45. import Waterfall from "@/components/Tags/waterfall.vue";
  46. import Information from "@/components/Information";
  47. import Control from "@/components/Controls/Control.Mobile.vue";
  48. import LoadingLogo from "@/components/shared/Loading.vue";
  49. import OpenVideo from "@/components/openVideo/";
  50. import { createApp } from "@/app";
  51. import { ref, onMounted, computed, nextTick, watch } from "vue";
  52. import { useStore } from "vuex";
  53. import browser from "@/utils/browser";
  54. import { useApp, getApp } from "@/app";
  55. import common from "@/utils/common";
  56. import * as apis from "@/apis/index.js";
  57. const musicPlayer = useMusicPlayer();
  58. let app = null;
  59. const closetagtype = () => {
  60. store.commit("tag/setTagClickType", {
  61. type: "",
  62. data: {},
  63. });
  64. };
  65. const store = useStore();
  66. const tags = computed(() => {
  67. return store.getters["tag/tags"] || [];
  68. });
  69. const player = computed(() => store.getters["player"]);
  70. const flying = computed(() => store.getters["flying"]);
  71. const metadata = computed(() => store.getters["scene/metadata"]);
  72. const controls = computed(() => {
  73. return metadata.value.controls;
  74. });
  75. const mode = computed(() => store.getters["mode"]);
  76. const showNavigations = computed(() => store.getters["showNavigations"]);
  77. const scene$ = ref(null);
  78. const hadVideo = ref(!!browser.getURLParam("novideo"));
  79. const show = ref(false);
  80. const dataLoaded = ref(false);
  81. const refMiniMap = ref(null);
  82. const isCollapse = ref(false);
  83. const background = ref(null);
  84. const resize = () => {
  85. if (this.$refs.background && (this.mode == "floorplan" || this.mode == "dollhouse")) {
  86. this.$nextTick(() => {
  87. let $active = $(this.$el).find(".tabs .active");
  88. background.value.style.width = $active[0].getBoundingClientRect().width + "px";
  89. background.value.style.left = $active.position().left + "px";
  90. });
  91. }
  92. };
  93. // watch(
  94. // () => hadVideo.value,
  95. // (val, old) => {
  96. // if (val) {
  97. // app.Scene.unlock();
  98. // }
  99. // }
  100. // );
  101. watch(
  102. () => player.value.showMap,
  103. (val, old) => {
  104. if (!isCollapse.value) {
  105. let $minmap = document.querySelector("[xui_min_map]");
  106. if ($minmap) {
  107. if (val) {
  108. $minmap.classList.remove("collapse");
  109. } else {
  110. $minmap.classList.add("collapse");
  111. }
  112. }
  113. }
  114. },
  115. {
  116. deep: true,
  117. }
  118. );
  119. watch(
  120. () => player.value.showWidgets,
  121. (val, old) => {
  122. let $minmap = document.querySelector("[xui_min_map]");
  123. if ($minmap) {
  124. if (val) {
  125. $minmap.classList.remove("collapse");
  126. } else {
  127. $minmap.classList.add("collapse");
  128. }
  129. }
  130. },
  131. {
  132. deep: true,
  133. }
  134. );
  135. const changeMode = (name, e, focus3d = false) => {
  136. if (!flying.value) {
  137. let width, left;
  138. store.commit("setMode", name);
  139. nextTick(() => {
  140. if (focus3d) {
  141. let $active = document.querySelector(".tabs>span:last-of-type");
  142. background.value.style.width = $active.getBoundingClientRect().width + "px";
  143. background.value.style.left = $active.offsetLeft + "px";
  144. } else {
  145. background.value.style.width = width || e.srcElement.getBoundingClientRect().width + "px";
  146. background.value.style.left = left || e.srcElement.offsetLeft + "px";
  147. }
  148. });
  149. }
  150. // console.dir(document.querySelector(".tabs>span:last-of-type"));
  151. };
  152. const toggleMap = () => {
  153. isCollapse.value = !isCollapse.value;
  154. let $minmap = document.querySelector("[xui_min_map]");
  155. if ($minmap) {
  156. if (!isCollapse.value) {
  157. $minmap.classList.remove("collapse");
  158. } else {
  159. $minmap.classList.add("collapse");
  160. }
  161. }
  162. };
  163. const onClickTagInfo = (el) => {
  164. el.stopPropagation();
  165. let item = tags.value.find((item) => item.sid == el.target.dataset.id);
  166. if (item.type == "commodity") {
  167. store.commit("tag/setTagClickType", {
  168. type: "goodlist",
  169. data: item,
  170. });
  171. } else if (item.type == "waterfall") {
  172. store.commit("tag/setTagClickType", {
  173. type: "waterfall",
  174. data: item,
  175. });
  176. }
  177. };
  178. onMounted(async () => {
  179. apis.burying_point({type:0});
  180. app = createApp({
  181. num: browser.getURLParam("m"),
  182. dom: scene$.value,
  183. mobile: true,
  184. isLoadTags: false,
  185. });
  186. app.use("MinMap", { theme: { camera_fillStyle: "#ED5D18" } });
  187. app.use("Tag");
  188. app
  189. .use("TagView", {
  190. render(data) {
  191. if (data.type == "waterfall") {
  192. let arr = data.products.map((item) => item.price);
  193. let priceMin = Math.min.apply(null, arr)
  194. let priceMax = Math.max.apply(null, arr)
  195. let price = priceMin==priceMax ? priceMax : `${priceMin}-${priceMax}`
  196. let range = `${data.products[0].symbol} ${price}`;
  197. return `<span class="tag-icon animate" style="background-image:url({{icon}})"></span>
  198. <div class="tag-body">
  199. <div data-id="${data.sid}" class="tag-commodity">
  200. <div style="background-image:url(${data.products[0].pic})" class='tag-avatar'>
  201. </div>
  202. <p class="tag-title">${data.title}</p>
  203. <p class="tag-info">${range} | 查看 ></p>
  204. </div>
  205. </div>
  206. `;
  207. } else if (data.type == "coupon") {
  208. return `<span class="tag-icon coupon animate" style="background-image:url({{icon}})"></span>`;
  209. } else if (data.type == "applet_link") {
  210. try {
  211. data.hotContent = JSON.parse(data.hotContent);
  212. } catch (error) {}
  213. return `<span class="tag-icon applet_link animate" style="background-image:url(${
  214. data.hotContent.liveIcon.src ? common.changeUrl(data.hotContent.liveIcon.src) : "{{icon}}"
  215. })"></span>`;
  216. } else if (data.type == "link_scene") {
  217. return `<span class="tag-icon animate" style="background-image:url({{icon}})"></span>`;
  218. } else if (data.type == "commodity") {
  219. let arr = data.products.map((item) => item.price);
  220. let priceMin = Math.min.apply(null, arr)
  221. let priceMax = Math.max.apply(null, arr)
  222. let price = priceMin==priceMax ? priceMax : `${priceMin}-${priceMax}`
  223. let range = `${data.products[0].symbol} ${price}`;
  224. return `<span class="tag-icon animate" style="background-image:url({{icon}})"></span>
  225. <div class="tag-body">
  226. <div data-id="${data.sid}" class="tag-commodity">
  227. <div style="background-image:url(${data.products[0].pic})" class='tag-avatar'>
  228. </div>
  229. <p class="tag-title">${data.title}</p>
  230. <p class="tag-info">${range} | 查看 ></p>
  231. </div>
  232. </div>
  233. `;
  234. } else {
  235. return `<span class="tag-icon animate" style="background-image:url({{icon}})"></span>`;
  236. }
  237. },
  238. })
  239. .then((view) => {
  240. view.on("click", (e) => {
  241. var tag = e.data;
  242. // 聚焦當前點擊的熱點
  243. view.focus(tag.sid).then(() => {
  244. if (tag.type == "coupon") {
  245. store.commit("tag/setTagClickType", {
  246. type: "treasure",
  247. data: tag,
  248. });
  249. apis.burying_point({type:2});
  250. } else if (tag.type == "applet_link") {
  251. browser.openLink(tag.hotContent.liveLink)
  252. } else if (tag.type == "link_scene") {
  253. let sceneFirstView = tag.hotContent.sceneFirstView;
  254. window.location.href = "".concat(window.location.pathname, "?").concat(`m=${sceneFirstView.num}&novideo=1&${sceneFirstView.sceneview}`);
  255. }
  256. });
  257. });
  258. view.on("focus", (e) => {
  259. document.querySelectorAll("[xui_tags_view] >div").forEach((el) => {
  260. if (el.getAttribute("data-tag-type") == "commodity" || el.getAttribute("data-tag-type") == "waterfall") {
  261. el.querySelector(".tag-body").classList.remove("show");
  262. el.style.zIndex = "auto";
  263. }
  264. });
  265. if (e.data.type == "commodity" || e.data.type == "waterfall") {
  266. e.target.style.zIndex = "999";
  267. e.target.querySelector(".tag-body").classList.add("show");
  268. e.target.querySelector(".tag-commodity").removeEventListener("click", onClickTagInfo);
  269. e.target.querySelector(".tag-commodity").addEventListener("click", onClickTagInfo);
  270. }
  271. });
  272. });
  273. app.use("TourPlayer");
  274. // if (!hadVideo.value) {
  275. // app.Scene.lock();
  276. // }
  277. app.Scene.on("ready", () => {
  278. show.value = true;
  279. });
  280. app.Scene.on("loaded", (pano) => {
  281. refMiniMap.value = "[xui_min_map]";
  282. store.commit("setFloorId", pano.floorIndex);
  283. app.resource.tags(`${process.env.VUE_APP_RESOURCE_URL}cdf/hot/${browser.getURLParam("m")}/hot.json?rnd=${Math.random()}`);
  284. useMusicPlayer();
  285. });
  286. app.Scene.on("panorama.videorenderer.resumerender", () => {
  287. musicPlayer.pause(true);
  288. });
  289. app.Scene.on("panorama.videorenderer.suspendrender", async () => {
  290. let player = await getApp().TourManager.player;
  291. if (!player.isPlaying) {
  292. musicPlayer.resume();
  293. }
  294. });
  295. app.store.on("metadata", (metadata) => {
  296. store.commit("scene/load", metadata);
  297. if (!metadata.controls.showMap) {
  298. app.MinMap.hide(true);
  299. }
  300. dataLoaded.value = true;
  301. });
  302. app.store.on("tags", (tags) => {
  303. store.commit("tag/load", tags);
  304. });
  305. app.Camera.on("mode.beforeChange", ({ fromMode, toMode, floorIndex }) => {
  306. if (fromMode) {
  307. store.commit("setFlying", true);
  308. }
  309. });
  310. app.Camera.on("mode.afterChange", ({ toMode, floorIndex }) => {
  311. store.commit("setFlying", false);
  312. });
  313. app.Camera.on("flying.started", (pano) => {
  314. store.commit("setFlying", true);
  315. });
  316. app.Camera.on("flying.ended", ({ targetPano }) => {
  317. store.commit("setFlying", false);
  318. store.commit("setPanoId", targetPano.id);
  319. if (app.Scene.isCurrentPanoHasVideo) {
  320. apis.burying_point({type:5});
  321. }
  322. });
  323. app.Camera.on("pano.chosen", (pano) => {
  324. apis.burying_point({type:4});
  325. });
  326. app.store.on("tour", async (tour) => {
  327. app.TourManager.load(tour);
  328. store.commit("tour/setData", {
  329. tours: JSON.parse(
  330. JSON.stringify(app.TourManager.tours, (key, val) => {
  331. if (key === "audio") {
  332. return null;
  333. } else {
  334. return val;
  335. }
  336. })
  337. ),
  338. });
  339. store.commit("tour/setBackUp", {
  340. tours: JSON.parse(
  341. JSON.stringify(app.TourManager.tours, (key, val) => {
  342. if (key === "audio") {
  343. return null;
  344. } else {
  345. return val;
  346. }
  347. })
  348. ),
  349. });
  350. });
  351. app.store.on("floorcad", (floor) => store.commit("scene/loadFloorData", floor));
  352. app.render();
  353. document.addEventListener('visibilitychange',()=>{
  354. if (document.hidden) {
  355. apis.burying_point({type:1});
  356. }
  357. })
  358. });
  359. </script>
  360. <style lang="scss">
  361. .tab-layer {
  362. width: 100%;
  363. text-align: center;
  364. display: flex;
  365. justify-content: center;
  366. align-items: center;
  367. z-index: 10;
  368. position: fixed;
  369. left: 50%;
  370. transform: translateX(-50%);
  371. top: 2.3rem;
  372. pointer-events: none;
  373. }
  374. .tabs {
  375. pointer-events: auto;
  376. position: relative;
  377. display: flex;
  378. background: #222222;
  379. border-radius: 6px;
  380. padding: 2px;
  381. justify-content: center;
  382. align-items: center;
  383. border: 1px solid rgba(255, 255, 255, 0.1);
  384. box-shadow: inset 0px 0px 6px 0px rgba(0, 0, 0, 0.5);
  385. .background {
  386. position: absolute;
  387. left: 2px;
  388. top: 2px;
  389. bottom: 2px;
  390. width: 50%;
  391. border-radius: 4px;
  392. background: #444444;
  393. box-shadow: 2px 0px 4px 0px rgba(0, 0, 0, 0.3);
  394. z-index: 0;
  395. transition: left 0.3s;
  396. }
  397. span {
  398. flex: 1;
  399. color: #fff;
  400. opacity: 0.5;
  401. border-radius: 6px;
  402. height: 0.94737rem;
  403. font-size: 0.36842rem;
  404. transition: all 0.3s ease;
  405. display: flex;
  406. align-items: center;
  407. justify-content: center;
  408. padding-left: 10px;
  409. padding-right: 10px;
  410. white-space: nowrap;
  411. z-index: 1;
  412. i {
  413. font-size: 0.47368rem;
  414. margin-right: 4px;
  415. pointer-events: none;
  416. }
  417. }
  418. span.active {
  419. opacity: 1;
  420. }
  421. }
  422. [xui_tags_view] {
  423. .tag-body {
  424. /* display: none; */
  425. position: absolute;
  426. left: 50%;
  427. bottom: 50px;
  428. transform: translateX(-50%) scale(0);
  429. transform-origin: bottom;
  430. transition: all 0.3s cubic-bezier(0.35, 0.32, 0.65, 0.63);
  431. // pointer-events: none;
  432. .tag-commodity {
  433. min-width: 230px;
  434. height: 76px;
  435. background: rgba(255, 255, 255, 0.8);
  436. box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.16);
  437. border-radius: 2px;
  438. position: relative;
  439. margin-bottom: 30px;
  440. &::before {
  441. content: "";
  442. display: inline-block;
  443. left: 50%;
  444. transform: translateX(-50%);
  445. width: 2px;
  446. height: 28px;
  447. bottom: -30px;
  448. background: linear-gradient(145deg, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0));
  449. position: absolute;
  450. }
  451. .tag-avatar {
  452. position: absolute;
  453. z-index: 99;
  454. width: 80px;
  455. height: 80px;
  456. background: #ffffff;
  457. box-shadow: 0px 3px 6px 0px rgb(0 0 0 / 16%);
  458. border-radius: 2px;
  459. top: -14px;
  460. left: -12px;
  461. background-size: cover;
  462. pointer-events: none;
  463. }
  464. > p {
  465. color: #131d34;
  466. font-size: 16px;
  467. pointer-events: none;
  468. }
  469. .tag-title {
  470. padding: 10px 10px 10px 76px;
  471. overflow: hidden;
  472. text-overflow: ellipsis;
  473. white-space: nowrap;
  474. width: 240px;
  475. }
  476. .tag-info {
  477. padding: 0 20px 0 76px;
  478. font-size: 12px;
  479. overflow: hidden;
  480. text-overflow: ellipsis;
  481. white-space: nowrap;
  482. }
  483. }
  484. &.show {
  485. transform: translateX(-50%) scale(1);
  486. }
  487. }
  488. .coupon {
  489. width: 64px !important;
  490. height: 64px !important;
  491. &::after {
  492. content: "發現好禮";
  493. width: 100%;
  494. color: #ed5d18;
  495. position: absolute;
  496. bottom: -24px;
  497. text-align: center;
  498. font-size: 14px;
  499. }
  500. }
  501. .applet_link {
  502. width: 64px !important;
  503. height: 64px !important;
  504. border-radius: 50%;
  505. background-color: #fff;
  506. border: 1px solid #ed5d18;
  507. position: relative;
  508. overflow: hidden;
  509. &::after {
  510. content: "直播中";
  511. width: 100%;
  512. height: 20px;
  513. background: #ed5d18;
  514. position: absolute;
  515. bottom: 0;
  516. text-align: center;
  517. line-height: 1.2;
  518. font-size: 12px;
  519. border-radius: 26%;
  520. }
  521. }
  522. }
  523. @media (orientation: landscape) {
  524. .tab-layer {
  525. top: 1.2rem;
  526. .tabs {
  527. height: 0.7rem;
  528. > span {
  529. height: 0.7rem;
  530. font-size: 0.25rem;
  531. }
  532. }
  533. }
  534. }
  535. </style>