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.

195 lines
3.9 KiB

5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 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. <view class="play-icon-container">
  12. <text class="play-icon" v-if="article.flagType===1"></text>
  13. <text class="play-icon-background" v-if="article.flagType===1"></text>
  14. </view>
  15. <text class="corner-mark">{{ article.cornerMark }}</text>
  16. </view>
  17. <view class="articleinfo">
  18. <view class="articletitle">{{ article.name }}</view><br>
  19. <view class="avatarName">
  20. {{ article.user.username }}
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. </li>
  26. </ul>
  27. </view>
  28. </view>
  29. </template>
  30. <script setup>
  31. import { ref, onMounted, reactive,computed } from 'vue';
  32. import homeApi from '@/api/HomeApi';
  33. const articleData = ref([]);
  34. function fetchData (){
  35. homeApi.gethomeList().then(response => {
  36. // 将articleData响应式对象赋值给articleData
  37. articleData.value = response.data;
  38. console.log('初始化后的articleData:', articleData.value);
  39. }).catch(error => {
  40. console.error('获取数据出错:', error);
  41. });
  42. };
  43. fetchData ();
  44. function chunk(arr, size = 2) {
  45. if (!arr) {
  46. return [];
  47. }
  48. const result = [];
  49. for (let i = 0; i < arr.length; ) {
  50. const subArr = [];
  51. for (let j = 0; j < size && i < arr.length; j++) {
  52. subArr.push(arr[i++]);
  53. }
  54. result.push(subArr);
  55. }
  56. return result;
  57. }
  58. </script>
  59. <style lang="scss">
  60. .class123 {
  61. background-color: #f1f1f1;
  62. width: 100%;
  63. }
  64. .play-icon-container {
  65. width: 30px;
  66. /* 可以根据需求调整这个容器宽度,用于控制整体大小和布局 */
  67. height: 30px;
  68. /* 可以根据需求调整这个容器高度,用于控制整体大小和布局 */
  69. position: absolute;
  70. }
  71. .play-icon {
  72. width: 0;
  73. height: 0;
  74. border-style: solid;
  75. border-width: 10px 0 10px 16px;
  76. border-color: transparent transparent transparent rgba(255, 255, 255, 1);
  77. position: absolute;
  78. bottom: 200%;
  79. left: 170%;
  80. transform: translate(200%, -50%);
  81. z-index: 1;
  82. }
  83. .play-icon-background {
  84. content: "";
  85. width: 35px;
  86. height: 35px;
  87. border-radius: 50%;
  88. background-color: rgba(0, 0, 0, 0.6);
  89. position: absolute;
  90. bottom: 210%;
  91. left: 120%;
  92. transform: translateX(100%);
  93. z-index: 0;
  94. }
  95. .daohang {
  96. height: 32px;
  97. }
  98. .container {
  99. margin-right: 0;
  100. margin-left: auto;
  101. }
  102. body {
  103. font-family: Arial, sans-serif;
  104. }
  105. .title {
  106. font-size: 22px;
  107. color: #000000;
  108. padding: 10px 0;
  109. }
  110. .data-list {
  111. list-style: none;
  112. padding: 0 10px;
  113. }
  114. .data-list-li {
  115. display: flex;
  116. align-items: flex-start;
  117. padding: 5px 0;
  118. }
  119. .article-row {
  120. display: flex;
  121. justify-content: space-between;
  122. width: 100%;
  123. }
  124. .articleimage {
  125. position: relative;
  126. width: 48%;
  127. height: 50%;
  128. margin: 3px;
  129. border-radius: 5px;
  130. overflow: hidden;
  131. }
  132. .el-image img {
  133. width: 100%;
  134. height: 100px;
  135. object-fit: cover;
  136. // transform: scale();
  137. }
  138. .articleinfo {
  139. // bottom: 0;
  140. // left: 0;4
  141. width: 100%;
  142. background-color: rgba(255, 255, 255, 1);
  143. color: white;
  144. padding: 5px;
  145. text-align: center;
  146. margin-top: 0;
  147. text-align: left;
  148. }
  149. .articletitle {
  150. padding: 0;
  151. font-size: 14px;
  152. color: #000000;
  153. width: 95%;
  154. }
  155. .avatarName {
  156. margin-left: 0;
  157. margin-top: -12px;
  158. font-size: 12px;
  159. color: gray;
  160. }
  161. .class123 {
  162. display: flex;
  163. }
  164. .corner-mark {
  165. position: absolute;
  166. top: 0;
  167. left: 0;
  168. background-color: red;
  169. color: white;
  170. padding: 2px 5px;
  171. border-radius: 2px;
  172. font-size: 12px;
  173. }
  174. </style>