app.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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. }
  172. };
  173. onMounted(async () => {
  174. apis.burying_point({ type: 0 });
  175. app = createApp({
  176. num: browser.getURLParam("m"),
  177. dom: scene$.value,
  178. mobile: true,
  179. isLoadTags: false,
  180. scene: {
  181. markerURL: "https://eurs3.4dkankan.com/cdf/file/43aa29799bfd472298a47cc6370b10cc.png",
  182. },
  183. });
  184. app.use("MinMap", { theme: { camera_fillStyle: "#ED5D18" } });
  185. app.use("Tag");
  186. app
  187. .use("TagView", {
  188. render(data) {
  189. if (data.type == "waterfall") {
  190. return `<span class="tag-icon waterfall animate" style="background-image:url({{icon}})"></span>`;
  191. } else if (data.type == "coupon") {
  192. return `<span class="tag-icon coupon animate" style="background-image:url({{icon}})"></span>`;
  193. } else if (data.type == "applet_link") {
  194. try {
  195. data.hotContent = JSON.parse(data.hotContent);
  196. } catch (error) {}
  197. return `<span class="tag-icon applet_link animate" style="background-image:url(${
  198. data.hotContent.liveIcon.src ? common.changeUrl(data.hotContent.liveIcon.src) : "{{icon}}"
  199. })"></span>`;
  200. } else if (data.type == "link_scene") {
  201. return `<span class="tag-icon animate" style="background-image:url({{icon}})"></span>`;
  202. } else if (data.type == "commodity") {
  203. let arr = data.products.map((item) => item.price);
  204. let priceMin = Math.min.apply(null, arr);
  205. let priceMax = Math.max.apply(null, arr);
  206. let price = priceMin == priceMax ? priceMax : `${priceMin}-${priceMax}`;
  207. let range = `${data.products[0].symbol} ${price}`;
  208. return `<span class="tag-icon animate" style="background-image:url({{icon}})"></span>
  209. <div class="tag-body">
  210. <div data-id="${data.sid}" class="tag-commodity">
  211. <div style="background-image:url(${data.products[0].pic})" class='tag-avatar'>
  212. </div>
  213. <p class="tag-title">${data.title}</p>
  214. <p class="tag-info">${range} | 查看 ></p>
  215. </div>
  216. </div>
  217. `;
  218. } else {
  219. return `<span class="tag-icon animate" style="background-image:url({{icon}})"></span>`;
  220. }
  221. },
  222. })
  223. .then((view) => {
  224. view.on("click", (e) => {
  225. var tag = e.data;
  226. // 聚焦當前點擊的熱點
  227. view.focus(tag.sid).then(() => {
  228. if (tag.type == "coupon") {
  229. store.commit("tag/setTagClickType", {
  230. type: "treasure",
  231. data: tag,
  232. });
  233. apis.burying_point({ type: 2 });
  234. } else if (tag.type == "waterfall") {
  235. store.commit("tag/setTagClickType", {
  236. type: "waterfall",
  237. data: tag,
  238. });
  239. } else if (tag.type == "applet_link") {
  240. browser.openLink(tag.hotContent.liveLink);
  241. } else if (tag.type == "link_scene") {
  242. let sceneFirstView = tag.hotContent.sceneFirstView;
  243. window.location.href = "".concat(window.location.pathname, "?").concat(`m=${sceneFirstView.num}&novideo=1&${sceneFirstView.sceneview}`);
  244. }
  245. });
  246. });
  247. view.on("focus", (e) => {
  248. document.querySelectorAll("[xui_tags_view] >div").forEach((el) => {
  249. if (el.getAttribute("data-tag-type") == "commodity") {
  250. el.querySelector(".tag-body").classList.remove("show");
  251. el.style.zIndex = "auto";
  252. }
  253. });
  254. if (e.data.type == "commodity") {
  255. e.target.style.zIndex = "999";
  256. e.target.querySelector(".tag-body").classList.add("show");
  257. e.target.querySelector(".tag-commodity").removeEventListener("click", onClickTagInfo);
  258. e.target.querySelector(".tag-commodity").addEventListener("click", onClickTagInfo);
  259. }
  260. });
  261. });
  262. app.use("TourPlayer");
  263. // if (!hadVideo.value) {
  264. // app.Scene.lock();
  265. // }
  266. app.Scene.on("ready", () => {
  267. show.value = true;
  268. });
  269. app.Scene.on("loaded", (pano) => {
  270. refMiniMap.value = "[xui_min_map]";
  271. store.commit("setFloorId", pano.floorIndex);
  272. app.resource.tags(`${process.env.VUE_APP_RESOURCE_URL}cdf/hot/${browser.getURLParam("m")}/hot.json?rnd=${Math.random()}`);
  273. useMusicPlayer();
  274. });
  275. app.Scene.on("panorama.videorenderer.resumerender", () => {
  276. musicPlayer.pause(true);
  277. });
  278. app.Scene.on("panorama.videorenderer.suspendrender", async () => {
  279. let player = await getApp().TourManager.player;
  280. if (!player.isPlaying) {
  281. musicPlayer.resume();
  282. }
  283. });
  284. app.store.on("metadata", (metadata) => {
  285. store.commit("scene/load", metadata);
  286. if (!metadata.controls.showMap) {
  287. app.MinMap.hide(true);
  288. }
  289. dataLoaded.value = true;
  290. });
  291. app.store.on("tags", (tags) => {
  292. store.commit("tag/load", tags);
  293. });
  294. app.Camera.on("mode.beforeChange", ({ fromMode, toMode, floorIndex }) => {
  295. if (fromMode) {
  296. store.commit("setFlying", true);
  297. }
  298. });
  299. app.Camera.on("mode.afterChange", ({ toMode, floorIndex }) => {
  300. store.commit("setFlying", false);
  301. });
  302. app.Camera.on("flying.started", (pano) => {
  303. store.commit("setFlying", true);
  304. });
  305. app.Camera.on("flying.ended", ({ targetPano }) => {
  306. store.commit("setFlying", false);
  307. store.commit("setPanoId", targetPano.id);
  308. if (app.Scene.isCurrentPanoHasVideo) {
  309. apis.burying_point({ type: 5 });
  310. }
  311. });
  312. app.Camera.on("pano.chosen", (pano) => {
  313. apis.burying_point({ type: 4 });
  314. });
  315. app.store.on("tour", async (tour) => {
  316. app.TourManager.load(tour);
  317. store.commit("tour/setData", {
  318. tours: JSON.parse(
  319. JSON.stringify(app.TourManager.tours, (key, val) => {
  320. if (key === "audio") {
  321. return null;
  322. } else {
  323. return val;
  324. }
  325. })
  326. ),
  327. });
  328. store.commit("tour/setBackUp", {
  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. });
  340. app.store.on("floorcad", (floor) => store.commit("scene/loadFloorData", floor));
  341. app.render();
  342. document.addEventListener("visibilitychange", () => {
  343. if (document.hidden) {
  344. apis.burying_point({ type: 1 });
  345. }
  346. });
  347. });
  348. </script>
  349. <style lang="scss">
  350. .tab-layer {
  351. width: 100%;
  352. text-align: center;
  353. display: flex;
  354. justify-content: center;
  355. align-items: center;
  356. z-index: 10;
  357. position: fixed;
  358. left: 50%;
  359. transform: translateX(-50%);
  360. top: 2.3rem;
  361. pointer-events: none;
  362. }
  363. .tabs {
  364. pointer-events: auto;
  365. position: relative;
  366. display: flex;
  367. background: #222222;
  368. border-radius: 6px;
  369. padding: 2px;
  370. justify-content: center;
  371. align-items: center;
  372. border: 1px solid rgba(255, 255, 255, 0.1);
  373. box-shadow: inset 0px 0px 6px 0px rgba(0, 0, 0, 0.5);
  374. .background {
  375. position: absolute;
  376. left: 2px;
  377. top: 2px;
  378. bottom: 2px;
  379. width: 50%;
  380. border-radius: 4px;
  381. background: #444444;
  382. box-shadow: 2px 0px 4px 0px rgba(0, 0, 0, 0.3);
  383. z-index: 0;
  384. transition: left 0.3s;
  385. }
  386. span {
  387. flex: 1;
  388. color: #fff;
  389. opacity: 0.5;
  390. border-radius: 6px;
  391. height: 0.94737rem;
  392. font-size: 0.36842rem;
  393. transition: all 0.3s ease;
  394. display: flex;
  395. align-items: center;
  396. justify-content: center;
  397. padding-left: 10px;
  398. padding-right: 10px;
  399. white-space: nowrap;
  400. z-index: 1;
  401. i {
  402. font-size: 0.47368rem;
  403. margin-right: 4px;
  404. pointer-events: none;
  405. }
  406. }
  407. span.active {
  408. opacity: 1;
  409. }
  410. }
  411. [xui_tags_view] {
  412. .tag-body {
  413. /* display: none; */
  414. position: absolute;
  415. left: 50%;
  416. bottom: 50px;
  417. transform: translateX(-50%) scale(0);
  418. transform-origin: bottom;
  419. transition: all 0.3s cubic-bezier(0.35, 0.32, 0.65, 0.63);
  420. // pointer-events: none;
  421. .tag-commodity {
  422. min-width: 230px;
  423. height: 76px;
  424. background: rgba(255, 255, 255, 0.8);
  425. box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.16);
  426. border-radius: 2px;
  427. position: relative;
  428. margin-bottom: 30px;
  429. &::before {
  430. content: "";
  431. display: inline-block;
  432. left: 50%;
  433. transform: translateX(-50%);
  434. width: 2px;
  435. height: 28px;
  436. bottom: -30px;
  437. background: linear-gradient(145deg, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0));
  438. position: absolute;
  439. }
  440. .tag-avatar {
  441. position: absolute;
  442. z-index: 99;
  443. width: 80px;
  444. height: 80px;
  445. background: #ffffff;
  446. box-shadow: 0px 3px 6px 0px rgb(0 0 0 / 16%);
  447. border-radius: 2px;
  448. top: -14px;
  449. left: -12px;
  450. background-size: cover;
  451. pointer-events: none;
  452. }
  453. > p {
  454. color: #131d34;
  455. font-size: 16px;
  456. pointer-events: none;
  457. }
  458. .tag-title {
  459. padding: 10px 10px 10px 76px;
  460. overflow: hidden;
  461. text-overflow: ellipsis;
  462. white-space: nowrap;
  463. width: 240px;
  464. }
  465. .tag-info {
  466. padding: 0 20px 0 76px;
  467. font-size: 12px;
  468. overflow: hidden;
  469. text-overflow: ellipsis;
  470. white-space: nowrap;
  471. }
  472. }
  473. &.show {
  474. transform: translateX(-50%) scale(1);
  475. }
  476. }
  477. .coupon {
  478. width: 64px !important;
  479. height: 64px !important;
  480. &::after {
  481. content: "發現好禮";
  482. width: 100%;
  483. color: #ed5d18;
  484. position: absolute;
  485. bottom: -24px;
  486. text-align: center;
  487. font-size: 14px;
  488. }
  489. }
  490. .waterfall {
  491. width: 70px !important;
  492. height: 70px !important;
  493. }
  494. .applet_link {
  495. width: 64px !important;
  496. height: 64px !important;
  497. border-radius: 50%;
  498. background-color: #fff;
  499. border: 1px solid #ed5d18;
  500. position: relative;
  501. overflow: hidden;
  502. &::after {
  503. content: "直播中";
  504. width: 100%;
  505. height: 20px;
  506. background: #ed5d18;
  507. position: absolute;
  508. bottom: 0;
  509. text-align: center;
  510. line-height: 1.2;
  511. font-size: 12px;
  512. border-radius: 26%;
  513. }
  514. }
  515. }
  516. @media (orientation: landscape) {
  517. .tab-layer {
  518. top: 1.2rem;
  519. .tabs {
  520. height: 0.7rem;
  521. > span {
  522. height: 0.7rem;
  523. font-size: 0.25rem;
  524. }
  525. }
  526. }
  527. }
  528. </style>