Home.vue 7.0 KB

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