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

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