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

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