Home.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <template>
  2. <div
  3. class="home"
  4. @click="autoplay"
  5. @touchstart="autoplay"
  6. v-if="data.content"
  7. >
  8. <audio
  9. v-if="audio"
  10. class="audio"
  11. id="audio1"
  12. :src="audio"
  13. preload
  14. autoplay
  15. loop
  16. ref="musicBg"
  17. ></audio>
  18. <div
  19. class="content"
  20. v-if="fixIcon.length > 0"
  21. :style="{ height: isMobile ? '90%' : '70%' }"
  22. >
  23. <div
  24. v-if="!isMobile"
  25. @click="slideto('slidePrev')"
  26. class="swiper-button-prev"
  27. ></div>
  28. <div class="mb-intro" v-show="active === 'title' && isMobile">
  29. <p v-html="data.title[myInd]"></p>
  30. <p v-html="data.content[myInd]"></p>
  31. </div>
  32. <swiper
  33. v-show="active !== 'title'"
  34. class="warpper"
  35. ref="mySwiper"
  36. :options="swiperOptions"
  37. >
  38. <swiper-slide v-for="i in data[active]" :key="i">
  39. <div class="slide">
  40. <img
  41. style="cursor: pointer"
  42. v-viewer
  43. v-if="active === 'images'"
  44. v-lazy="imgSrc(i)"
  45. alt=""
  46. />
  47. <video
  48. v-else-if="active === 'video'"
  49. :src="fixUrl(i.url)"
  50. controls
  51. autoplay
  52. ></video>
  53. <iframe
  54. @click="colseParent(i)"
  55. v-else-if="active === 'model' || active === 'iframe'"
  56. :src="fixUrl(i)"
  57. frameborder="0"
  58. ></iframe>
  59. </div>
  60. </swiper-slide>
  61. <div class="swiper-pagination" slot="pagination"></div>
  62. </swiper>
  63. <div
  64. v-if="!isMobile"
  65. @click="slideto('slideNext')"
  66. class="swiper-button-next"
  67. ></div>
  68. </div>
  69. <ul class="iconarr" v-if="fixIcon.length > 1">
  70. <li
  71. :class="{ active: item.id === active }"
  72. @click="active = item.id"
  73. v-for="(item, i) in fixIcon"
  74. :key="i"
  75. >
  76. <img :src="require(`@/assets/images/${item.img}.png`)" alt="" />
  77. <span>{{ item.name }}</span>
  78. </li>
  79. </ul>
  80. <div
  81. class="intro"
  82. :class="{ ismtop: fixIcon.length <= 0 }"
  83. v-if="!isMobile || (isMobile && fixIcon.length <= 0)"
  84. >
  85. <h3 v-html="data.title[myInd]"></h3>
  86. <p v-html="data.content[myInd]"></p>
  87. </div>
  88. </div>
  89. <!-- <h3></h3> -->
  90. </template>
  91. <script>
  92. import { obj } from "./data";
  93. import { Swiper, SwiperSlide } from "vue-awesome-swiper";
  94. import "swiper/css/swiper.css";
  95. import browser from "@/utils/browser";
  96. let iconArr = [
  97. { name: "图片", id: "images", img: "img-icon", display: false },
  98. { name: "视频", id: "video", img: "video-icon", display: false },
  99. { name: "网页", id: "iframe", img: "iframe-icon", display: false },
  100. { name: "模型", id: "model", img: "model-icon", display: false },
  101. ];
  102. browser.mobile &&
  103. iconArr.push({ name: "介绍", id: "title", img: "txt-icon", display: false });
  104. export default {
  105. name: "Home",
  106. data() {
  107. return {
  108. myInd: 0,
  109. // 为定制化加的索引
  110. loadAuto: false,
  111. audio: "",
  112. m: this.$route.query.m,
  113. id: this.$route.query.id,
  114. isMobile: browser.mobile,
  115. isAndriod: browser.android,
  116. swiperOptions: browser.mobile
  117. ? {
  118. pagination: {
  119. el: ".swiper-pagination",
  120. clickable: true,
  121. },
  122. on: {
  123. slideChangeTransitionEnd: () => {
  124. let swiper = this.$refs.mySwiper.$swiper;
  125. let activeIndex = swiper.activeIndex;
  126. this.myInd = activeIndex;
  127. },
  128. },
  129. }
  130. : {
  131. slidesPerView: 3,
  132. spaceBetween: 0,
  133. centeredSlides: true,
  134. pagination: {
  135. el: ".swiper-pagination",
  136. clickable: true,
  137. },
  138. on: {
  139. slideChangeTransitionEnd: () => {
  140. let swiper = this.$refs.mySwiper.$swiper;
  141. let activeIndex = swiper.activeIndex;
  142. this.myInd = activeIndex;
  143. },
  144. },
  145. },
  146. data: {},
  147. iconArr,
  148. active: "",
  149. };
  150. },
  151. watch: {
  152. active(newVal) {
  153. if (!newVal) {
  154. return;
  155. }
  156. if (!this.$refs.musicBg) {
  157. return;
  158. }
  159. setTimeout(() => {
  160. if (newVal == "video") {
  161. if (!this.$refs.musicBg.paused) {
  162. this.$refs.musicBg.pause();
  163. }
  164. } else {
  165. if (this.$refs.musicBg.paused) {
  166. this.$refs.musicBg.play(); // 暂停
  167. }
  168. }
  169. }, 500);
  170. },
  171. },
  172. computed: {
  173. swiper() {
  174. return this.$refs.mySwiper.$swiper;
  175. },
  176. fixIcon() {
  177. let arr = this.iconArr.filter((item) => !!item.display);
  178. return arr;
  179. },
  180. },
  181. components: {
  182. Swiper,
  183. SwiperSlide,
  184. },
  185. methods: {
  186. imgSrc(val) {
  187. if (typeof val === "number") return `/data/${this.m}/img/${val}.png`;
  188. else return val;
  189. },
  190. // 追加的图片地址过滤
  191. autoplay() {
  192. if (this.loadAuto) {
  193. return;
  194. }
  195. try {
  196. this.$refs.musicBg.play();
  197. this.loadAuto = true;
  198. } catch (error) {
  199. error;
  200. }
  201. },
  202. async getData() {
  203. // https://www.4dmodel.com/
  204. let url = `https://super.4dage.com/data/${
  205. this.id
  206. }/hot/js/data.js?time=${Math.random()}`;
  207. let result = (await this.$http.get(url)).data;
  208. let temp = result[this.m];
  209. obj.forEach((v) => {
  210. if (v.id === this.m) {
  211. temp = v;
  212. } else {
  213. temp.title = [temp.title];
  214. temp.content = [temp.content];
  215. }
  216. });
  217. //
  218. //
  219. this.data = temp;
  220. if (!this.data) {
  221. return alert("热点解析错误");
  222. }
  223. this.audio = this.data["backgroundMusic"];
  224. if (!this.data.content && this.isMobile) {
  225. this.iconArr.pop();
  226. }
  227. this.iconArr.forEach((item) => {
  228. if (this.data[item.id]) {
  229. this.active = !this.active ? item.id : this.active;
  230. item.display = true;
  231. }
  232. });
  233. },
  234. colseParent(item) {
  235. if (this.isMobile) {
  236. if (
  237. item.indexOf("mp.weixin.qq.com/mp/") > -1 &&
  238. this.active === "iframe"
  239. ) {
  240. window.parent.document.getElementById("closepop").click();
  241. }
  242. }
  243. },
  244. fixUrl(item) {
  245. let condition =
  246. item.indexOf("http://") > -1 || item.indexOf("https://") > -1;
  247. if (this.isMobile) {
  248. if (
  249. item.indexOf("mp.weixin.qq.com/mp/") > -1 &&
  250. this.active === "iframe"
  251. ) {
  252. return `https://www.4dmodel.com/SuperTwo/hot_online1/linktoWC.html?url=${encodeURIComponent(
  253. item
  254. )}`;
  255. }
  256. }
  257. if (!condition) {
  258. return "https://" + item;
  259. }
  260. return item;
  261. },
  262. slideto(action) {
  263. this.swiper[action]();
  264. },
  265. },
  266. mounted() {
  267. this.getData();
  268. document.addEventListener(
  269. "WeixinJSBridgeReady",
  270. () => {
  271. this.autoplay();
  272. },
  273. false
  274. );
  275. },
  276. };
  277. </script>
  278. <style lang="less" scoped>
  279. .home {
  280. background-color: rgba(0, 0, 0, 0.8);
  281. }
  282. .audio {
  283. position: fixed;
  284. top: -100px;
  285. left: -100px;
  286. opacity: 0;
  287. }
  288. .mb-intro {
  289. height: 90vh;
  290. overflow-y: auto;
  291. color: #fff;
  292. padding: 10px;
  293. > p {
  294. line-height: 1.5;
  295. letter-spacing: 1px;
  296. &:first-of-type {
  297. font-weight: bold;
  298. font-size: 20px;
  299. }
  300. }
  301. }
  302. .home {
  303. width: 100%;
  304. height: 100%;
  305. position: relative;
  306. .ismtop {
  307. padding-top: 40px !important;
  308. }
  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. .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. max-height: 30vh;
  360. overflow: auto;
  361. width: 70%;
  362. color: #fff;
  363. margin: 0 auto;
  364. /deep/ h3 {
  365. font-size: 20px;
  366. font-weight: 600;
  367. margin-bottom: 10px;
  368. }
  369. > p {
  370. line-height: 1.5;
  371. font-size: 16px;
  372. }
  373. }
  374. }
  375. @media screen and (max-width: 1400px) {
  376. .home {
  377. overflow-y: auto;
  378. overflow-x: hidden;
  379. .content {
  380. .warpper {
  381. .slide {
  382. img,
  383. video,
  384. iframe {
  385. max-height: 500px;
  386. }
  387. img {
  388. max-height: 80vh;
  389. width: 90%;
  390. }
  391. iframe {
  392. height: 500px;
  393. }
  394. }
  395. }
  396. }
  397. }
  398. }
  399. @media screen and (max-width: 1000px) {
  400. .home {
  401. background: rgba(0, 0, 0, 0.8);
  402. .content {
  403. .warpper {
  404. .slide {
  405. width: 100%;
  406. img,
  407. video,
  408. iframe {
  409. max-height: none;
  410. width: 100%;
  411. border-radius: 0;
  412. }
  413. img {
  414. max-height: 80vh;
  415. width: 90%;
  416. }
  417. iframe {
  418. width: 100%;
  419. height: 100vh;
  420. }
  421. }
  422. }
  423. }
  424. .iconarr {
  425. list-style: none;
  426. margin-right: 0px;
  427. position: fixed;
  428. bottom: 10px;
  429. right: 0px;
  430. z-index: 10000;
  431. li {
  432. width: 70px;
  433. }
  434. }
  435. }
  436. }
  437. @media only screen and (max-width: 906px) and (orientation: landscape) {
  438. .home {
  439. .content {
  440. .warpper {
  441. .slide {
  442. width: 100%;
  443. img,
  444. video,
  445. iframe {
  446. max-width: 70%;
  447. max-height: 80vh;
  448. }
  449. iframe {
  450. width: 100%;
  451. max-width: unset;
  452. height: 100vh;
  453. }
  454. }
  455. }
  456. }
  457. }
  458. }
  459. </style>
  460. <style>
  461. .swiper-container {
  462. width: 100%;
  463. height: 100%;
  464. }
  465. .swiper-pagination-bullet {
  466. background: #fff;
  467. }
  468. .swiper-slide {
  469. text-align: center;
  470. font-size: 18px;
  471. display: flex;
  472. justify-content: center;
  473. align-items: center;
  474. transition: 300ms;
  475. transform: scale(0.8);
  476. position: relative;
  477. opacity: 0.5;
  478. }
  479. .swiper-slide-active,
  480. .swiper-slide-duplicate-active {
  481. transform: scale(1);
  482. opacity: 1;
  483. z-index: 999;
  484. }
  485. .swiper-button-prev,
  486. .swiper-button-next {
  487. background: rgba(0, 0, 0, 0.4);
  488. padding: 10px 20px;
  489. color: #fff !important;
  490. }
  491. .swiper-button-prev {
  492. left: 0;
  493. }
  494. .swiper-button-next {
  495. right: 0;
  496. }
  497. .slide img {
  498. image-rendering: -webkit-optimize-contrast;
  499. }
  500. @media screen and (max-width: 500px) {
  501. .swiper-slide {
  502. width: 100%;
  503. }
  504. }
  505. </style>