SwkkView.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. <template>
  2. <div
  3. class="skww-view"
  4. >
  5. <div
  6. class="swkk-wrap"
  7. />
  8. <menu>
  9. <button
  10. :class="{active: isAutoMoving}"
  11. @click="onClickAutoMoving"
  12. >
  13. <img
  14. v-show="!isAutoMoving"
  15. src="@/assets\images\swkk\zidongmanyou.png"
  16. alt=""
  17. draggable="false"
  18. >
  19. <img
  20. v-show="isAutoMoving"
  21. src="@/assets\images\swkk\zidongmanyou_1.png"
  22. alt=""
  23. draggable="false"
  24. >
  25. <div>自动漫游</div>
  26. </button>
  27. <button
  28. :class="{active: isShowTourGuide}"
  29. @click="onClickCjdl"
  30. >
  31. <img
  32. v-show="!isShowTourGuide"
  33. src="@/assets\images\swkk\changjingdaolan.png"
  34. alt=""
  35. draggable="false"
  36. >
  37. <img
  38. v-show="isShowTourGuide"
  39. src="@/assets\images\swkk\changjingdaolan_1.png"
  40. alt=""
  41. draggable="false"
  42. >
  43. <div>场景导览</div>
  44. </button>
  45. <button
  46. :class="{active: mode === 2}"
  47. @click="onClickQjmy"
  48. >
  49. <img
  50. v-show="mode !== 2"
  51. src="@/assets\images\swkk\quanjingmanyou.png"
  52. alt=""
  53. draggable="false"
  54. >
  55. <img
  56. v-show="mode === 2"
  57. src="@/assets\images\swkk\quanjingmanyou_1.png"
  58. alt=""
  59. draggable="false"
  60. >
  61. <div>全景漫游</div>
  62. </button>
  63. <button
  64. :class="{active: mode === 3}"
  65. @click="onClickMnmx"
  66. >
  67. <img
  68. v-show="mode !== 3"
  69. src="@/assets\images\swkk\minimoxing.png"
  70. alt=""
  71. draggable="false"
  72. >
  73. <img
  74. v-show="mode === 3"
  75. src="@/assets\images\swkk\minimoxing_1.png"
  76. alt=""
  77. draggable="false"
  78. >
  79. <div>迷你模型</div>
  80. </button>
  81. <button
  82. :class="{active: mode === 4}"
  83. @click="onClickDbfs"
  84. >
  85. <img
  86. v-show="mode !== 4"
  87. src="@/assets\images\swkk\dingbufushi.png"
  88. alt=""
  89. draggable="false"
  90. >
  91. <img
  92. v-show="mode === 4"
  93. src="@/assets\images\swkk\dingbufushi_1.png"
  94. alt=""
  95. draggable="false"
  96. >
  97. <div>顶部俯视</div>
  98. </button>
  99. </menu>
  100. <!-- 右上地图 -->
  101. <div
  102. v-show="!isLoading && mode === 2"
  103. class="mini-map"
  104. >
  105. <div
  106. class="radio-wrap"
  107. :class="{ active: floor === '1' }"
  108. @click="changeFloor('1')"
  109. >
  110. <div class="radio" />
  111. <div class="rowrr">
  112. 一层
  113. </div>
  114. </div>
  115. <div
  116. class="radio-wrap"
  117. :class="{ active: floor === '2' }"
  118. @click="changeFloor('2')"
  119. >
  120. <div class="radio" />
  121. <div class="rowrr">
  122. 二层
  123. </div>
  124. </div>
  125. </div>
  126. <!-- 导览栏 -->
  127. <div
  128. v-show="isShowTourGuide"
  129. class="tour-guide-wrap"
  130. :style="{
  131. zIndex: $globalConfig.zIndex.swkkGuideBar.self
  132. }"
  133. >
  134. <ul
  135. v-if="tourList.length"
  136. class="tour-guide"
  137. >
  138. <li
  139. v-for="(item, index) in tourList"
  140. :key="item.sid"
  141. ref="scene-item"
  142. :class="{active: curSceneIdx === index}"
  143. @click="changeScene(index)"
  144. >
  145. <img
  146. :src="item.list[0].enter.cover"
  147. alt=""
  148. draggable="false"
  149. >
  150. <div
  151. v-show="isAutoMoving && (curSceneIdx === index)"
  152. class="progress"
  153. :style="{
  154. width: autoMovingProgress + '%',
  155. }"
  156. />
  157. <div class="title">
  158. {{ item.name }}
  159. </div>
  160. </li>
  161. </ul>
  162. </div>
  163. <HotspotDetail
  164. v-if="isShowDetail"
  165. class="hotspot-detail"
  166. :hotspot-list="relatedHotspotList"
  167. @close="isShowDetail = false"
  168. />
  169. </div>
  170. </template>
  171. <script>
  172. import HotspotDetail from "@/components/HotspotDetail.vue"
  173. export default {
  174. components: {
  175. HotspotDetail,
  176. },
  177. data() {
  178. //这里存放数据
  179. return {
  180. kankan: null,
  181. isLoading: true,
  182. floor: 0,
  183. canClickAutoMoving: false,
  184. isAutoMoving: false,
  185. isChangingAutoMovingStatus: false,
  186. autoMovingProgress: 0,
  187. isShowTourGuide: false,
  188. tourList: [],
  189. isChangingScene: false,
  190. curSceneIdx: null,
  191. mode: 2,
  192. baseHotData: null,
  193. isShowDetail: false,
  194. }
  195. },
  196. computed: {
  197. ...globalMapState([
  198. 'isMuted',
  199. ])
  200. },
  201. watch: {
  202. isMuted: {
  203. handler(vNew) {
  204. if (!vNew) {
  205. this.stopAutoMoving()
  206. }
  207. }
  208. },
  209. isAutoMoving: {
  210. handler(vNew) {
  211. if (vNew) {
  212. this.isShowTourGuide = true
  213. } else {
  214. }
  215. }
  216. },
  217. isShowTourGuide: {
  218. handler(vNew) {
  219. if (vNew) {
  220. this.$msgCenter.publish('swkk-guide-bar-show')
  221. } else {
  222. this.$msgCenter.publish('swkk-guide-bar-hide')
  223. }
  224. }
  225. }
  226. },
  227. beforeCreate() {
  228. },
  229. beforeMount() {
  230. },
  231. mounted() {
  232. // setTimeout(() => {
  233. this.$msgCenter.publish('show-loading')
  234. let floor = this.$route.query.floor
  235. this.floor = floor
  236. let sceneCode = ''
  237. if (floor === "1") sceneCode = process.env.VUE_APP_SCENE_CODE_FLOOR_1
  238. else if (floor === "2") sceneCode = process.env.VUE_APP_SCENE_CODE_FLOOR_2
  239. console.assert(sceneCode, 'no sceneCode!')
  240. // 不等一秒,就会因为use了小地图而卡死?
  241. // setTimeout(() => {
  242. let kankan = new KanKan({
  243. dom: ".swkk-wrap",
  244. num: sceneCode,
  245. })
  246. kankan.use("MinMap", {
  247. theme: {
  248. camera_fillStyle: "#930909",
  249. },
  250. })
  251. kankan.use("TourPlayer").then((player) => {
  252. player.on("play", ({ partId, frameId }) => {
  253. this.isAutoMoving = true
  254. this.isChangingAutoMovingStatus = false
  255. this.mustMute()
  256. })
  257. player.on("pause", ({ partId, frameId }) => {
  258. this.isAutoMoving = false
  259. this.isChangingAutoMovingStatus = false
  260. this.cancelMustMute()
  261. })
  262. player.on("end", async () => {
  263. this.isAutoMoving = false
  264. this.isChangingAutoMovingStatus = false
  265. this.autoMovingProgress = 0
  266. this.frameId = null
  267. this.cancelMustMute()
  268. })
  269. player.on("progress", ({ partId, frameId, progress }) => {
  270. if (partId !== this.curSceneIdx) {
  271. this.curSceneIdx = partId
  272. this.autoMovingProgress = 0
  273. this.$refs['scene-item'][this.curSceneIdx].scrollIntoView()
  274. }
  275. this.autoMovingProgress = (frameId / this.tourList[partId].list.length + Number(progress).toFixed(5) / this.tourList[partId].list.length) * 100
  276. })
  277. })
  278. // 导览数据
  279. kankan.TourManager.on("loaded", (tours) => {
  280. try {
  281. this.tourList = tours
  282. setTimeout(() => {
  283. this.canClickAutoMoving = true
  284. }, 1000)
  285. } catch (e) {
  286. console.error('没拿到导览数据:', e)
  287. this.tourList = []
  288. }
  289. this.$msgCenter.publish('hide-loading')
  290. })
  291. // 全部热点数据
  292. kankan.store.on("tags", (tags) => {
  293. this.baseHotData = tags.tags.reverse()
  294. console.log('baseHotData: ', this.baseHotData)
  295. })
  296. // 热点
  297. kankan.use("TagView", {
  298. render(data) {
  299. let ifNeedShow = false
  300. // data.title如果没有“&”或者是“a&b&show”这样子,就要显示。
  301. let arrTitle = data.title.split("&")
  302. if (arrTitle[2] === 'show' || !data.title.includes("&")) {
  303. ifNeedShow = true
  304. }
  305. let title = data.title.split("&")[0]
  306. return `
  307. <span class="tag-icon animate" title=${title} style="${ifNeedShow ? "" : "display: none;"}; background-image: url({{icon}})"></span>
  308. <div class="tag-body"></div>
  309. `
  310. },
  311. }).then((TagView) => {
  312. // 监听手动点击事件
  313. TagView.on("click", (e) => {
  314. // // 点击热点的时候当前背景音乐的播放状态
  315. // let dom = document.querySelector("#bacMusic")
  316. // window.bacMusic = !dom.paused
  317. // setTimeout(() => {
  318. // this.$refs.RbottomRef.opMusic(false)
  319. // }, 200)
  320. console.log(e.data)
  321. const example1 = {
  322. content: "<p>《胡乔木为他题词“浩气长存”》</p>",
  323. icon: "http://4dkk.4dage.com/v4/sdk/4.2.0/images/tag_icon_default.svg",
  324. media: {
  325. image: [
  326. { src: "q0AbKQ789922.jpeg" },
  327. { src: "kfhFHmL789632.jpeg" },
  328. ],
  329. },
  330. sid: "WfndN9Z789888",
  331. title: "陈处泰",
  332. type: "image",
  333. }
  334. const example2 = {
  335. content: "<p>汪裕先烈士狱中致姐姐的信</p>",
  336. media: {
  337. image: [
  338. { src: "q0AbKQ789922.jpeg" },
  339. { src: "kfhFHmL789632.jpeg" },
  340. ],
  341. },
  342. sid: "XQT0F8570262",
  343. title: "汪裕先&27&show",
  344. type: "image"
  345. }
  346. this.relatedHotspotList = []
  347. if (e.data.title.split("&")[1]) { // 如果是多个热点合并
  348. this.baseHotData.forEach((item) => {
  349. if (item.title.split("&")[1] === e.data.title.split("&")[1]) {
  350. this.relatedHotspotList.push(item)
  351. }
  352. })
  353. console.log(this.relatedHotspotList)
  354. } else { // 单个热点
  355. this.relatedHotspotList.push(e.data)
  356. }
  357. // 聚焦当前点击的热点
  358. TagView.focus(e.data.sid)
  359. this.isShowDetail = true
  360. })
  361. })
  362. // 球幕视频的播放与暂停影响背景音乐的播放状态
  363. kankan.Scene.on("panorama.videorenderer.startvideo", () => {
  364. console.log('startvideo')
  365. this.mustMute()
  366. })
  367. kankan.Scene.on("panorama.videorenderer.suspendrender", () => {
  368. console.log('suspend')
  369. this.cancelMustMute()
  370. })
  371. kankan.Scene.on("panorama.videorenderer.resumerender", () => {
  372. console.log('resume')
  373. this.mustMute()
  374. })
  375. kankan.Scene.on("loaded", () => {
  376. console.log('loaded!')
  377. this.isLoading = false
  378. //设置地面logo
  379. kankan.Scene.setFloorLogo({
  380. url: "./img/diBiao.png",
  381. size: 40,
  382. })
  383. })
  384. // 监听看看的模式
  385. kankan.Camera.on("mode.beforeChange", ({ toMode }) => {
  386. this.mode = {
  387. floorplan: 4,
  388. dollhouse: 3,
  389. panorama: 2,
  390. }[toMode]
  391. })
  392. kankan.render()
  393. this.kankan = kankan
  394. // }, 1000)
  395. // }, 500)
  396. },
  397. beforeDestroy() {
  398. this.stopAutoMoving()
  399. },
  400. methods: {
  401. ...globalMapMutations([
  402. 'mustMute',
  403. 'cancelMustMute',
  404. ]),
  405. // 切换楼层
  406. changeFloor(val) {
  407. let newHref = location.href.substring(0, location.href.length - 1) + val
  408. location.href = newHref
  409. location.reload()
  410. },
  411. onClickAutoMoving() {
  412. if (!this.canClickAutoMoving) {
  413. return
  414. }
  415. if (this.isAutoMoving) {
  416. this.stopAutoMoving()
  417. } else {
  418. this.startAutoMoving()
  419. }
  420. },
  421. async startAutoMoving() {
  422. if (this.isChangingAutoMovingStatus || this.isAutoMoving) {
  423. return
  424. }
  425. this.isChangingAutoMovingStatus = true
  426. let player = await this.kankan.TourManager.player
  427. player.play()
  428. },
  429. async stopAutoMoving() {
  430. if (this.isChangingAutoMovingStatus || !this.isAutoMoving) {
  431. return
  432. }
  433. this.isChangingAutoMovingStatus = true
  434. let player = await this.kankan.TourManager.player
  435. player.pause()
  436. },
  437. onClickCjdl() {
  438. this.isShowTourGuide = !this.isShowTourGuide
  439. },
  440. onClickQjmy() {
  441. this.kankan.Camera.panorama()
  442. },
  443. onClickMnmx() {
  444. this.stopAutoMoving()
  445. this.kankan.Camera.dollhouse()
  446. },
  447. onClickDbfs() {
  448. this.stopAutoMoving()
  449. this.kankan.Camera.floorplan()
  450. },
  451. async changeScene(index) {
  452. if (this.isChangingScene) {
  453. return
  454. }
  455. this.stopAutoMoving()
  456. this.isChangingScene = true
  457. this.curSceneIdx = index
  458. let player = await this.kankan.TourManager.player
  459. player.pause()
  460. await player.selectPart(index)
  461. this.isChangingScene = false
  462. },
  463. },
  464. }
  465. </script>
  466. <style lang="less" scoped>
  467. .skww-view {
  468. position: relative;
  469. width: 100%;
  470. height: 100%;
  471. z-index: 0;
  472. .swkk-wrap {
  473. position: absolute;
  474. top: 0;
  475. left: 0;
  476. width: 100%;
  477. height: 100%;
  478. z-index: 0;
  479. }
  480. > menu {
  481. position: absolute;
  482. z-index: 1;
  483. top: 2rem;
  484. left: 1.75rem;
  485. display: flex;
  486. flex-direction: column;
  487. align-items: center;
  488. gap: 0.83rem;
  489. > button {
  490. > img {
  491. width: 5rem;
  492. height: 5rem;
  493. }
  494. > div {
  495. color: #fff;
  496. text-shadow: 0px 0px 0.2rem rgba(255,255,255,0.6);
  497. margin-top: 0.17rem;
  498. font-size: 1.17rem;
  499. }
  500. &.active {
  501. > div {
  502. color: #930909;
  503. text-shadow: 0px 0px 0.2rem rgba(255,255,255,0.6);
  504. }
  505. }
  506. }
  507. }
  508. /deep/[xui_min_map] {
  509. top: 7rem;
  510. right: 1.67rem;
  511. width: 18rem;
  512. height: 18rem;
  513. border: 0.08rem solid #D8B275;
  514. background-color: rgba(81, 32, 32, 0.4);
  515. border-radius: 0 0 0.42rem 0.42rem;
  516. }
  517. .mini-map {
  518. position: absolute;
  519. z-index: 1;
  520. right: 1.67rem;
  521. top: 2.5rem;
  522. border: 0.08rem solid #d8b275;
  523. border-radius: 0.42rem 0.42rem 0 0;
  524. color: #fff;
  525. width: 18rem;
  526. height: 4.6rem;
  527. background-color: #930909;
  528. display: flex;
  529. justify-content: space-evenly;
  530. .radio-wrap {
  531. display: flex;
  532. justify-content: center;
  533. align-items: center;
  534. font-size: 1.67rem;
  535. .radio {
  536. margin-right: 0.5rem;
  537. width: 2.2rem;
  538. height: 2.2rem;
  539. border-radius: 50%;
  540. border: 0.08rem solid #fff;
  541. position: relative;
  542. }
  543. .rowrr {
  544. }
  545. }
  546. .active {
  547. color: #d8b275;
  548. pointer-events: none;
  549. .radio {
  550. &::after {
  551. content: "";
  552. position: absolute;
  553. top: 50%;
  554. left: 50%;
  555. transform: translate(-50%, -50%);
  556. border-radius: 50%;
  557. width: 1rem;
  558. height: 1rem;
  559. background-color: #d8b275;
  560. }
  561. }
  562. }
  563. }
  564. .tour-guide-wrap {
  565. position: absolute;
  566. left: 0;
  567. bottom: 0;
  568. width: 100%;
  569. height: 13.75rem;
  570. background: rgba(216,178,117,0.6);
  571. padding: 1.17rem 1.17rem 1.92rem 1.17rem;
  572. .tour-guide {
  573. display: flex;
  574. align-items: center;
  575. gap: 0.83rem;
  576. overflow: auto;
  577. width: 100%;
  578. height: 100%;
  579. > li {
  580. flex: 0 0 auto;
  581. width: 12.5rem;
  582. height: 10.5rem;
  583. position: relative;
  584. > img {
  585. background: #D26868;
  586. width: 100%;
  587. height: 7.5rem;
  588. object-fit: cover;
  589. }
  590. > .progress {
  591. position: absolute;
  592. left: 0;
  593. top: 6.7rem;
  594. height: 0.5rem;
  595. background-color: #930909;
  596. }
  597. .title {
  598. margin-top: 0.5rem;
  599. text-align: center;
  600. font-size: 1.25rem;
  601. color: #FFFFFF;
  602. white-space: pre;
  603. word-break: break-all;
  604. overflow: hidden;
  605. text-overflow: ellipsis;
  606. }
  607. &.active {
  608. > img {
  609. border: 0.33rem solid #930909;
  610. }
  611. .title {
  612. color: #930909;
  613. }
  614. }
  615. }
  616. }
  617. }
  618. .hotspot-detail {
  619. position: absolute;
  620. top: 0;
  621. left: 0;
  622. width: 100%;
  623. height: 100%;
  624. }
  625. }
  626. </style>