app.vue 16 KB

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