Home.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. <template>
  2. <!-- @click="autoplay" @touchstart="autoplay" -->
  3. <div class="home">
  4. <audio v-if="audio" class="audio" id="audio1" :src="audio" preload ref="musicBg" @ended="overAudio"></audio>
  5. <div class="content" v-if="(!audio && fixIcon.length > 0) || (audio && fixIcon.length > 1)"
  6. :class="{ isMobileCon: isMobile }">
  7. <div v-if="!isMobile && lengthShow" @click="slideto('slidePrev')" class="swiper-button-prev"></div>
  8. <div class="mb-intro" v-show="active === 'title' && isMobile">
  9. <p v-html="data.title"></p>
  10. <p v-html="data.content"></p>
  11. <p v-html="data.imagesDesc[myInd]" v-if="data.imagesDesc && data.imagesDesc[myInd] && active === 'images'
  12. "></p>
  13. <p v-html="data.videosDesc[myInd]" v-if="data.videosDesc && data.videosDesc[myInd] && active === 'video'"></p>
  14. </div>
  15. <!-- 查看图片 -->
  16. <viewer class="viewerCla" ref="viewer" :images="lookPics">
  17. <img :src="lookPics[0]" alt="" />
  18. </viewer>
  19. <swiper v-show="active !== 'title'" class="warpper" ref="mySwiper" :options="swiperOptions">
  20. <swiper-slide v-for="(item, i) in data[active]" :key="i">
  21. <div class="slide">
  22. <img style="cursor: pointer" v-if="active === 'images'" v-lazy="fixUrl(item)" @click="lookImg(fixUrl(item))"
  23. alt="" />
  24. <video class="videoDom" v-else-if="active === 'video'" :src="fixUrl(item.url)" controls></video>
  25. <iframe @click="colseParent(item)" v-else-if="active === 'model' || active === 'iframe'" :src="fixUrl(item)"
  26. frameborder="0"></iframe>
  27. </div>
  28. </swiper-slide>
  29. <div class="swiper-pagination" slot="pagination" v-show="lengthShow"></div>
  30. </swiper>
  31. <div v-if="!isMobile && lengthShow" @click="slideto('slideNext')" class="swiper-button-next"></div>
  32. </div>
  33. <ul class="iconarr" v-if="fixIcon.length > 0" :class="{ oneChuMusic: fixIcon.length === 1 && !audio }">
  34. <li :class="{
  35. active: item.id === active || item.audioAc,
  36. onlyTxt: audio && fixIcon.length === 2 && i !== 0,
  37. }" @click="changeActive(item.id, item.audioAc)" v-for="(item, i) in fixIcon" :key="i">
  38. <img :src="require(`@/assets/images/${item.img}.png`)" alt="" />
  39. <span>{{ item.name }}</span>
  40. </li>
  41. </ul>
  42. <div class="intro" :class="{
  43. ismtop:
  44. (!audio && fixIcon.length === 0) || (audio && fixIcon.length === 1),
  45. }" v-if="!isMobile || (isMobile && fixIcon.length <= 0)">
  46. <h3 v-html="data.title"></h3>
  47. <p v-html="data.content"></p>
  48. <p v-html="data.imagesDesc[myInd]" v-if="data.imagesDesc && data.imagesDesc[myInd] && active === 'images'"></p>
  49. <p v-html="data.videosDesc[myInd]" v-if="data.videosDesc && data.videosDesc[myInd] && active === 'video'"></p>
  50. </div>
  51. </div>
  52. </template>
  53. <script>
  54. import { Swiper, SwiperSlide } from "vue-awesome-swiper";
  55. import "swiper/css/swiper.css";
  56. import browser from "@/utils/browser";
  57. let iconArr = [
  58. {
  59. name: "音频",
  60. id: "audio",
  61. img: "audio-icon",
  62. display: false,
  63. audioAc: false,
  64. },
  65. { name: "图片", id: "images", img: "img-icon", display: false },
  66. { name: "视频", id: "video", img: "video-icon", display: false },
  67. { name: "网页", id: "iframe", img: "iframe-icon", display: false },
  68. { name: "模型", id: "model", img: "model-icon", display: false },
  69. ];
  70. browser.mobile &&
  71. iconArr.push({ name: "介绍", id: "title", img: "txt-icon", display: false });
  72. export default {
  73. name: "Home",
  74. data() {
  75. return {
  76. lookPics: [],
  77. // 图片描述的索引
  78. myInd: 0,
  79. lengthShow: false,
  80. // 看看是不是只有一张图,一个视频或irm,只有一张图的时候隐藏左右按钮和小圆点
  81. audio: "",
  82. m: this.$route.query.m,
  83. id: this.$route.query.id,
  84. isMobile: browser.mobile,
  85. isAndriod: browser.android,
  86. swiperOptions: browser.mobile
  87. ? {
  88. pagination: {
  89. el: ".swiper-pagination",
  90. clickable: true,
  91. },
  92. on: {
  93. slideChangeTransitionEnd: () => {
  94. let swiper = this.$refs.mySwiper.$swiper;
  95. let activeIndex = swiper.activeIndex;
  96. this.myInd = activeIndex;
  97. },
  98. },
  99. }
  100. : {
  101. slidesPerView: 3,
  102. spaceBetween: 0,
  103. centeredSlides: true,
  104. pagination: {
  105. el: ".swiper-pagination",
  106. clickable: true,
  107. },
  108. on: {
  109. slideChangeTransitionEnd: () => {
  110. let swiper = this.$refs.mySwiper.$swiper;
  111. let activeIndex = swiper.activeIndex;
  112. this.myInd = activeIndex;
  113. },
  114. },
  115. },
  116. data: {},
  117. iconArr,
  118. active: "",
  119. };
  120. },
  121. watch: {
  122. myInd: {
  123. handler(newv) {
  124. this.$nextTick(() => {
  125. setTimeout(() => {
  126. if (this.active == "video") {
  127. // 控制当前选中的视频播放
  128. let videoDoms = document.querySelectorAll(".videoDom");
  129. videoDoms.forEach((v, i) => {
  130. if (i === newv) v.play();
  131. else v.pause();
  132. });
  133. }
  134. }, 500);
  135. });
  136. },
  137. immediate: true,
  138. },
  139. active(newVal) {
  140. let AcDataLength = this.data[newVal].length - 1;
  141. if (this.myInd > AcDataLength) this.myInd = AcDataLength;
  142. // 判断是否只有一张图片或者视频,ifrm lengthShow
  143. let tempType = this.data[newVal];
  144. if (tempType && tempType.length && tempType.length > 1)
  145. this.lengthShow = true;
  146. else this.lengthShow = false;
  147. if (!newVal) {
  148. return;
  149. }
  150. if (!this.$refs.musicBg) {
  151. return;
  152. }
  153. // 如果点击的是音频
  154. setTimeout(() => {
  155. if (newVal == "video") {
  156. this.audioAc(false);
  157. if (!this.$refs.musicBg.paused) {
  158. this.$refs.musicBg.pause();
  159. }
  160. }
  161. // 控制当前选中的视频播放
  162. let videoDoms = document.querySelectorAll(".videoDom");
  163. videoDoms.forEach((v, i) => {
  164. if (i === this.myInd) v.play();
  165. else v.pause();
  166. });
  167. }, 500);
  168. },
  169. },
  170. computed: {
  171. swiper() {
  172. return this.$refs.mySwiper.$swiper;
  173. },
  174. fixIcon() {
  175. let arr = this.iconArr.filter((item) => !!item.display);
  176. return arr;
  177. },
  178. },
  179. components: {
  180. Swiper,
  181. SwiperSlide,
  182. },
  183. methods: {
  184. // 点击查看大图
  185. lookImg(url) {
  186. let dom = this.$refs.viewer.$viewer;
  187. this.lookPics = [url];
  188. dom.show();
  189. },
  190. // 音频播放完毕
  191. overAudio() {
  192. console.log("播放声音完毕");
  193. this.audioAc(false);
  194. },
  195. // 音频的状态
  196. audioAc(flag) {
  197. this.iconArr.forEach((v) => {
  198. if (v.id === "audio") v.audioAc = flag;
  199. });
  200. },
  201. // 点击切换图片--视频
  202. changeActive(id, flag) {
  203. if (id === "audio" && flag === false) {
  204. this.audioAc(true);
  205. this.$refs.musicBg.play();
  206. return;
  207. } else if (id === "audio" && flag === true) {
  208. this.audioAc(false);
  209. this.$refs.musicBg.pause();
  210. return;
  211. }
  212. this.active = id;
  213. },
  214. async getData() {
  215. let url = `data/${this.id
  216. }/hot/js/data.js?time=${Math.random()}`;
  217. let result = (await this.$http.get(url)).data;
  218. this.data = result[this.m];
  219. if (!this.data) {
  220. return alert("热点解析错误");
  221. }
  222. this.audio = this.data["backgroundMusic"];
  223. if (!this.data.content && this.isMobile) {
  224. this.iconArr.pop();
  225. }
  226. this.iconArr.forEach((item) => {
  227. if (this.data[item.id]) {
  228. this.active = !this.active ? item.id : this.active;
  229. item.display = true;
  230. }
  231. // 如果有音频
  232. if (item.id === "audio" && this.audio) item.display = true;
  233. });
  234. },
  235. colseParent(item) {
  236. if (this.isMobile) {
  237. if (
  238. item.indexOf("mp.weixin.qq.com/mp/") > -1 &&
  239. this.active === "iframe"
  240. ) {
  241. window.parent.document.getElementById("closepop").click();
  242. }
  243. }
  244. },
  245. fixUrl(item) {
  246. let condition =
  247. item.indexOf("http://") > -1 || item.indexOf("https://") > -1;
  248. if (this.isMobile) {
  249. if (
  250. item.indexOf("mp.weixin.qq.com/mp/") > -1 &&
  251. this.active === "iframe"
  252. ) {
  253. return `https://www.4dmodel.com/SuperTwo/hot_online1/linktoWC.html?url=${encodeURIComponent(
  254. item
  255. )}`;
  256. }
  257. }
  258. if (!condition) {
  259. return "https://" + item;
  260. }
  261. return item;
  262. },
  263. slideto(action) {
  264. this.swiper[action]();
  265. },
  266. },
  267. mounted() {
  268. this.getData();
  269. document.addEventListener(
  270. "WeixinJSBridgeReady",
  271. () => {
  272. this.autoplay();
  273. },
  274. false
  275. );
  276. },
  277. };
  278. </script>
  279. <style lang="less" scoped>
  280. .viewerCla img {
  281. display: none;
  282. }
  283. .audio {
  284. position: fixed;
  285. top: -100px;
  286. left: -100px;
  287. opacity: 0;
  288. }
  289. .mb-intro {
  290. color: #fff;
  291. padding: 10px;
  292. height: calc(100% - 30px);
  293. overflow-y: auto;
  294. >p {
  295. line-height: 1.5;
  296. letter-spacing: 1px;
  297. &:first-of-type {
  298. font-weight: bold;
  299. font-size: 20px;
  300. padding-right: 40px;
  301. }
  302. }
  303. }
  304. .home {
  305. background-color: rgba(0, 0, 0, 0.6);
  306. width: 100%;
  307. height: 100%;
  308. position: relative;
  309. .content {
  310. width: 100%;
  311. height: 80%;
  312. .warpper {
  313. width: 100%;
  314. height: 100%;
  315. .slide {
  316. font-size: 0;
  317. img,
  318. video,
  319. iframe {
  320. max-height: 570px;
  321. border-radius: 14px;
  322. }
  323. iframe {
  324. height: 570px;
  325. width: 1000px;
  326. }
  327. }
  328. }
  329. }
  330. .isMobileCon {
  331. height: calc(100vh - 90px);
  332. }
  333. .iconarr {
  334. z-index: 1999;
  335. position: absolute;
  336. right: 30px;
  337. bottom: calc(20vh - 20px);
  338. list-style: none;
  339. display: flex;
  340. justify-content: flex-end;
  341. li {
  342. display: flex;
  343. align-items: center;
  344. justify-content: center;
  345. color: #fff;
  346. list-style: none;
  347. font-size: 14px;
  348. width: 90px;
  349. height: 32px;
  350. line-height: 32px;
  351. cursor: pointer;
  352. border-radius: 10px;
  353. border: solid 1px #fff;
  354. margin-right: 10px;
  355. span {
  356. margin-left: 4px;
  357. }
  358. }
  359. .active {
  360. background: #19bbed;
  361. border: none;
  362. }
  363. }
  364. .oneChuMusic {
  365. opacity: 0;
  366. pointer-events: none;
  367. }
  368. .onlyTxt {
  369. display: none !important;
  370. }
  371. .intro {
  372. max-height: 19vh;
  373. overflow: auto;
  374. width: 70%;
  375. color: #fff;
  376. margin: 0 auto;
  377. >h3 {
  378. font-size: 20px;
  379. font-weight: 600;
  380. }
  381. >p {
  382. line-height: 1.5;
  383. margin-top: 10px;
  384. font-size: 16px;
  385. text-indent: 32px;
  386. }
  387. &::-webkit-scrollbar {
  388. /*滚动条整体样式*/
  389. width: 3px;
  390. /*高宽分别对应横竖滚动条的尺寸*/
  391. height: 1px;
  392. }
  393. &::-webkit-scrollbar-thumb {
  394. /*滚动条里面小方块*/
  395. border-radius: 10px;
  396. -webkit-box-shadow: inset 0 0 5px transparent;
  397. background: #fff;
  398. }
  399. &::-webkit-scrollbar-track {
  400. /*滚动条里面轨道*/
  401. -webkit-box-shadow: inset 0 0 5px transparent;
  402. border-radius: 10px;
  403. background: transparent;
  404. }
  405. }
  406. .ismtop {
  407. max-height: 65%;
  408. height: 65%;
  409. padding: 50px 0;
  410. display: flex;
  411. flex-direction: column;
  412. justify-content: center;
  413. }
  414. }
  415. @media screen and (max-width: 1400px) {
  416. .home {
  417. overflow-y: auto;
  418. overflow-x: hidden;
  419. .content {
  420. .warpper {
  421. .slide {
  422. img,
  423. video,
  424. iframe {
  425. max-height: 500px;
  426. }
  427. img {
  428. max-height: 80vh;
  429. width: 90%;
  430. }
  431. iframe {
  432. height: 500px;
  433. }
  434. }
  435. }
  436. }
  437. }
  438. }
  439. @media screen and (max-width: 1000px) {
  440. .home {
  441. background: rgba(0, 0, 0, 0.8);
  442. .content {
  443. .warpper {
  444. .slide {
  445. width: 100%;
  446. img,
  447. video,
  448. iframe {
  449. max-height: none;
  450. width: 100%;
  451. border-radius: 0;
  452. }
  453. img {
  454. max-height: 80vh;
  455. width: 90%;
  456. }
  457. iframe {
  458. width: 100%;
  459. height: calc(100vh - 90px);
  460. }
  461. }
  462. }
  463. }
  464. .iconarr {
  465. display: flex;
  466. flex-wrap: wrap;
  467. list-style: none;
  468. margin-right: 0px;
  469. position: fixed;
  470. bottom: 0px;
  471. right: 0px;
  472. z-index: 1999;
  473. li {
  474. width: 70px;
  475. margin-bottom: 10px;
  476. }
  477. }
  478. }
  479. }
  480. @media only screen and (max-width: 906px) and (orientation: landscape) {
  481. .home {
  482. .content {
  483. .warpper {
  484. .slide {
  485. width: 100%;
  486. img,
  487. video,
  488. iframe {
  489. max-width: 70%;
  490. max-height: 80vh;
  491. }
  492. iframe {
  493. width: 100%;
  494. max-width: unset;
  495. height: calc(100vh - 90px);
  496. }
  497. }
  498. }
  499. }
  500. }
  501. }
  502. </style>
  503. <style>
  504. .swiper-container {
  505. width: 100%;
  506. height: 100%;
  507. }
  508. .swiper-pagination-bullet {
  509. background: #fff;
  510. }
  511. .swiper-slide {
  512. text-align: center;
  513. font-size: 18px;
  514. display: flex;
  515. justify-content: center;
  516. align-items: center;
  517. transition: 300ms;
  518. transform: scale(0.8);
  519. position: relative;
  520. opacity: 0.5;
  521. }
  522. .swiper-slide-active,
  523. .swiper-slide-duplicate-active {
  524. transform: scale(1);
  525. opacity: 1;
  526. z-index: 999;
  527. }
  528. .swiper-button-prev,
  529. .swiper-button-next {
  530. background: rgba(0, 0, 0, 0.4);
  531. padding: 10px 20px;
  532. color: #fff !important;
  533. }
  534. .swiper-button-prev {
  535. left: 0;
  536. }
  537. .swiper-button-next {
  538. right: 0;
  539. }
  540. @media screen and (max-width: 500px) {
  541. .swiper-slide {
  542. width: 100%;
  543. }
  544. }
  545. </style>