Home.vue 12 KB

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