index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <div class="hotspot-page">
  3. <div class="hotspot-page-info">
  4. <h3>{{ myTitle }}</h3>
  5. <p>{{ myTxt }}</p>
  6. </div>
  7. <!-- 音频图标 -->
  8. <div
  9. v-if="audio && !isOneAduio"
  10. class="audioIcon"
  11. :title="audioSta ? '关闭音频' : '打开音频'"
  12. @click="audioSta = !audioSta"
  13. >
  14. <img :src="audioSta ? VolumeOff : VolumeOn" alt="" />
  15. </div>
  16. <div class="hotspot-page-main">
  17. <!-- 音频播放器 -->
  18. <audio
  19. id="myAudio"
  20. v-if="audio"
  21. ref="volumeRef"
  22. v-show="isOneAduio"
  23. :src="audio"
  24. controls
  25. ></audio>
  26. <!-- 模型页面 -->
  27. <Swiper
  28. v-if="myType === 'model'"
  29. class="hotspot-page-swiper hotspot-page-model"
  30. @swiper="initSwiper"
  31. @slideChange="handleChange"
  32. >
  33. <SwiperSlide v-for="(item, index) in curList" :key="item.url">
  34. <iframe v-if="index === myInd" :src="item" frameborder="0" />
  35. </SwiperSlide>
  36. </Swiper>
  37. <!-- 视频页面 -->
  38. <Swiper
  39. v-if="myType === 'video'"
  40. class="hotspot-page-swiper hotspot-page-video"
  41. @swiper="initSwiper"
  42. @slideChange="handleChange"
  43. >
  44. <SwiperSlide v-for="(item, index) in curList" :key="item.url">
  45. <video
  46. v-if="index === myInd"
  47. id="videoID"
  48. class="hotspot-page-video"
  49. controls
  50. :src="item.url"
  51. autoplay
  52. />
  53. </SwiperSlide>
  54. </Swiper>
  55. <!-- 图片页面 -->
  56. <Swiper
  57. v-if="myType === 'img'"
  58. class="hotspot-page-swiper hotspot-page-img-swiper"
  59. @swiper="initSwiper"
  60. @slideChange="handleChange"
  61. >
  62. <SwiperSlide v-for="item in curList" :key="item">
  63. <div class="hotspot-page-img">
  64. <img :src="item" alt="" />
  65. </div>
  66. </SwiperSlide>
  67. </Swiper>
  68. <template v-if="curList.length > 1">
  69. <div class="hotspot-page-swiper__left" @click="handlePre" />
  70. <div class="hotspot-page-swiper__right" @click="handleNext" />
  71. </template>
  72. </div>
  73. <!-- 底部的tab -->
  74. <div v-if="flooTab.length > 1" class="hotspot-page-nav">
  75. <div
  76. v-for="item in flooTab"
  77. :key="item.id"
  78. :class="[
  79. 'hotspot-page-nav__item',
  80. {
  81. active: myType === item.type,
  82. },
  83. ]"
  84. @click="handleTab(item)"
  85. >
  86. <img :class="`${item.type}-icon`" :src="myType === item.type ? item.acIcon : item.icon" />
  87. {{ item.name }}
  88. {{ item.type === 'img' ? `${myInd + 1}/${data.img.length}` : '' }}
  89. </div>
  90. </div>
  91. </div>
  92. </template>
  93. <script>
  94. import { Swiper, SwiperSlide } from 'swiper/vue';
  95. import 'swiper/css';
  96. import { parseUrlParams } from '@/utils';
  97. import ModelIcon from '@hotspot/assets/images/icon-model@2x.png';
  98. import AcModelIcon from '@hotspot/assets/images/icon-model-1@2x.png';
  99. import ImageIcon from '@hotspot/assets/images/icon-image@2x.png';
  100. import AcImageIcon from '@hotspot/assets/images/icon-image-1@2x.png';
  101. import VideoIcon from '@hotspot/assets/images/icon-video@2x.png';
  102. import AcVideoIcon from '@hotspot/assets/images/icon-video-1@2x.png';
  103. import VolumeOn from '@hotspot/assets/images/Volume-on.png';
  104. import VolumeOff from '@hotspot/assets/images/Volume-off.png';
  105. const urlParams = parseUrlParams(window.location.href);
  106. export default {
  107. name: 'hotspot',
  108. components: {
  109. Swiper,
  110. SwiperSlide,
  111. },
  112. data() {
  113. return {
  114. VolumeOn,
  115. VolumeOff,
  116. m: urlParams.m,
  117. id: urlParams.id,
  118. // 音频地址
  119. audio: '',
  120. // 如果只有单独的音频
  121. isOneAduio: false,
  122. // 音频状态
  123. audioSta: false,
  124. data: {
  125. // 模型数组
  126. model: [],
  127. // 视频数组
  128. video: [],
  129. // 图片数组
  130. img: [],
  131. },
  132. // 当前 type
  133. myType: '',
  134. // 当前索引
  135. myInd: 0,
  136. // 底部的tab
  137. flooTab: [],
  138. // 标题
  139. myTitle: '',
  140. // 内容
  141. myTxt: '',
  142. // 视频内容
  143. videoTxt: [],
  144. imgTxt: [],
  145. // 只有标题和文字(没有视频,没有模型,没有图片)
  146. oneTxt: false,
  147. };
  148. },
  149. computed: {
  150. curList() {
  151. return this.data[this.myType] || [];
  152. },
  153. },
  154. watch: {
  155. audioSta(val) {
  156. if (val) {
  157. this.$refs.volumeRef.play();
  158. this.$refs.volumeRef.onended = () => {
  159. // console.log("----音频播放完毕");
  160. this.audioSta = false;
  161. };
  162. } else this.$refs.volumeRef.pause();
  163. },
  164. },
  165. mounted() {
  166. this.getData();
  167. },
  168. methods: {
  169. async getData() {
  170. // https://www.4dmodel.com/
  171. let url = `https://super.4dage.com/data/${this.id}/hot/js/data.js?time=${Math.random()}`;
  172. let result = await fetch(url).then((response) => response.json());
  173. const resData = result[this.m];
  174. console.log('----', resData);
  175. if (resData) {
  176. this.audio = resData.backgroundMusic;
  177. // 只有单独的音频上传
  178. if (resData.backgroundMusic && !resData.model && !resData.video && !resData.images) {
  179. this.isOneAduio = true;
  180. }
  181. // 底部的tab
  182. const arr = [];
  183. const obj = {};
  184. if (resData.model) {
  185. obj.model = resData.model;
  186. arr.push({ id: 1, type: 'model', name: '模型', icon: ModelIcon, acIcon: AcModelIcon });
  187. }
  188. if (resData.video) {
  189. obj.video = resData.video;
  190. arr.push({ id: 2, type: 'video', name: '视频', icon: VideoIcon, acIcon: AcVideoIcon });
  191. } else {
  192. this.$nextTick(() => {
  193. if (
  194. !window.navigator.userAgent.match(
  195. /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
  196. )
  197. ) {
  198. this.audioSta = true;
  199. this.$refs.volumeRef.play();
  200. }
  201. });
  202. }
  203. if (resData.images) {
  204. obj.img = resData.images;
  205. arr.push({ id: 3, type: 'img', name: '图片', icon: ImageIcon, acIcon: AcImageIcon });
  206. }
  207. this.flooTab = arr;
  208. this.data = obj;
  209. // 当前type的值 应该为
  210. if (resData.model) this.myType = 'model';
  211. else if (resData.video) this.myType = 'video';
  212. else if (resData.images) this.myType = 'img';
  213. this.myTitle = resData.title || '';
  214. this.myTxt = resData.content || '';
  215. this.videoTxt = resData.videosDesc || [];
  216. this.imgTxt = resData.imagesDesc || [];
  217. // 只有 标题和 文字介绍(没有视频,没有模型,没有图片)
  218. if (!obj.model && !obj.video && !obj.img && !resData.backgroundMusic) {
  219. this.oneTxt = true;
  220. }
  221. }
  222. },
  223. handleTab(item) {
  224. this.myInd = 0;
  225. this.myType = item.type;
  226. },
  227. initSwiper(swiper) {
  228. this.swiper = swiper;
  229. },
  230. handleChange({ activeIndex }) {
  231. this.myInd = activeIndex;
  232. },
  233. handlePre() {
  234. this.swiper?.slidePrev();
  235. },
  236. handleNext() {
  237. this.swiper?.slideNext();
  238. },
  239. },
  240. };
  241. </script>
  242. <style lang="scss">
  243. @import './index.scss';
  244. </style>