Home.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. <!-- -->
  2. <template>
  3. <div class="Home" @click.once="onceClickMusic">
  4. <div class="loading" v-show="loding">
  5. <div class="loadBox">
  6. <div class="loadIcon">
  7. <img src="../assets/img/loading.png" alt="" />
  8. </div>
  9. <div class="txt">加载中</div>
  10. </div>
  11. </div>
  12. <div class="box" @click="stopPlay(false)"></div>
  13. <!-- 右上地图 -->
  14. <div class="rightMap" v-show="!loding && numSta === 2">
  15. <div class="row1" @click="cutFool('1')" :class="{ active: num === '1' }">
  16. <div class="rowll"></div>
  17. <div class="rowrr">一层</div>
  18. </div>
  19. <div class="row1" @click="cutFool('2')" :class="{ active: num === '2' }">
  20. <div class="rowll"></div>
  21. <div class="rowrr">二层</div>
  22. </div>
  23. </div>
  24. <!-- 右下按钮 -->
  25. <Rbottom
  26. ref="RbottomRef"
  27. @cutKankan="cutKankan"
  28. @daoLanCut="daoLanCut"
  29. @stopPlay="stopPlay"
  30. :acList="partId"
  31. :playing="playing"
  32. :progressPart="progressPart"
  33. :clickBottomAc.sync="clickBottomAc"
  34. @openHot="openHot"
  35. />
  36. <!-- 左上名字和介绍 -->
  37. <div class="Ltitle" :class="{ open: title }">
  38. <div class="Ltitlell" @click="title = !title">
  39. <img src="../assets/img/LeftTop/title_left.png" alt="" v-if="title" />
  40. <img src="../assets/img/LeftTop/title_right.png" alt="" v-else />
  41. </div>
  42. <div class="Ltitlerr" v-show="title">
  43. 南京雨花台烈士纪念馆{{ num === "1" ? "一" : "二" }}楼
  44. </div>
  45. </div>
  46. <!-- 点击热点出来的界面 -->
  47. <Hot
  48. v-if="sonInfo"
  49. :info="sonInfo"
  50. :hotIdOrName="hotIdOrName"
  51. @hotClose="hotClose"
  52. />
  53. <!-- 新手指引页面 -->
  54. <Guide />
  55. </div>
  56. </template>
  57. <script>
  58. import Hot from "../components/Hot.vue";
  59. import Guide from "../components/Guide.vue";
  60. import Rbottom from "../components/Rbottom.vue";
  61. export default {
  62. name: "Home",
  63. //import引入的组件需要注入到对象中才能使用
  64. components: { Rbottom, Hot, Guide },
  65. data() {
  66. //这里存放数据
  67. return {
  68. kankan: null,
  69. num: "",
  70. loding: true,
  71. title: true,
  72. numSta: 2,
  73. // -------自动导览数据
  74. partId: 0,
  75. frameId: null,
  76. progress: 0,
  77. progressPart: 0,
  78. disable: false,
  79. playing: false,
  80. sonInfo: null,
  81. hotIdOrName: null,
  82. clickBottomAc: false,
  83. // 点位背景音乐的状态
  84. dotAudioSrc: "",
  85. };
  86. },
  87. //监听属性 类似于data概念
  88. computed: {},
  89. //监控data中的数据变化
  90. watch: {},
  91. //方法集合
  92. methods: {
  93. // 热点点击关闭
  94. hotClose() {
  95. this.sonInfo = null;
  96. if (window.bacMusic) {
  97. setTimeout(() => {
  98. this.$refs.RbottomRef.opMusic(true);
  99. }, 100);
  100. }
  101. },
  102. onceClickMusic() {
  103. this.$refs.RbottomRef.opMusic(true);
  104. setTimeout(() => {
  105. window.bacMusic = true;
  106. }, 500);
  107. },
  108. async stopPlay(val) {
  109. if (!val && this.playing) this.$refs.RbottomRef.leftCut(-1);
  110. let player = await this.kankan.TourManager.player;
  111. player.pause();
  112. this.progress = 0;
  113. },
  114. async play() {
  115. let player = await this.kankan.TourManager.player;
  116. this.progress = 0;
  117. if (this.playing) {
  118. player.pause();
  119. } else {
  120. player.play();
  121. }
  122. },
  123. // 场景导览切换
  124. async daoLanCut(index) {
  125. if (this.disable) {
  126. return;
  127. }
  128. this.partId = index;
  129. this.frameId = 0;
  130. this.disable = true;
  131. this.progress = 0;
  132. this.progressPart = 0;
  133. let player = await this.kankan.TourManager.player;
  134. player.pause();
  135. await player.selectPart(index);
  136. this.disable = false;
  137. this.clickBottomAc = true;
  138. },
  139. // 切换楼层
  140. cutFool(val) {
  141. // window.location.replace(`#/Swkk${val}`)
  142. window.location.replace(`/YHT/Swkk/index.html#/${val}`);
  143. setTimeout(() => {
  144. location.reload(true);
  145. }, 200);
  146. },
  147. cutKankan(ind) {
  148. if (ind === 0) {
  149. // 点击自动漫游
  150. // this.kankan.Camera.panorama();
  151. this.play();
  152. this.progressPart = 0;
  153. const dotAudioDomId = document.querySelector("#dotAudioDomId");
  154. if (dotAudioDomId) document.body.removeChild(dotAudioDomId);
  155. }
  156. if (ind === 2) this.kankan.Camera.panorama();
  157. else if (ind === 3) this.kankan.Camera.dollhouse();
  158. else if (ind === 4) this.kankan.Camera.floorplan();
  159. },
  160. openHot(data) {
  161. this.openHotFu(data);
  162. },
  163. // 封装点击热点的函数
  164. openHotFu(data) {
  165. // console.log('-------',data);
  166. // 点击热点的时候当前背景音乐的播放状态
  167. let dom = document.querySelector("#bacMusic");
  168. window.bacMusic = !dom.paused;
  169. setTimeout(() => {
  170. this.$refs.RbottomRef.opMusic(false);
  171. }, 700);
  172. let temp = [];
  173. // 如果是多个热点合并
  174. if (data.title.split("&")[1]) {
  175. this.baseHotData.forEach((v) => {
  176. if (v.title.split("&")[1] === data.title.split("&")[1]) {
  177. temp.push(v);
  178. if (v.media && v.media.image && v.media.image.length > 1) {
  179. v.media.image.forEach((p, pI) => {
  180. if (pI !== 0) temp.push({ ...v, media: { image: [p] } });
  181. });
  182. }
  183. }
  184. });
  185. let obj = {
  186. image: [],
  187. audio: [],
  188. link: [],
  189. video: [],
  190. };
  191. temp.forEach((v) => {
  192. if (obj[v.type]) obj[v.type].push(v);
  193. });
  194. for (const k in obj) {
  195. if (k === "audio") {
  196. obj[k].reverse();
  197. }
  198. }
  199. this.hotIdOrName = {
  200. id: data.sid,
  201. name: data.title.split("&")[0],
  202. };
  203. this.sonInfo = obj;
  204. } else {
  205. this.hotIdOrName = {
  206. id: data.sid,
  207. name: data.title,
  208. };
  209. // 单个热点
  210. this.sonInfo = { [data.type]: [data] };
  211. }
  212. // 如果只需监听热点点击,实现其他逻辑操作,下面的代码不需要调用
  213. // 聚焦当前点击的热点
  214. window.TagView.focus(data.sid);
  215. },
  216. },
  217. //生命周期 - 创建完成(可以访问当前this实例)
  218. created() {},
  219. //生命周期 - 挂载完成(可以访问DOM元素)
  220. mounted() {
  221. let num = this.$route.params.id;
  222. this.num = num;
  223. if (num === "1") num = "KJ-aigSkgvRWR";
  224. else if (num === "2") num = "KJ-ufjLwlSXba";
  225. window.KKNum = num;
  226. let kankan = new KanKan({
  227. dom: ".box",
  228. num,
  229. // 本地化加上
  230. deploy:'local',
  231. resource:'',
  232. server:''
  233. });
  234. kankan.use("MinMap", {
  235. theme: {
  236. camera_fillStyle: "#930909",
  237. },
  238. });
  239. kankan.use("TourPlayer").then((player) => {
  240. player.on("play", ({ partId, frameId }) => {
  241. this.playing = true;
  242. });
  243. player.on("pause", ({ partId, frameId }) => {
  244. this.playing = false;
  245. });
  246. player.on("end", async () => {
  247. this.playing = false;
  248. this.progress = 0;
  249. this.frameId = null;
  250. this.$refs.RbottomRef.leftCut(-1);
  251. // 兼容最后一个画面没有进度的问题
  252. this.progressPart = 100;
  253. });
  254. let currPartId;
  255. let currFrames;
  256. player.on("progress", ({ partId, frameId, progress }) => {
  257. // 不让自动漫游多次点击
  258. if (frameId === 0) {
  259. // 防止多次点击自动漫游
  260. let mainApp = document.querySelector("#app");
  261. mainApp.style.pointerEvents = "auto";
  262. }
  263. // 画面进度
  264. this.partId = partId;
  265. this.frameId = frameId;
  266. this.progress = Number(progress * 100).toFixed(5);
  267. // 片段进度
  268. if (this.tours.length == 1) {
  269. this.progressPart = this.progress;
  270. } else {
  271. if (currPartId != partId) {
  272. currPartId = partId;
  273. currFrames = this.tours[partId].list.length;
  274. this.progressPart = 0;
  275. }
  276. this.progressPart += progress / currFrames;
  277. }
  278. });
  279. });
  280. // 有关球幕视频控制背景音乐
  281. kankan.Scene.on("panorama.videorenderer.startvideo", () => {
  282. // 进入球幕视频
  283. let dom = document.querySelector("#bacMusic");
  284. window.bacMusic = !dom.paused;
  285. setTimeout(() => {
  286. this.$refs.RbottomRef.opMusic(false);
  287. // 如果有对应的点位音频,删除
  288. const dotAudioDomId = document.querySelector("#dotAudioDomId");
  289. if (dotAudioDomId) document.body.removeChild(dotAudioDomId);
  290. }, 200);
  291. // 暂停背景音乐
  292. });
  293. kankan.Scene.on("panorama.videorenderer.resumerender", () => {
  294. // 进入球幕视频
  295. let dom = document.querySelector("#bacMusic");
  296. window.bacMusic = !dom.paused;
  297. setTimeout(() => {
  298. this.$refs.RbottomRef.opMusic(false);
  299. // 如果有对应的点位音频,删除
  300. const dotAudioDomId = document.querySelector("#dotAudioDomId");
  301. if (dotAudioDomId) document.body.removeChild(dotAudioDomId);
  302. }, 200);
  303. // 暂停背景音乐
  304. });
  305. kankan.Scene.on("panorama.videorenderer.suspendrender", () => {
  306. // 退出球幕视频
  307. if (window.bacMusic) {
  308. setTimeout(() => {
  309. this.$refs.RbottomRef.opMusic(true);
  310. }, 100);
  311. }
  312. // 恢复背景音乐
  313. });
  314. // 导览数据
  315. kankan.TourManager.on("loaded", (tours) => {
  316. // console.log("--------", tours);
  317. this.tours = tours;
  318. this.$refs.RbottomRef.baseSw(tours);
  319. });
  320. // 全部热点数据
  321. kankan.store.on("tags", (tags) => {
  322. this.$refs.RbottomRef.getHotListToFather(tags.tags);
  323. this.baseHotData = tags.tags.reverse();
  324. });
  325. // 热点
  326. kankan
  327. .use("TagView", {
  328. render(data) {
  329. let arrTitle = data.title.split("&");
  330. let flag = false;
  331. if (arrTitle[2] || !data.title.includes("&")) flag = true;
  332. let title = data.title.split("&")[0];
  333. return `<span class="tag-icon animate" title=${title} style="${
  334. flag ? "" : "display: none;"
  335. };background-image:url({{icon}})"></span><div class="tag-body"></div>`;
  336. },
  337. })
  338. .then((TagView) => {
  339. window.TagView = TagView;
  340. // 监听手动点击事件
  341. TagView.on("click", (e) => {
  342. this.openHotFu(e.data);
  343. });
  344. });
  345. kankan.render();
  346. kankan.Scene.on("loaded", () => {
  347. this.loding = false;
  348. //设置地面logo
  349. kankan.Scene.setFloorLogo({
  350. url: "img/diBiao.png",
  351. size: 40,
  352. });
  353. });
  354. let obj = {
  355. floorplan: 4,
  356. dollhouse: 3,
  357. panorama: 2,
  358. };
  359. // 监听看看的模式
  360. kankan.Camera.on("mode.beforeChange", ({ toMode, floorIndex }) => {
  361. let num = obj[toMode];
  362. this.numSta = num;
  363. if (this.$refs.RbottomRef && this.$refs.RbottomRef.leftCut) {
  364. this.$refs.RbottomRef.leftCut(num);
  365. }
  366. });
  367. // 每次移动了点位就会触发
  368. kankan.Camera.on("flying.started", (pano) => {
  369. // 如果不是自动导览改变了点位的时候,才有手动移动到固定点位的逻辑
  370. if (!this.playing) {
  371. // console.log(123456, pano);
  372. // 固定点位的id
  373. const dotId = pano.panoId;
  374. // 走到固定点位播放音频
  375. const obj = {
  376. 60: "dingxiang.mp3",
  377. 112: "liyunsheng.mp3",
  378. };
  379. // 记录当前点位音乐的路径,用于下面的对比
  380. if (obj[dotId]) {
  381. // 如果当前已经在播放音频了,并且对应的src相等
  382. if (this.dotAudioSrc === obj[dotId]) return;
  383. else {
  384. // 如果当前点位音频的src不相等
  385. this.dotAudioSrc = obj[dotId];
  386. const audio = document.createElement("audio");
  387. audio.src = `dotAudio/${obj[dotId]}`;
  388. audio.id = "dotAudioDomId";
  389. document.body.appendChild(audio);
  390. // 暂停背景音乐并且记录背景音乐的状态
  391. let dom = document.querySelector("#bacMusic");
  392. window.bacMusic = !dom.paused;
  393. setTimeout(() => {
  394. this.$refs.RbottomRef.opMusic(false);
  395. }, 200);
  396. // 播放点位的对应音频
  397. audio.play();
  398. }
  399. } else {
  400. this.dotAudioSrc = "";
  401. // 如果有对应的点位音频,删除
  402. const dotAudioDomId = document.querySelector("#dotAudioDomId");
  403. if (dotAudioDomId) document.body.removeChild(dotAudioDomId);
  404. // 离开的有音频的点位,看看之前的背景音乐状态,判断时候播放背景音乐
  405. if (window.bacMusic) {
  406. setTimeout(() => {
  407. this.$refs.RbottomRef.opMusic(true);
  408. }, 100);
  409. }
  410. }
  411. }
  412. this.clickBottomAc = false;
  413. });
  414. this.kankan = kankan;
  415. },
  416. beforeCreate() {}, //生命周期 - 创建之前
  417. beforeMount() {}, //生命周期 - 挂载之前
  418. beforeUpdate() {}, //生命周期 - 更新之前
  419. updated() {}, //生命周期 - 更新之后
  420. beforeDestroy() {}, //生命周期 - 销毁之前
  421. destroyed() {}, //生命周期 - 销毁完成
  422. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  423. };
  424. </script>
  425. <style lang='less' scoped>
  426. @keyframes loading {
  427. 100% {
  428. left: -900px;
  429. }
  430. }
  431. .Home {
  432. width: 100%;
  433. height: 100%;
  434. overflow: hidden;
  435. position: relative;
  436. .box {
  437. width: 100%;
  438. height: 100%;
  439. position: absolute;
  440. top: 0;
  441. left: 0;
  442. }
  443. .loading {
  444. position: absolute;
  445. top: 0;
  446. left: 0;
  447. z-index: 12;
  448. width: 100%;
  449. height: 100%;
  450. background: rgba(0, 0, 0, 0.5);
  451. display: flex;
  452. justify-content: center;
  453. align-items: center;
  454. .loadBox {
  455. color: #fff;
  456. text-align: center;
  457. letter-spacing: 2px;
  458. width: 110px;
  459. height: 110px;
  460. border-radius: 2px;
  461. .loadIcon {
  462. width: 60px;
  463. height: 60px;
  464. position: relative;
  465. overflow: hidden;
  466. margin: 10px auto;
  467. img {
  468. height: 60px;
  469. position: absolute;
  470. left: 0;
  471. top: 0;
  472. animation: loading 1s steps(15) infinite;
  473. }
  474. }
  475. }
  476. }
  477. /deep/[xui_min_map] {
  478. width: 180px;
  479. height: 180px;
  480. border: 2px solid #d8b275;
  481. background-color: rgba(81, 32, 32, 0.4);
  482. border-radius: 0 0 8px 8px;
  483. right: 20px;
  484. top: 65px;
  485. }
  486. .rightMap {
  487. position: absolute;
  488. z-index: 1;
  489. right: 20px;
  490. top: 28px;
  491. border: 2px solid #d8b275;
  492. border-radius: 8px 8px 0 0;
  493. color: #fff;
  494. width: 180px;
  495. height: 40px;
  496. background-color: #930909;
  497. display: flex;
  498. justify-content: space-between;
  499. padding: 0 15px;
  500. .row1 {
  501. cursor: pointer;
  502. display: flex;
  503. justify-content: center;
  504. align-items: center;
  505. font-size: 14px;
  506. .rowll {
  507. margin-right: 6px;
  508. width: 20px;
  509. height: 20px;
  510. border-radius: 50%;
  511. border: 1px solid #d8b275;
  512. position: relative;
  513. }
  514. .rowrr {
  515. padding-bottom: 2px;
  516. }
  517. }
  518. .active {
  519. color: #d8b275;
  520. pointer-events: none;
  521. .rowll {
  522. &::after {
  523. content: "";
  524. position: absolute;
  525. top: 50%;
  526. left: 50%;
  527. transform: translate(-50%, -50%);
  528. border-radius: 50%;
  529. width: 10px;
  530. height: 10px;
  531. background-color: #d8b275;
  532. }
  533. }
  534. }
  535. }
  536. .Ltitle {
  537. transition: all 0.3s;
  538. position: absolute;
  539. z-index: 10;
  540. left: -196px;
  541. top: 28px;
  542. width: 230px;
  543. height: 34px;
  544. background-image: url("../assets/img/LeftTop/label_title.png");
  545. background-size: 100% 100%;
  546. display: flex;
  547. .Ltitlell {
  548. position: relative;
  549. left: 196px;
  550. cursor: pointer;
  551. width: 44px;
  552. height: 100%;
  553. padding: 6px 0 0px 10px;
  554. & > img {
  555. width: 8px;
  556. height: 13px;
  557. }
  558. }
  559. .Ltitlerr {
  560. width: 186px;
  561. height: 40px;
  562. line-height: 32px;
  563. font-size: 14px;
  564. color: #fff;
  565. }
  566. }
  567. .open {
  568. left: 0;
  569. .Ltitlell {
  570. left: 0;
  571. }
  572. }
  573. }
  574. </style>