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

193 lines
3.5 KiB

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