Home.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <div class="Home">
  3. <!-- 标题 -->
  4. <div class="title">{{ myTitle || "热点" }}</div>
  5. <!-- 主体带滚动条的盒子 -->
  6. <div class="main">
  7. <!-- 图片 -->
  8. <div class="imgBox" :class="{ imgBoxOne: !myTxt }">
  9. <Swiper class="warpper" ref="mySwiper" :options="swiperOptions">
  10. <SwiperSlide v-for="item in myImgArr" :key="item">
  11. <!-- 线上数据 -->
  12. <img :src="item" alt="" @click="lookImg(item)" />
  13. <!-- 本地化部署 -->
  14. <!-- <img
  15. :src="item.replace('https://super.4dage.com', '')"
  16. alt=""
  17. @click="lookImg(item.replace('https://super.4dage.com', ''))"
  18. /> -->
  19. </SwiperSlide>
  20. </Swiper>
  21. <!-- 索引 -->
  22. <div class="myIndBox" v-if="myImgArr.length">
  23. {{ myInd + 1 }} / <span>{{ myImgArr.length }}</span>
  24. </div>
  25. </div>
  26. <!-- 介绍 -->
  27. <div class="txtBox" v-if="myTxt" v-html="myTxt || '暂无内容'"></div>
  28. </div>
  29. <!-- 查看图片 -->
  30. <viewer class="viewerCla" ref="viewer" :images="lookPics">
  31. <img :src="lookPics[0]" alt="" />
  32. </viewer>
  33. </div>
  34. </template>
  35. <script>
  36. import { Swiper, SwiperSlide } from "vue-awesome-swiper";
  37. import "swiper/css/swiper.css";
  38. export default {
  39. components: { Swiper, SwiperSlide },
  40. data() {
  41. return {
  42. m: this.$route.query.m,
  43. id: this.$route.query.id,
  44. // 标题
  45. myTitle: "",
  46. // 图片数组
  47. myImgArr: [],
  48. // 简介
  49. myTxt: "",
  50. // 图片索引
  51. myInd: 0,
  52. // 轮播图设置
  53. swiperOptions: {
  54. slidesPerView: 1,
  55. spaceBetween: 0,
  56. centeredSlides: true,
  57. on: {
  58. slideChangeTransitionEnd: () => {
  59. let swiper = this.$refs.mySwiper.$swiper;
  60. let activeIndex = swiper.activeIndex;
  61. this.myInd = activeIndex;
  62. },
  63. },
  64. },
  65. // 查看图片
  66. lookPics: [],
  67. };
  68. },
  69. computed: {},
  70. watch: {},
  71. methods: {
  72. // 点击查看大图
  73. lookImg(url) {
  74. let dom = this.$refs.viewer.$viewer;
  75. this.lookPics = [url];
  76. dom.show();
  77. },
  78. async getData() {
  79. // https://www.4dmodel.com/
  80. //线上数据
  81. let url = `https://super.4dage.com/data/${
  82. // let url = `/data/${
  83. //本地化部署
  84. this.id
  85. }/hot/js/data.js?time=${Math.random()}`;
  86. let result = (await this.$http.get(url)).data;
  87. const resData = result[this.m];
  88. if (!resData) return alert("热点解析错误");
  89. this.myTitle = resData.title;
  90. this.myImgArr = resData.images || [];
  91. this.myTxt = resData.content;
  92. },
  93. },
  94. created() {},
  95. mounted() {
  96. this.getData();
  97. },
  98. beforeCreate() {}, //生命周期 - 创建之前
  99. beforeMount() {}, //生命周期 - 挂载之前
  100. beforeUpdate() {}, //生命周期 - 更新之前
  101. updated() {}, //生命周期 - 更新之后
  102. beforeDestroy() {}, //生命周期 - 销毁之前
  103. destroyed() {}, //生命周期 - 销毁完成
  104. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  105. };
  106. </script>
  107. <style lang='less' scoped>
  108. .Home {
  109. width: 100%;
  110. height: 100%;
  111. background-color: black;
  112. color: #fff;
  113. .viewerCla img {
  114. display: none;
  115. }
  116. .title {
  117. height: 50px;
  118. line-height: 49px;
  119. padding: 0 50px 0 10px;
  120. border-bottom: 1px solid #ccc;
  121. }
  122. .main {
  123. height: calc(100% - 50px);
  124. width: 100%;
  125. overflow-y: auto;
  126. .imgBox {
  127. height: 80vh;
  128. position: relative;
  129. .warpper {
  130. width: 100%;
  131. height: 100%;
  132. .swiper-wrapper {
  133. img {
  134. width: 100%;
  135. height: 100%;
  136. object-fit: contain;
  137. }
  138. }
  139. }
  140. .myIndBox {
  141. z-index: 9;
  142. pointer-events: none;
  143. font-size: 12px;
  144. position: absolute;
  145. bottom: 20px;
  146. left: 50%;
  147. transform: translateX(-50%);
  148. background: rgba(0, 0, 0, 0.4);
  149. border: 1px solid #ccc;
  150. border-radius: 15px;
  151. padding: 6px 10px;
  152. & > span {
  153. opacity: 0.6;
  154. }
  155. }
  156. }
  157. .imgBoxOne {
  158. height: 100%;
  159. }
  160. .txtBox {
  161. padding: 40px 15px;
  162. font-size: 14px;
  163. line-height: 20px;
  164. color: black;
  165. background-color: #fff;
  166. border-radius: 8px 8px 0 0;
  167. min-height: 80vh;
  168. position: relative;
  169. &::before {
  170. content: "";
  171. width: 35px;
  172. height: 4px;
  173. background: #444;
  174. border-radius: 13px 13px 13px 13px;
  175. opacity: 1;
  176. position: absolute;
  177. top: 14px;
  178. left: 50%;
  179. transform: translateX(-50%);
  180. }
  181. }
  182. }
  183. }
  184. @media screen and (min-width: 1200px) {
  185. .Home {
  186. .main {
  187. &::-webkit-scrollbar {
  188. /*滚动条整体样式*/
  189. width: 3px; /*高宽分别对应横竖滚动条的尺寸*/
  190. height: 1px;
  191. }
  192. &::-webkit-scrollbar-thumb {
  193. /*滚动条里面小方块*/
  194. border-radius: 10px;
  195. -webkit-box-shadow: inset 0 0 5px transparent;
  196. background: #ccc;
  197. }
  198. &::-webkit-scrollbar-track {
  199. /*滚动条里面轨道*/
  200. -webkit-box-shadow: inset 0 0 5px transparent;
  201. border-radius: 10px;
  202. background: transparent;
  203. }
  204. .imgBox {
  205. .warpper {
  206. .swiper-wrapper {
  207. img {
  208. cursor: pointer;
  209. }
  210. }
  211. }
  212. }
  213. }
  214. // 本地化
  215. .title {
  216. height: 70px;
  217. line-height: 70px;
  218. font-size: 22px;
  219. }
  220. .main {
  221. height: calc(100% - 70px);
  222. .imgBox {
  223. height: 72vh;
  224. }
  225. .txtBox {
  226. padding: 30px 20px 40px;
  227. min-height: 72vh;
  228. font-size: 18px;
  229. line-height: 24px;
  230. letter-spacing: 4px;
  231. }
  232. }
  233. }
  234. }
  235. </style>