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

205 lines
4.0 KiB

  1. <template>
  2. <view class="book-item" :class="{'horizontal': horizontal}" @click="goToNovelDetail">
  3. <image class="book-cover" src="https://bookcover.yuewen.com/qdbimg/349573/1033014772/150.webp" mode="aspectFill"></image>
  4. <view class="book-info">
  5. <view class="book-title">{{book.title}}</view>
  6. <view class="book-author" v-if="book.author && !horizontal">{{book.author}}</view>
  7. <view class="book-desc" v-if="!horizontal">{{book.desc || '暂无简介'}}</view>
  8. <view class="content-row" v-if="!horizontal">
  9. <view class="book-tags" v-if="book.tags && book.tags.length">
  10. <text class="tag" v-for="(tag, index) in book.tags" :key="index">{{tag}}</text>
  11. </view>
  12. </view>
  13. <view class="content-row" v-if="!horizontal">
  14. <view class="book-status" v-if="book.status">
  15. <text>{{book.status}}</text>
  16. </view>
  17. <view class="book-text">
  18. 大家都在读
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. props: {
  27. book: {
  28. type: Object,
  29. default: () => ({
  30. id: '1',
  31. title: '我是半妖',
  32. cover: 'https://tse4-mm.cn.bing.net/th/id/OIP-C.iUyxJ_fxLjjX3kEBjteXWwAAAA?rs=1&pid=ImgDetMain',
  33. author: '东方不败',
  34. desc: '这是一部关于半妖少年成长的玄幻小说,讲述了主角在人妖两界的冒险故事。',
  35. tags: ['玄幻', '冒险', '热血'],
  36. status: '连载中'
  37. })
  38. },
  39. // 是否显示为水平布局(默认垂直布局)
  40. horizontal: {
  41. type: Boolean,
  42. default: false
  43. }
  44. },
  45. data() {
  46. return {}
  47. },
  48. methods: {
  49. goToNovelDetail() {
  50. uni.navigateTo({
  51. url: `/pages_order/novel/novelDetail?id=${this.book.id}`
  52. });
  53. }
  54. }
  55. }
  56. </script>
  57. <style lang="scss" scoped>
  58. .book-item {
  59. display: flex;
  60. padding: 20rpx 0;
  61. border-bottom: 1px solid #eee;
  62. &:last-child {
  63. border-bottom: none;
  64. }
  65. .book-cover {
  66. width: 170rpx;
  67. height: 230rpx;
  68. border-radius: 8rpx;
  69. margin-right: 20rpx;
  70. box-shadow: 0 4rpx 8rpx rgba(0,0,0,0.1);
  71. }
  72. .book-info {
  73. flex: 1;
  74. display: flex;
  75. flex-direction: column;
  76. justify-content: space-between;
  77. .book-title {
  78. font-size: 28rpx;
  79. font-weight: bold;
  80. color: #333;
  81. white-space: nowrap;
  82. overflow: hidden;
  83. text-overflow: ellipsis;
  84. flex: 1;
  85. margin-right: 10rpx;
  86. }
  87. .book-author {
  88. font-size: 24rpx;
  89. color: #666;
  90. margin-bottom: 10rpx;
  91. }
  92. .book-desc {
  93. font-size: 24rpx;
  94. color: #999;
  95. line-height: 1.5;
  96. display: -webkit-box;
  97. -webkit-box-orient: vertical;
  98. -webkit-line-clamp: 2;
  99. overflow: hidden;
  100. margin-bottom: 10rpx;
  101. }
  102. .content-row {
  103. display: flex;
  104. align-items: center;
  105. margin-bottom: 10rpx;
  106. }
  107. .book-tags {
  108. display: flex;
  109. flex-wrap: wrap;
  110. .tag {
  111. font-size: 20rpx;
  112. color: #666;
  113. background-color: #f5f5f5;
  114. padding: 4rpx 12rpx;
  115. border-radius: 20rpx;
  116. margin-right: 10rpx;
  117. }
  118. }
  119. .book-status {
  120. flex-shrink: 0;
  121. text {
  122. font-size: 20rpx;
  123. color: #67C23A;
  124. background-color: rgba(103, 194, 58, 0.1);
  125. border-radius: 20rpx;
  126. padding: 4rpx 12rpx;
  127. }
  128. }
  129. .book-text{
  130. font-size: 20rpx;
  131. }
  132. }
  133. }
  134. /* 水平布局样式 - 用于网格展示 */
  135. .book-item.horizontal {
  136. flex-direction: column;
  137. width: 200rpx;
  138. padding: 10rpx;
  139. border: none;
  140. .book-cover {
  141. width: 100%;
  142. height: 260rpx;
  143. margin-right: 0;
  144. margin-bottom: 10rpx;
  145. }
  146. .book-info {
  147. .title-row {
  148. display: flex;
  149. justify-content: space-between;
  150. align-items: center;
  151. }
  152. .book-title {
  153. font-size: 26rpx;
  154. white-space: wrap;
  155. overflow: hidden;
  156. text-overflow: ellipsis;
  157. flex: 1;
  158. display: -webkit-box;
  159. -webkit-box-orient: vertical;
  160. -webkit-line-clamp: 2;
  161. margin-right: 5rpx;
  162. }
  163. .book-author {
  164. font-size: 22rpx;
  165. }
  166. .book-desc {
  167. display: none;
  168. }
  169. .book-tags {
  170. display: none;
  171. }
  172. .book-status {
  173. flex-shrink: 0;
  174. text {
  175. font-size: 18rpx;
  176. }
  177. }
  178. }
  179. }
  180. </style>