You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

236 lines
7.0 KiB

7 months ago
  1. <template>
  2. <view class="class123">
  3. <view class="container" style="width: 100%;">
  4. <view class="title"><b>推荐</b></view>
  5. <ul class="data-list">
  6. <li class="data-list-li articleList" v-for="(group, index) in chunk(articleData, 2)" :key="index">
  7. <view class="article-row">
  8. <view class="articleimage" v-for="(article, subIndex) in group" :key="subIndex">
  9. <view class="el-image">
  10. <img :src="article.cover" alt="文章图片"></img>
  11. <text class="play-icon"></text>
  12. <text class="corner-mark">{{ article.cornerMark }}</text>
  13. </view>
  14. <view class="articleinfo">
  15. <text class="articletitle">{{ article.name }}</text><br>
  16. <text class="avatarName">
  17. {{ article.user.username }}
  18. </text>
  19. </view>
  20. </view>
  21. </view>
  22. </li>
  23. </ul>
  24. </view>
  25. </view>
  26. <!-- <div class="sidebar-right" style="width: 400px; float: right;">
  27. <div>
  28. <img
  29. src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAHJSURBVFiF1ZhRkoMgDIb/OD1CPc/SWe5Vey86i+dx75B9KHHEWsEItvu/tFYGviaQkBCUGqw1AECM6+RnEz49ADChB4DWuU67DinAOmJ8TWBy5ZnQb4XNBgxg1/TItJhwywVNAg7WGmL87KZaUA5os/YyWK0KHPDYv4O13eqYVy9KujSlNUsuAh4JJ3oF+QT4DjjREmQE+E44ERMurXNenqND8m64wBAdyhEwdZqO1JRlBNRYjwk3hLRWUlOWBtBZTzb0+e4uAbSohKkBgJBbt8rLlwBKJUGFSVxsSkxaGNQM1pqmxuFonetKWXM1F+9RCWsS49oo91+29oJWs+Bcwe2bTzz9flvWLDhPSVu0Zc3DLKjVCY94Zo5YLNzOt2Qsf6pGM5P2plQdcART7HQm9Ccm3IjLu3h05865i1uwFBjwCE1NCBV+72RAVAWaAtN5IFiQCf0eN4+1syqiLkvaJmNNogjYPvwxTRskqfPdETAJ1IpcKTHNFOR6YomqOm3aKy2xHjBLdUy4HI8Ta+7JCLB1zteoL3KVLNxFH936EH1080h0BGSqR5jTwKwGmXPp/f8t4Lk+tom+JKmpJ5WhERgZI2FLW7/8AexhA1wjeFcZAAAAAElFTkSuQmCC"
  30. alt style="width: 20px; height: 20px; margin-right: 5px; vertical-align: middle;">精选视频
  31. </div>
  32. <ul class="data-list" >
  33. <li class="data-list-li articleList" v-for="(article, index) in articleData" :key="index">
  34. <div class="articleimg">
  35. <div class="el-image articleimg-img" >
  36. <img :src="article.cover" alt="文章图片">
  37. <span class="play-time">{{ article.videoDuration }}</span>
  38. </div>
  39. </div>
  40. <div class="articleinfo">
  41. <h5>{{ article.name }}</h5>
  42. <span class="homepage-list-li-see">
  43. <img :src="seeSrc" alt="浏览量图标">
  44. {{ article.viewCount }}
  45. </span>
  46. <span class="articleinfo-time">{{ article.releaseTime }}</span>
  47. </div>
  48. </li>
  49. </ul>
  50. </div> -->
  51. <!-- <view class="class123">
  52. <view class="container" style="width: 100%;">
  53. <view class="title"><b>推荐</b></view>
  54. <ul class="data-list">
  55. <li class="data-list-li articleList" v-for="(group, index) in chunk(articleData.value, 2)" :key="index">
  56. <view class="article-row flex-row">
  57. <view class="articleimage" v-for="(article, subIndex) in group" :key="subIndex" style="width: 48%; margin-right: 2%;" v-if="subIndex < 2">
  58. <view class="el-image">
  59. <img :src="article.cover" alt="文章图片"></img>
  60. <text class="play-icon"></text>
  61. <text class="corner-mark">{{ article.cornerMark }}</text>
  62. </view>
  63. <view class="articleinfo">
  64. <text class="articletitle">{{ article.name }}</text><br>
  65. <text class="avatarName">
  66. {{ article.user.username }}
  67. </text>
  68. </view>
  69. </view>
  70. <view class="articleimage" v-for="(article, subIndex) in group" :key="subIndex" style="width: 100%; margin-top: 10px;" v-if="subIndex === 2">
  71. <view class="el-image">
  72. <img :src="article.cover" alt="文章图片"></img>
  73. <text class="play-icon"></text>
  74. <text class="corner-mark">{{ article.cornerMark }}</text>
  75. </view>
  76. <view class="articleinfo">
  77. <text class="articletitle">{{ article.name }}</text><br>
  78. <text class="avatarName">
  79. {{ article.user.username }}
  80. </text>
  81. </view>
  82. </view>
  83. </view>
  84. </li>
  85. </ul>
  86. </view>
  87. </view> -->
  88. </template>
  89. <script setup>
  90. import { ref, onMounted, reactive,computed } from 'vue';
  91. import homeApi from '@/api/HomeApi';
  92. const articleData = ref([]);
  93. function fetchData (){
  94. homeApi.gethomeList().then(response => {
  95. // 将articleData响应式对象赋值给articleData
  96. articleData.value = response.data;
  97. console.log('初始化后的articleData:', articleData.value);
  98. }).catch(error => {
  99. console.error('获取数据出错:', error);
  100. });
  101. };
  102. fetchData ();
  103. function chunk(arr, size = 2) {
  104. if (!arr) {
  105. return [];
  106. }
  107. const result = [];
  108. for (let i = 0; i < arr.length; ) {
  109. const subArr = [];
  110. for (let j = 0; j < size && i < arr.length; j++) {
  111. subArr.push(arr[i++]);
  112. }
  113. result.push(subArr);
  114. }
  115. return result;
  116. }
  117. </script>
  118. <style lang="scss">
  119. .class123 {
  120. background-color: #f1f1f1;
  121. }
  122. .play-icon {
  123. width: 0;
  124. height: 0;
  125. border-style: solid;
  126. border-width: 10px 0 10px 16px;
  127. border-color: transparent transparent transparent rgba(255, 255, 255, 1);
  128. position: absolute;
  129. top: 35%;
  130. left: 50%;
  131. transform: translate(-50%, -50%);
  132. }
  133. .daohang {
  134. height: 32px;
  135. }
  136. .container {
  137. margin-right: 0;
  138. margin-left: auto;
  139. }
  140. body {
  141. font-family: Arial, sans-serif;
  142. }
  143. .title {
  144. margin-left: 7px;
  145. font-size: 18px;
  146. color: #000000;
  147. padding: 10px 0;
  148. }
  149. .data-list {
  150. list-style: none;
  151. padding: 0 10px;
  152. }
  153. .data-list-li {
  154. display: flex;
  155. align-items: flex-start;
  156. padding: 5px 0;
  157. }
  158. .article-row {
  159. display: flex;
  160. justify-content: space-between;
  161. }
  162. .articleimage {
  163. position: relative;
  164. width: 50%;
  165. height: 50%;
  166. margin-right: 10px;
  167. border-radius: 5px;
  168. overflow: hidden;
  169. }
  170. .el-image img {
  171. width: 100%;
  172. height: 100px;
  173. object-fit: cover;
  174. // transform: scale();
  175. }
  176. .articleinfo {
  177. position: relative;
  178. // bottom: 0;
  179. // left: 0;4
  180. width: 100%;
  181. background-color: rgba(255, 255, 255, 1);
  182. color: white;
  183. padding: 5px;
  184. text-align: center;
  185. margin-top: 0;
  186. text-align: left;
  187. }
  188. .articletitle {
  189. padding: 0;
  190. font-size: 14px;
  191. color: #000000;
  192. }
  193. .avatarName {
  194. margin-left: 0;
  195. display: inline-block;
  196. font-size: 12px;
  197. color: gray;
  198. }
  199. .class123 {
  200. display: flex;
  201. }
  202. .corner-mark {
  203. position: absolute;
  204. top: 0;
  205. left: 0;
  206. background-color: red;
  207. color: white;
  208. padding: 2px 5px;
  209. border-radius: 2px;
  210. font-size: 12px;
  211. }
  212. </style>