小说小程序前端代码仓库(小程序)
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.

200 lines
3.9 KiB

  1. <template>
  2. <view class="book-item" :class="{'horizontal': horizontal}" @click="$emit('click')">
  3. <image class="book-cover" src="https://bookcover.yuewen.com/qdbimg/349573/1033014772/150.webp" mode="aspectFill"></image>
  4. <view class="book-info">
  5. <view class="book-title">{{book.title}}</view>
  6. <view class="book-author" v-if="book.author && !horizontal">{{book.author}}</view>
  7. <view class="book-desc" v-if="!horizontal">{{book.desc || '暂无简介'}}</view>
  8. <view class="content-row" v-if="!horizontal">
  9. <view class="book-tags" v-if="book.tags && book.tags.length">
  10. <text class="tag" v-for="(tag, index) in book.tags" :key="index">{{tag}}</text>
  11. </view>
  12. </view>
  13. <view class="content-row" v-if="!horizontal">
  14. <view class="book-status" v-if="book.status">
  15. <text>{{book.status}}</text>
  16. </view>
  17. <view class="book-text">
  18. 大家都在读
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. props: {
  27. book: {
  28. type: Object,
  29. default: () => ({
  30. id: '1',
  31. title: '我是半妖',
  32. cover: 'https://tse4-mm.cn.bing.net/th/id/OIP-C.iUyxJ_fxLjjX3kEBjteXWwAAAA?rs=1&pid=ImgDetMain',
  33. author: '东方不败',
  34. desc: '这是一部关于半妖少年成长的玄幻小说,讲述了主角在人妖两界的冒险故事。',
  35. tags: ['玄幻', '冒险', '热血'],
  36. status: '连载中'
  37. })
  38. },
  39. // 是否显示为水平布局(默认垂直布局)
  40. horizontal: {
  41. type: Boolean,
  42. default: false
  43. }
  44. },
  45. data() {
  46. return {}
  47. },
  48. methods: {
  49. }
  50. }
  51. </script>
  52. <style lang="scss" scoped>
  53. .book-item {
  54. display: flex;
  55. padding: 20rpx 0;
  56. border-bottom: 1px solid #eee;
  57. &:last-child {
  58. border-bottom: none;
  59. }
  60. .book-cover {
  61. width: 170rpx;
  62. height: 230rpx;
  63. border-radius: 8rpx;
  64. margin-right: 20rpx;
  65. box-shadow: 0 4rpx 8rpx rgba(0,0,0,0.1);
  66. }
  67. .book-info {
  68. flex: 1;
  69. display: flex;
  70. flex-direction: column;
  71. justify-content: space-between;
  72. .book-title {
  73. font-size: 28rpx;
  74. font-weight: bold;
  75. color: #333;
  76. white-space: nowrap;
  77. overflow: hidden;
  78. text-overflow: ellipsis;
  79. flex: 1;
  80. margin-right: 10rpx;
  81. }
  82. .book-author {
  83. font-size: 24rpx;
  84. color: #666;
  85. margin-bottom: 10rpx;
  86. }
  87. .book-desc {
  88. font-size: 24rpx;
  89. color: #999;
  90. line-height: 1.5;
  91. display: -webkit-box;
  92. -webkit-box-orient: vertical;
  93. -webkit-line-clamp: 2;
  94. overflow: hidden;
  95. margin-bottom: 10rpx;
  96. }
  97. .content-row {
  98. display: flex;
  99. align-items: center;
  100. margin-bottom: 10rpx;
  101. }
  102. .book-tags {
  103. display: flex;
  104. flex-wrap: wrap;
  105. .tag {
  106. font-size: 20rpx;
  107. color: #666;
  108. background-color: #f5f5f5;
  109. padding: 4rpx 12rpx;
  110. border-radius: 20rpx;
  111. margin-right: 10rpx;
  112. }
  113. }
  114. .book-status {
  115. flex-shrink: 0;
  116. text {
  117. font-size: 20rpx;
  118. color: #67C23A;
  119. background-color: rgba(103, 194, 58, 0.1);
  120. border-radius: 20rpx;
  121. padding: 4rpx 12rpx;
  122. }
  123. }
  124. .book-text{
  125. font-size: 20rpx;
  126. }
  127. }
  128. }
  129. /* 水平布局样式 - 用于网格展示 */
  130. .book-item.horizontal {
  131. flex-direction: column;
  132. width: 200rpx;
  133. padding: 10rpx;
  134. border: none;
  135. .book-cover {
  136. width: 100%;
  137. height: 260rpx;
  138. margin-right: 0;
  139. margin-bottom: 10rpx;
  140. }
  141. .book-info {
  142. .title-row {
  143. display: flex;
  144. justify-content: space-between;
  145. align-items: center;
  146. }
  147. .book-title {
  148. font-size: 26rpx;
  149. white-space: wrap;
  150. overflow: hidden;
  151. text-overflow: ellipsis;
  152. flex: 1;
  153. display: -webkit-box;
  154. -webkit-box-orient: vertical;
  155. -webkit-line-clamp: 2;
  156. margin-right: 5rpx;
  157. }
  158. .book-author {
  159. font-size: 22rpx;
  160. }
  161. .book-desc {
  162. display: none;
  163. }
  164. .book-tags {
  165. display: none;
  166. }
  167. .book-status {
  168. flex-shrink: 0;
  169. text {
  170. font-size: 18rpx;
  171. }
  172. }
  173. }
  174. }
  175. </style>