Home.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <template>
  2. <div class="home">
  3. <div class="main">
  4. <div class="myTitle">{{ myTitle }}</div>
  5. <div class="mainCon" v-show="!oneTxt">
  6. <audio id="myAudio" v-if="audio" v-show="isOneAduio" :src="urlToFitFu(audio)" controls></audio>
  7. <!-- 如果只有一个模块 -->
  8. <!-- <div class="oneTabNum" v-if="
  9. flooTab.length === 1 &&
  10. data[myType] &&
  11. data[myType].length &&
  12. data[myType].length > 1
  13. ">
  14. {{ myInd + 1 }} / {{ data[myType].length }}
  15. </div> -->
  16. <!-- 主要内容 -->
  17. <div class="contenBoxMain swiper-container">
  18. <div class="swiper-wrapper">
  19. <div class="contenBox swiper-slide" v-for="(item, index) in data[myType]"
  20. :key="myType === 'video' ? item.url : item">
  21. <!-- 模型页面 -->
  22. <div class="modelBox" v-if="myType === 'model'">
  23. <iframe :src="urlToFitFu(item)" frameborder="0" v-if="index === myInd"></iframe>
  24. </div>
  25. <!-- 视频页面 -->
  26. <div class="videoBox" v-else-if="myType === 'video'">
  27. <video controls controlslist="nodownload" :src="urlToFitFu(item.url)" v-if="index === myInd"></video>
  28. </div>
  29. <!-- 图片页面 -->
  30. <div class="imgBox" v-else-if="myType === 'img'">
  31. <div class="smImgBox">
  32. <img v-lazy="urlToFitFu(item)" alt="" @click="lookImg(urlToFitFu(item))" />
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. <!-- 左右箭头 -->
  38. <template v-if="!isMobile">
  39. <div @click="cutMyInd(-1, myInd === 0)" class="leftJJ awccJJ" :class="{ noClick: myInd === 0 }"
  40. v-if="data[myType] && data[myType].length > 1"></div>
  41. <div @click="cutMyInd(1, myInd === data[myType].length - 1)" class="rightJJ awccJJ"
  42. :class="{ noClick: myInd === data[myType].length - 1 }" v-if="data[myType] && data[myType].length > 1">
  43. </div>
  44. </template>
  45. </div>
  46. </div>
  47. <div class="swiper-pagination" v-if="data[myType] && data[myType].length > 1"></div>
  48. <!-- 下面的文字介绍 -->
  49. <div class="flooTxt" :class="{ flooTxtOne: oneTxt }">
  50. <div class="flooTxtBox">
  51. <!-- <div class="myTitle">{{ myTitle }}</div> -->
  52. <!-- 视频的介绍 -->
  53. <div class="myTxt" v-if="myType === 'video' && videoTxt[myInd]" v-html="videoTxt[myInd]">
  54. </div>
  55. <div class="myTxt" v-if="myType === 'img' && imgTxt[myInd]" v-html="imgTxt[myInd]">
  56. </div>
  57. <div class="myTxt" v-html="myTxt"></div>
  58. </div>
  59. </div>
  60. </div>
  61. <!-- 查看图片 -->
  62. <viewer class="viewerCla" ref="viewer" :images="lookPics">
  63. <img :src="lookPics[0]" alt="" />
  64. </viewer>
  65. <!-- 底部的tab -->
  66. <div class="flooTabBox" v-if="flooTab.length > 1">
  67. <div @click="myType = item.type" class="tabRow" :class="{ tabRowAc: myType === item.type }"
  68. v-for="item in flooTab" :key="item.id">
  69. <img :src="require(`@/assets/images/pc/icon${item.id}${myType === item.type ? 'Ac' : ''
  70. }.png`)
  71. " alt="" />
  72. <div>
  73. {{ item.name }}
  74. <span v-if="
  75. data[item.type] &&
  76. data[item.type].length &&
  77. data[item.type].length > 1
  78. ">{{ item.type === myType ? myInd + 1 + "/" : null
  79. }}{{ data[item.type].length }}</span>
  80. </div>
  81. </div>
  82. <!-- 音频图标 -->
  83. <div class="tabRow" v-if="audio && !isOneAduio" @click="audioSta = !audioSta" :title="audioSta ? '关闭音频' : '打开音频'">
  84. <img :src="require(`@/assets/images/pc/audio${audioSta ? 'Ac' : ''}.png`)" alt="" />
  85. <div>音频</div>
  86. </div>
  87. </div>
  88. </div>
  89. </template>
  90. <script>
  91. import Swiper from "swiper"
  92. import "swiper/css/swiper.min.css"
  93. export default {
  94. name: "Home",
  95. components: {
  96. },
  97. data() {
  98. return {
  99. isMobile: /iPhone|iPad|iPod|Android/i.test(navigator.userAgent),
  100. m: this.$route.query.m,
  101. id: this.$route.query.id,
  102. // 音频地址
  103. audio: "",
  104. // 如果只有单独的音频
  105. isOneAduio: false,
  106. // 音频状态
  107. audioSta: false,
  108. data: {
  109. // 模型数组
  110. model: [],
  111. // 视频数组
  112. video: [],
  113. // 图片数组
  114. img: [],
  115. },
  116. // 当前 type
  117. myType: "",
  118. // 底部的tab
  119. flooTab: [],
  120. // 当前索引
  121. myInd: 0,
  122. // 查看图片
  123. lookPics: [],
  124. // 标题
  125. myTitle: "",
  126. // 内容
  127. myTxt: "",
  128. // 视频内容
  129. videoTxt: [],
  130. imgTxt: [],
  131. // 只有标题和文字(没有视频,没有模型,没有图片)
  132. oneTxt: false,
  133. }
  134. },
  135. watch: {
  136. myType() {
  137. this.myInd = 0
  138. },
  139. // 音频的开启和关闭
  140. audioSta(val) {
  141. const dom = document.querySelector("#myAudio")
  142. if (val) {
  143. dom.play()
  144. dom.onended = () => {
  145. // console.log("----音频播放完毕");
  146. this.audioSta = false
  147. }
  148. } else dom.pause()
  149. },
  150. },
  151. computed: {},
  152. methods: {
  153. // 本地化 url 适配
  154. urlToFitFu(url) {
  155. return url
  156. // const resUrl = url;
  157. // if (url.includes("https://super.4dage.com")) {
  158. // return url.replace("https://super.4dage.com", "");
  159. // } else if (url.includes("http://super.4dage.com")) {
  160. // return url.replace("http://super.4dage.com", "");
  161. // } else return resUrl;
  162. },
  163. // 点击左右箭头
  164. cutMyInd(num) {
  165. console.log(num, this.swiper)
  166. if (!this.swiper) return
  167. if (num > 0) {
  168. this.swiper.slideNext()
  169. } else {
  170. this.swiper.slidePrev()
  171. }
  172. },
  173. // 点击查看大图
  174. lookImg(url) {
  175. // console.log(url)
  176. let dom = this.$refs.viewer.$viewer
  177. this.lookPics = [url]
  178. // console.log(Object.keys(dom))
  179. dom.options.toolbar = false
  180. dom.show()
  181. },
  182. async getData() {
  183. // https://www.4dmodel.com/
  184. let url = `https://super.4dage.com/data/${
  185. // 线上数据
  186. // let url = `/data/${
  187. //本地化部署
  188. this.id
  189. }/hot/js/data.js?time=${Math.random()}`
  190. let result = (await this.$http.get(url)).data
  191. const resData = result[this.m]
  192. // console.log("----", resData);
  193. if (resData) {
  194. this.audio = resData.backgroundMusic
  195. // 只有单独的音频上传
  196. if (
  197. resData.backgroundMusic &&
  198. !resData.model &&
  199. !resData.video &&
  200. !resData.images
  201. ) {
  202. this.isOneAduio = true
  203. }
  204. // 底部的tab
  205. const arr = []
  206. const obj = {}
  207. if (resData.model) {
  208. obj.model = resData.model
  209. arr.push({ id: 1, type: "model", name: "模型" })
  210. }
  211. if (resData.video) {
  212. obj.video = resData.video
  213. arr.push({ id: 2, type: "video", name: "视频" })
  214. }
  215. if (resData.images) {
  216. obj.img = resData.images
  217. arr.push({ id: 3, type: "img", name: "图片" })
  218. }
  219. this.flooTab = arr
  220. this.data = obj
  221. // 当前type的值 应该为
  222. if (resData.model) this.myType = "model"
  223. else if (resData.video) this.myType = "video"
  224. else if (resData.images) this.myType = "img"
  225. this.myTitle = resData.title || ""
  226. this.myTxt = resData.content || ""
  227. this.videoTxt = resData.videosDesc || []
  228. this.imgTxt = resData.imagesDesc || []
  229. // 只有 标题和 文字介绍(没有视频,没有模型,没有图片)
  230. if (!obj.model && !obj.video && !obj.img && !resData.backgroundMusic) {
  231. this.oneTxt = true
  232. }
  233. this.$nextTick(() => {
  234. const _this = this
  235. this.swiper = new Swiper('.contenBoxMain', {
  236. on: {
  237. slideChange() {
  238. _this.myInd = this.activeIndex
  239. }
  240. },
  241. pagination: {
  242. el: '.swiper-pagination',
  243. }
  244. })
  245. })
  246. }
  247. },
  248. },
  249. mounted() {
  250. this.getData()
  251. },
  252. }
  253. </script>
  254. <style lang="less" scoped>
  255. .home {
  256. background: url("../assets/images/pc/hot_bg.png") no-repeat center center;
  257. background-color: rgba(transparent, 0.8);
  258. background-size: 100% 100%;
  259. border-radius: 10px;
  260. color: rgba(80, 61, 42, 0.9);
  261. .swiper-pagination {
  262. margin: 10px 0 0;
  263. position: relative;
  264. display: flex;
  265. align-items: center;
  266. justify-content: center;
  267. gap: 6px;
  268. width: 100%;
  269. :deep(.swiper-pagination-bullet) {
  270. width: 24px;
  271. height: 4px;
  272. border-radius: 2px;
  273. background: #66442c49;
  274. opacity: 1;
  275. &.swiper-pagination-bullet-active {
  276. background: #603C23;
  277. }
  278. }
  279. }
  280. .viewerCla img {
  281. display: none;
  282. }
  283. height: 100%;
  284. position: relative;
  285. #myAudio {
  286. z-index: 11;
  287. position: absolute;
  288. top: 50%;
  289. left: 50%;
  290. transform: translate(-50%, -50%);
  291. width: 500px;
  292. height: 60px;
  293. }
  294. .main {
  295. width: 100%;
  296. margin: 0 auto;
  297. height: 100%;
  298. padding: 30px 0 20px 0;
  299. display: flex;
  300. flex-direction: column;
  301. align-items: center;
  302. justify-content: center;
  303. .myTitle {
  304. font-size: 22px;
  305. font-weight: 700;
  306. margin-bottom: 20px;
  307. text-align: center;
  308. }
  309. .mainCon {
  310. position: relative;
  311. border-radius: 6px;
  312. overflow: hidden;
  313. width: 100%;
  314. height: calc(100% - 300px);
  315. .oneTabNum {
  316. z-index: 10;
  317. position: absolute;
  318. bottom: 0;
  319. left: 50%;
  320. transform: translateX(-50%);
  321. font-size: 14px;
  322. }
  323. .contenBoxMain {
  324. position: relative;
  325. width: 100%;
  326. height: 100%;
  327. }
  328. .contenBox {
  329. .modelBox,
  330. .videoBox,
  331. .imgBox {
  332. width: 100%;
  333. height: 100%;
  334. }
  335. .modelBox {
  336. iframe {
  337. width: 100%;
  338. height: 100%;
  339. }
  340. }
  341. .videoBox {
  342. padding: 0px 50px;
  343. video {
  344. width: 100%;
  345. height: 100%;
  346. }
  347. }
  348. .imgBox {
  349. padding: 0px 50px;
  350. .smImgBox {
  351. width: 100%;
  352. height: 100%;
  353. // cursor: zoom-in;
  354. & > img {
  355. width: 100%;
  356. height: 100%;
  357. object-fit: contain;
  358. }
  359. }
  360. }
  361. }
  362. .awccJJ {
  363. cursor: pointer;
  364. position: absolute;
  365. top: 50%;
  366. transform: translateY(-50%);
  367. left: 30px;
  368. width: 16px;
  369. height: 30px;
  370. background-image: url("../assets/images/pc/left.png");
  371. background-size: 100% 100%;
  372. z-index: 1;
  373. &:focus {
  374. outline: none;
  375. }
  376. }
  377. .rightJJ {
  378. left: auto;
  379. right: 30px;
  380. background-image: url("../assets/images/pc/right.png");
  381. }
  382. .noClick {
  383. cursor: default;
  384. opacity: 0.4;
  385. }
  386. }
  387. .flooTxt {
  388. margin: 0 auto;
  389. margin-top: 10px;
  390. width: 70%;
  391. height: 100%;
  392. max-height: 200px;
  393. .flooTxtBox {
  394. width: 100%;
  395. height: 100%;
  396. padding: 0 30px;
  397. overflow-y: auto;
  398. .myTxt {
  399. font-size: 16px;
  400. color: #333333;
  401. line-height: 24px;
  402. }
  403. &::-webkit-scrollbar {
  404. /*滚动条整体样式*/
  405. width: 3px;
  406. /*高宽分别对应横竖滚动条的尺寸*/
  407. height: 1px;
  408. }
  409. &::-webkit-scrollbar-thumb {
  410. /*滚动条里面小方块*/
  411. border-radius: 10px;
  412. -webkit-box-shadow: inset 0 0 5px transparent;
  413. background: rgb(192, 166, 126);
  414. }
  415. &::-webkit-scrollbar-track {
  416. /*滚动条里面轨道*/
  417. -webkit-box-shadow: inset 0 0 5px transparent;
  418. border-radius: 10px;
  419. background: transparent;
  420. }
  421. }
  422. }
  423. .flooTxtOne {
  424. height: 600px;
  425. }
  426. }
  427. // 底部
  428. .flooTabBox {
  429. z-index: 10;
  430. position: absolute;
  431. bottom: 20px;
  432. right: 20px;
  433. display: flex;
  434. .tabRow {
  435. width: 60px;
  436. cursor: pointer;
  437. display: flex;
  438. flex-direction: column;
  439. align-items: center;
  440. font-size: 12px;
  441. // background-color: #dedede;
  442. color: black;
  443. border-radius: 18px;
  444. & > img {
  445. width: 40px;
  446. display: inline-block;
  447. margin-bottom: 3px;
  448. }
  449. & > div {
  450. min-width: 40px;
  451. text-align: center;
  452. }
  453. }
  454. .tabRowAc {
  455. // background-color: #c8aa7d;
  456. pointer-events: none;
  457. // color: #c7aa7c;
  458. }
  459. }
  460. }
  461. // 移动端
  462. @media screen and (max-width: 1000px) {
  463. .home {
  464. background: url("../assets/images/pc/hot_bg_M.png") no-repeat center center;
  465. background-size: cover !important;
  466. .swiper-pagination {
  467. margin: 10px 0 0;
  468. gap: 4px;
  469. :deep(.swiper-pagination-bullet) {
  470. width: 15px;
  471. height: 3px;
  472. }
  473. }
  474. #myAudio {
  475. width: 90vw;
  476. max-width: 500px;
  477. }
  478. .main {
  479. width: 100%;
  480. height: 100%;
  481. padding: 0;
  482. position: absolute;
  483. .myTitle {
  484. font-size: 16px;
  485. margin: 8px 0;
  486. }
  487. .mainCon {
  488. border-radius: 0;
  489. height: calc(100% - 195px);
  490. .contenBox {
  491. .videoBox {
  492. padding: 0 30px;
  493. position: relative;
  494. video {
  495. width: calc(100% - 60px);
  496. max-height: 100%;
  497. height: auto;
  498. position: absolute;
  499. top: 50%;
  500. left: 50%;
  501. transform: translate(-50%, -50%);
  502. }
  503. }
  504. .imgBox {
  505. // padding: 60px 50px 80px;
  506. padding: 0 15px;
  507. .smImgBox {
  508. cursor: default;
  509. }
  510. }
  511. }
  512. .awccJJ {
  513. left: 0;
  514. width: 28px;
  515. height: 57px;
  516. cursor: default;
  517. background-image: url("../assets/images/pc/icon-left.png");
  518. }
  519. .rightJJ {
  520. left: auto;
  521. right: 0;
  522. background-image: url("../assets/images/pc/icon-right.png");
  523. }
  524. }
  525. .flooTxt {
  526. margin-top: -5px;
  527. width: 100%;
  528. padding: 10px 15px 0px 15px;
  529. max-height: 250px;
  530. .flooTxtBox {
  531. padding: 0;
  532. .myTxt {
  533. font-size: 14px;
  534. line-height: 22px;
  535. }
  536. }
  537. }
  538. .flooTxtOne {
  539. height: 100%;
  540. }
  541. }
  542. .flooTabBox {
  543. width: 100%;
  544. bottom: 220px;
  545. right: 0;
  546. justify-content: center;
  547. .tabRow {
  548. cursor: default;
  549. // margin: 0 6px;
  550. // padding: 0 10px;
  551. height: 32px;
  552. & > img {
  553. width: 30px;
  554. }
  555. }
  556. }
  557. }
  558. }
  559. </style>