Home.vue 13 KB

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