Home.vue 13 KB

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