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

211 lines
3.9 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.details || '暂无简介'}}</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>{{ statusText }}</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. computed: {
  39. statusClass() {
  40. const statusMap = {
  41. 'draft': 'new',
  42. '0': 'ongoing',
  43. '1': 'completed'
  44. };
  45. return statusMap[this.book.status] || 'ongoing';
  46. },
  47. statusText() {
  48. const textMap = {
  49. // '0': '新建',
  50. '0': '连载中',
  51. '1': '已完结'
  52. };
  53. return textMap[this.book.status] || '连载中';
  54. },
  55. },
  56. data() {
  57. return {}
  58. },
  59. methods: {
  60. }
  61. }
  62. </script>
  63. <style lang="scss" scoped>
  64. .book-item {
  65. display: flex;
  66. padding: 20rpx 0;
  67. border-bottom: 1px solid #eee;
  68. &:last-child {
  69. border-bottom: none;
  70. }
  71. .book-cover {
  72. width: 160rpx;
  73. height: 210rpx;
  74. border-radius: 16rpx;
  75. margin-right: 20rpx;
  76. box-shadow: 0 4rpx 8rpx rgba(0,0,0,0.1);
  77. }
  78. .book-info {
  79. flex: 1;
  80. display: flex;
  81. flex-direction: column;
  82. justify-content: space-between;
  83. .book-title {
  84. font-size: 28rpx;
  85. font-weight: bold;
  86. color: #333;
  87. white-space: nowrap;
  88. overflow: hidden;
  89. text-overflow: ellipsis;
  90. flex: 1;
  91. margin-right: 10rpx;
  92. }
  93. .book-author {
  94. font-size: 24rpx;
  95. color: #666;
  96. margin-bottom: 10rpx;
  97. }
  98. .book-desc {
  99. font-size: 24rpx;
  100. color: #999;
  101. line-height: 1.5;
  102. display: -webkit-box;
  103. -webkit-box-orient: vertical;
  104. -webkit-line-clamp: 2;
  105. overflow: hidden;
  106. margin-bottom: 10rpx;
  107. }
  108. .content-row {
  109. display: flex;
  110. align-items: center;
  111. margin-bottom: 10rpx;
  112. }
  113. .book-tags {
  114. display: flex;
  115. flex-wrap: wrap;
  116. .tag {
  117. font-size: 20rpx;
  118. color: #666;
  119. background-color: #f5f5f5;
  120. padding: 4rpx 12rpx;
  121. border-radius: 20rpx;
  122. margin-right: 10rpx;
  123. }
  124. }
  125. .book-status {
  126. flex-shrink: 0;
  127. text {
  128. font-size: 20rpx;
  129. color: #67C23A;
  130. background-color: rgba(103, 194, 58, 0.1);
  131. border-radius: 20rpx;
  132. padding: 4rpx 12rpx;
  133. }
  134. }
  135. .book-text{
  136. font-size: 20rpx;
  137. }
  138. }
  139. }
  140. /* 水平布局样式 - 用于网格展示 */
  141. .book-item.horizontal {
  142. flex-direction: column;
  143. width: 220rpx;
  144. padding: 10rpx;
  145. border: none;
  146. .book-cover {
  147. width: 100%;
  148. height: 300rpx;
  149. margin-right: 0;
  150. margin-bottom: 10rpx;
  151. }
  152. .book-info {
  153. .title-row {
  154. display: flex;
  155. justify-content: space-between;
  156. align-items: center;
  157. }
  158. .book-title {
  159. font-size: 26rpx;
  160. white-space: wrap;
  161. overflow: hidden;
  162. text-overflow: ellipsis;
  163. flex: 1;
  164. display: -webkit-box;
  165. -webkit-box-orient: vertical;
  166. -webkit-line-clamp: 2;
  167. margin-right: 5rpx;
  168. }
  169. .book-author {
  170. font-size: 22rpx;
  171. }
  172. .book-desc {
  173. display: none;
  174. }
  175. .book-tags {
  176. display: none;
  177. }
  178. .book-status {
  179. flex-shrink: 0;
  180. text {
  181. font-size: 18rpx;
  182. }
  183. }
  184. }
  185. }
  186. </style>