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

253 lines
4.6 KiB

  1. <template>
  2. <view class="book-item" :class="{'horizontal': horizontal}" @click="$emit('click')">
  3. <view class="cover-wrapper">
  4. <image class="book-cover" :src="book.image
  5. && book.image.split(',')[0]" mode="aspectFill"></image>
  6. <view class="tag original" v-if="book.isOriginal == 'Y'">原创</view>
  7. </view>
  8. <view class="book-info">
  9. <view class="book-title">{{book.name}}</view>
  10. <view class="book-author" v-if="book.author && !horizontal">{{book.author}}</view>
  11. <view class="book-desc" v-if="!horizontal">{{book.details || '暂无简介'}}</view>
  12. <view class="content-row" v-if="!horizontal">
  13. <view class="book-tags" v-if="book.tags && book.tags.length">
  14. <text class="tag" v-for="(tag, index) in book.tags" :key="index">{{tag}}</text>
  15. </view>
  16. </view>
  17. <view class="content-row" v-if="!horizontal">
  18. <view class="book-status">
  19. <text>{{ statusText }}</text>
  20. </view>
  21. <view class="book-text">
  22. {{ item.service || '大家都在读' }}
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. props: {
  31. book: {
  32. type: Object,
  33. default: {}
  34. },
  35. // 是否显示为水平布局(默认垂直布局)
  36. horizontal: {
  37. type: Boolean,
  38. default: false
  39. },
  40. },
  41. computed: {
  42. statusClass() {
  43. const statusMap = {
  44. 'draft': 'new',
  45. '0': 'ongoing',
  46. '1': 'completed'
  47. };
  48. return statusMap[this.book.status] || 'ongoing';
  49. },
  50. statusText() {
  51. const textMap = {
  52. // '0': '新建',
  53. '0': '连载中',
  54. '1': '已完结'
  55. };
  56. return textMap[this.book.status] || '连载中';
  57. },
  58. },
  59. data() {
  60. return {}
  61. },
  62. methods: {
  63. }
  64. }
  65. </script>
  66. <style lang="scss" scoped>
  67. .book-item {
  68. display: flex;
  69. padding: 20rpx 0;
  70. border-bottom: 1px solid #eee;
  71. &:last-child {
  72. border-bottom: none;
  73. }
  74. .cover-wrapper {
  75. position: relative;
  76. width: 160rpx;
  77. height: 210rpx;
  78. border-radius: 16rpx;
  79. margin-right: 20rpx;
  80. box-shadow: 0 4rpx 8rpx rgba(0,0,0,0.1);
  81. .book-cover {
  82. width: 100%;
  83. height: 100%;
  84. border-radius: 16rpx;
  85. }
  86. .tag {
  87. position: absolute;
  88. top: 0;
  89. left: 0;
  90. font-size: 20rpx;
  91. color: #fff;
  92. padding: 2rpx 8rpx;
  93. &.original {
  94. background-color: #ffa502;
  95. }
  96. }
  97. }
  98. .book-info {
  99. flex: 1;
  100. display: flex;
  101. flex-direction: column;
  102. justify-content: space-between;
  103. .book-title {
  104. font-size: 28rpx;
  105. font-weight: bold;
  106. color: #333;
  107. white-space: nowrap;
  108. overflow: hidden;
  109. text-overflow: ellipsis;
  110. flex: 1;
  111. margin-right: 10rpx;
  112. }
  113. .book-author {
  114. font-size: 24rpx;
  115. color: #666;
  116. margin-bottom: 10rpx;
  117. }
  118. .book-desc {
  119. font-size: 24rpx;
  120. color: #999;
  121. line-height: 1.5;
  122. display: -webkit-box;
  123. -webkit-box-orient: vertical;
  124. -webkit-line-clamp: 2;
  125. overflow: hidden;
  126. margin-bottom: 10rpx;
  127. }
  128. .content-row {
  129. display: flex;
  130. align-items: center;
  131. margin-bottom: 10rpx;
  132. }
  133. .book-tags {
  134. display: flex;
  135. flex-wrap: wrap;
  136. .tag {
  137. font-size: 20rpx;
  138. color: #666;
  139. background-color: #f5f5f5;
  140. padding: 4rpx 12rpx;
  141. border-radius: 20rpx;
  142. margin-right: 10rpx;
  143. }
  144. }
  145. .book-status {
  146. flex-shrink: 0;
  147. text {
  148. font-size: 20rpx;
  149. color: #67C23A;
  150. background-color: rgba(103, 194, 58, 0.1);
  151. border-radius: 20rpx;
  152. padding: 4rpx 12rpx;
  153. }
  154. }
  155. .book-text{
  156. font-size: 20rpx;
  157. }
  158. }
  159. }
  160. /* 水平布局样式 - 用于网格展示 */
  161. .book-item.horizontal {
  162. flex-direction: column;
  163. width: 220rpx;
  164. padding: 10rpx;
  165. border: none;
  166. .cover-wrapper {
  167. position: relative;
  168. width: 100%;
  169. height: 300rpx;
  170. margin-right: 0;
  171. margin-bottom: 10rpx;
  172. .book-cover {
  173. width: 100%;
  174. height: 100%;
  175. }
  176. .tag {
  177. position: absolute;
  178. top: 0;
  179. left: 0;
  180. font-size: 20rpx;
  181. color: #fff;
  182. padding: 2rpx 8rpx;
  183. &.original {
  184. background-color: #ffa502;
  185. }
  186. }
  187. }
  188. .book-info {
  189. .title-row {
  190. display: flex;
  191. justify-content: space-between;
  192. align-items: center;
  193. }
  194. .book-title {
  195. font-size: 26rpx;
  196. white-space: wrap;
  197. overflow: hidden;
  198. text-overflow: ellipsis;
  199. flex: 1;
  200. display: -webkit-box;
  201. -webkit-box-orient: vertical;
  202. -webkit-line-clamp: 2;
  203. margin-right: 5rpx;
  204. }
  205. .book-author {
  206. font-size: 22rpx;
  207. }
  208. .book-desc {
  209. display: none;
  210. }
  211. .book-tags {
  212. display: none;
  213. }
  214. .book-status {
  215. flex-shrink: 0;
  216. text {
  217. font-size: 18rpx;
  218. }
  219. }
  220. }
  221. }
  222. </style>