index.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import { defineComponent, onMounted, ref } from 'vue';
  2. import { storeToRefs } from 'pinia';
  3. import { useRoute } from 'vue-router';
  4. import Other from './components/other';
  5. import Menu from './components/menu';
  6. import GuiLoading from './components/gui-loading';
  7. import Popup from './components/popup/index.vue';
  8. import HotSpotList from './components/hot-spot-list';
  9. import type { HotDataType } from '@/types';
  10. import useBaseStore from '@/store/module/base';
  11. import { CAMERA_TYPE_ENUM, CameraTypeMap } from '@/types/home';
  12. import './index.scss';
  13. export default defineComponent({
  14. name: 'home',
  15. components: {
  16. Other,
  17. GuiLoading,
  18. Popup,
  19. },
  20. setup() {
  21. const baseStore = useBaseStore();
  22. const { checkedHotData, hotVisible } = storeToRefs(baseStore);
  23. const route = useRoute();
  24. const cameraMode = ref(CAMERA_TYPE_ENUM.PANORAMA);
  25. const init = async () => {
  26. // @ts-ignore
  27. const kankan = new KanKan({
  28. dom: '#player',
  29. num: route.query.m,
  30. server: 'https://www.4dkankan.com',
  31. });
  32. kankan.use('MinMap', {
  33. theme: {
  34. camera_fillStyle: '#000000',
  35. },
  36. });
  37. // 热点
  38. kankan
  39. .use('TagView', {
  40. // 自定义热点图标
  41. // render(data) {
  42. // return `<div>${data.title}</div>`
  43. // }
  44. })
  45. .then((TagView) => {
  46. window.TagView = TagView;
  47. // 监听手动点击事件
  48. TagView.on('click', (e) => {
  49. console.log(e);
  50. const isLink = e.data.title.startsWith('(link)');
  51. if (isLink) {
  52. const regex = new RegExp(`<\/?p[^>]*>`, 'g');
  53. const link = e.data.content.replace(regex, '');
  54. const isHttp = link.startsWith('http');
  55. window.location.href = isHttp ? link : `https://scene.4dage.com${link}`;
  56. } else {
  57. // this.openHotFu(e.data);
  58. baseStore.setState('checkedHotData', e.data);
  59. baseStore.setState('hotVisible', true);
  60. }
  61. });
  62. });
  63. // 全部热点数据
  64. kankan.store.on('tags', (tags) => {
  65. baseStore.setState('hotList', tags.tags);
  66. });
  67. // 监听看看的模式
  68. kankan.Camera.on('mode.beforeChange', ({ toMode }) => {
  69. cameraMode.value = CameraTypeMap[toMode];
  70. });
  71. // 有关球幕视频控制背景音乐
  72. kankan.Scene.on('panorama.videorenderer.startvideo', () => {
  73. // 进入球幕视频
  74. handleBgMusic(false);
  75. });
  76. kankan.Scene.on('panorama.videorenderer.resumerender', () => {
  77. // 进入球幕视频
  78. handleBgMusic(false);
  79. });
  80. kankan.Scene.on('panorama.videorenderer.suspendrender', () => {
  81. // 退出球幕视频
  82. handleBgMusic(true);
  83. });
  84. kankan.render();
  85. window.kankan = kankan;
  86. baseStore.setState('kankanInited', true);
  87. };
  88. const handleBgMusic = (type = true) => {
  89. if (type) {
  90. baseStore.bgMusicDom?.play();
  91. } else {
  92. baseStore.bgMusicDom?.pause();
  93. }
  94. baseStore.setState('bgMusicPlaying', type);
  95. };
  96. const closeHotDetail = () => {
  97. baseStore.setState('hotVisible', false);
  98. };
  99. let once = false;
  100. const handlePageClick = () => {
  101. if (once) return;
  102. handleBgMusic();
  103. once = true;
  104. };
  105. onMounted(() => {
  106. init();
  107. });
  108. return {
  109. hotVisible,
  110. checkedHotData,
  111. cameraMode,
  112. closeHotDetail,
  113. handlePageClick,
  114. };
  115. },
  116. render() {
  117. return (
  118. <div class="home" onClick={this.handlePageClick}>
  119. {/* 进度条加载 */}
  120. <GuiLoading />
  121. {/* 加载初始页面 */}
  122. <div id="gui-thumb" />
  123. {/* 热点弹出框 */}
  124. <Popup
  125. hotData={this.checkedHotData}
  126. visible={this.hotVisible}
  127. onUpdate:visible={this.closeHotDetail}
  128. />
  129. {/* 场景canvs主容器 */}
  130. <div id="player" />
  131. {/* 底部菜单 */}
  132. <div id="gui-parent">
  133. {/* 热点气泡 */}
  134. <div id="hot" />
  135. <div id="gui">
  136. {/* 热点列表 */}
  137. <HotSpotList />
  138. {/* 底部菜单 */}
  139. <Menu mode={this.cameraMode} />
  140. {/* <div class="home_logo">
  141. <img src="images/btm_logo.png" />
  142. <span>提供技术支持</span>
  143. </div> */}
  144. </div>
  145. <Other />
  146. </div>
  147. </div>
  148. );
  149. },
  150. });