index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 ModelIcon from '@/assets/images/icon-model@2x.png';
  97. import AcModelIcon from '@/assets/images/icon-model-1@2x.png';
  98. import ImageIcon from '@/assets/images/icon-image@2x.png';
  99. import AcImageIcon from '@/assets/images/icon-image-1@2x.png';
  100. import VideoIcon from '@/assets/images/icon-video@2x.png';
  101. import AcVideoIcon from '@/assets/images/icon-video-1@2x.png';
  102. import VolumeOn from '@/assets/images/Volume-on.png';
  103. import VolumeOff from '@/assets/images/Volume-off.png';
  104. export default {
  105. name: 'hotspot',
  106. components: {
  107. Swiper,
  108. SwiperSlide,
  109. },
  110. data() {
  111. return {
  112. VolumeOn,
  113. VolumeOff,
  114. m: this.$route.query.m,
  115. id: this.$route.query.id,
  116. // 音频地址
  117. audio: '',
  118. // 如果只有单独的音频
  119. isOneAduio: false,
  120. // 音频状态
  121. audioSta: false,
  122. data: {
  123. // 模型数组
  124. model: [],
  125. // 视频数组
  126. video: [],
  127. // 图片数组
  128. img: [],
  129. },
  130. // 当前 type
  131. myType: '',
  132. // 当前索引
  133. myInd: 0,
  134. // 底部的tab
  135. flooTab: [],
  136. // 标题
  137. myTitle: '',
  138. // 内容
  139. myTxt: '',
  140. // 视频内容
  141. videoTxt: [],
  142. imgTxt: [],
  143. // 只有标题和文字(没有视频,没有模型,没有图片)
  144. oneTxt: false,
  145. };
  146. },
  147. computed: {
  148. curList() {
  149. return this.data[this.myType] || [];
  150. },
  151. },
  152. watch: {
  153. audioSta(val) {
  154. if (val) {
  155. this.$refs.volumeRef.play();
  156. this.$refs.volumeRef.onended = () => {
  157. // console.log("----音频播放完毕");
  158. this.audioSta = false;
  159. };
  160. } else this.$refs.volumeRef.pause();
  161. },
  162. },
  163. mounted() {
  164. this.getData();
  165. },
  166. methods: {
  167. async getData() {
  168. // https://www.4dmodel.com/
  169. let url = `https://super.4dage.com/data/${this.id}/hot/js/data.js?time=${Math.random()}`;
  170. let result = await fetch(url).then((response) => response.json());
  171. const resData = result[this.m];
  172. console.log('----', resData);
  173. if (resData) {
  174. this.audio = resData.backgroundMusic;
  175. // 只有单独的音频上传
  176. if (resData.backgroundMusic && !resData.model && !resData.video && !resData.images) {
  177. this.isOneAduio = true;
  178. }
  179. // 底部的tab
  180. const arr = [];
  181. const obj = {};
  182. if (resData.model) {
  183. obj.model = resData.model;
  184. arr.push({ id: 1, type: 'model', name: '模型', icon: ModelIcon, acIcon: AcModelIcon });
  185. }
  186. if (resData.video) {
  187. obj.video = resData.video;
  188. arr.push({ id: 2, type: 'video', name: '视频', icon: VideoIcon, acIcon: AcVideoIcon });
  189. } else {
  190. this.$nextTick(() => {
  191. this.audioSta = true;
  192. this.$refs.volumeRef.play();
  193. });
  194. }
  195. if (resData.images) {
  196. obj.img = resData.images;
  197. arr.push({ id: 3, type: 'img', name: '图片', icon: ImageIcon, acIcon: AcImageIcon });
  198. }
  199. this.flooTab = arr;
  200. this.data = obj;
  201. // 当前type的值 应该为
  202. if (resData.model) this.myType = 'model';
  203. else if (resData.video) this.myType = 'video';
  204. else if (resData.images) this.myType = 'img';
  205. this.myTitle = resData.title || '';
  206. this.myTxt = resData.content || '';
  207. this.videoTxt = resData.videosDesc || [];
  208. this.imgTxt = resData.imagesDesc || [];
  209. // 只有 标题和 文字介绍(没有视频,没有模型,没有图片)
  210. if (!obj.model && !obj.video && !obj.img && !resData.backgroundMusic) {
  211. this.oneTxt = true;
  212. }
  213. }
  214. },
  215. handleTab(item) {
  216. this.myInd = 0;
  217. this.myType = item.type;
  218. },
  219. initSwiper(swiper) {
  220. this.swiper = swiper;
  221. },
  222. handleChange({ activeIndex }) {
  223. this.myInd = activeIndex;
  224. },
  225. handlePre() {
  226. this.swiper?.slidePrev();
  227. },
  228. handleNext() {
  229. this.swiper?.slideNext();
  230. },
  231. },
  232. };
  233. </script>
  234. <style lang="scss">
  235. @import './index.scss';
  236. </style>