app.vue 16 KB

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