BookItems.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <div class="books-wrapper">
  3. <div class="wrapper">
  4. <div
  5. class="book"
  6. v-for="book in books"
  7. :key="book.bookUrl"
  8. @click="handleClick(book)"
  9. >
  10. <div class="cover-img">
  11. <img
  12. class="cover"
  13. :src="getCover(book)"
  14. :key="book.coverUrl"
  15. @error.once="proxyImage"
  16. alt=""
  17. loading="lazy"
  18. />
  19. </div>
  20. <div class="info">
  21. <div class="name">{{ book.name }}</div>
  22. <div class="sub">
  23. <div class="author">
  24. {{ book.author }}
  25. </div>
  26. <div class="tags" v-if="isSearch">
  27. <el-tag
  28. v-for="tag in book.kind?.split(',').slice(0, 2)"
  29. :key="tag"
  30. >
  31. {{ tag }}
  32. </el-tag>
  33. </div>
  34. <div class="update-info" v-if="!isSearch">
  35. <div class="dot">•</div>
  36. <div class="size">共{{ (book as Book).totalChapterNum }}章</div>
  37. <div class="dot">•</div>
  38. <div class="date">
  39. {{ dateFormat((book as Book).lastCheckTime) }}
  40. </div>
  41. </div>
  42. </div>
  43. <div class="intro" v-if="isSearch">{{ book.intro }}</div>
  44. <div class="dur-chapter" v-if="!isSearch">
  45. 已读:{{ (book as Book).durChapterTitle }}
  46. </div>
  47. <div class="last-chapter">最新:{{ book.latestChapterTitle }}</div>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. </template>
  53. <script setup lang="ts">
  54. import type { Book, SeachBook } from '@/book'
  55. import { dateFormat, isLegadoUrl } from '../utils/utils'
  56. import API from '@api'
  57. const props = defineProps<{
  58. books: Array<Book | SeachBook>
  59. isSearch: boolean
  60. }>()
  61. const emit = defineEmits(['bookClick'])
  62. const handleClick = (book: Book | SeachBook) => emit('bookClick', book)
  63. const getCover = ({ bookUrl, coverUrl }: Book | SeachBook) => {
  64. if (coverUrl === undefined) return API.getProxyCoverUrl(bookUrl)
  65. return isLegadoUrl(coverUrl) ? API.getProxyCoverUrl(coverUrl) : coverUrl
  66. }
  67. const proxyImage = (evt: Event) => {
  68. const target = evt.target as HTMLImageElement
  69. target.src = API.getProxyCoverUrl(target.src)
  70. }
  71. const subJustify = computed(() =>
  72. props.isSearch ? 'space-between' : 'flex-start',
  73. )
  74. </script>
  75. <style lang="scss" scoped>
  76. .books-wrapper {
  77. overflow: auto;
  78. .wrapper {
  79. display: grid;
  80. grid-template-columns: repeat(auto-fill, 380px);
  81. justify-content: space-around;
  82. grid-gap: 10px;
  83. .book {
  84. user-select: none;
  85. display: flex;
  86. cursor: pointer;
  87. margin-bottom: 18px;
  88. padding: 24px 24px;
  89. width: 360px;
  90. flex-direction: row;
  91. justify-content: space-around;
  92. .cover-img {
  93. width: 84px;
  94. height: 112px;
  95. .cover {
  96. width: 84px;
  97. height: 112px;
  98. }
  99. }
  100. .info {
  101. display: flex;
  102. flex-direction: column;
  103. justify-content: space-around;
  104. align-items: left;
  105. height: 112px;
  106. margin-left: 20px;
  107. flex: 1;
  108. overflow: hidden;
  109. .name {
  110. width: fit-content;
  111. font-size: 16px;
  112. font-weight: 700;
  113. color: #33373d;
  114. }
  115. .sub {
  116. display: flex;
  117. flex-direction: row;
  118. align-items: baseline;
  119. justify-content: v-bind('subJustify');
  120. font-size: 12px;
  121. font-weight: 600;
  122. color: #6b6b6b;
  123. .tags {
  124. :deep(.el-tag) {
  125. margin-right: 0.5em;
  126. }
  127. }
  128. .update-info {
  129. display: flex;
  130. .dot {
  131. margin: 0 7px;
  132. }
  133. }
  134. }
  135. .intro,
  136. .dur-chapter,
  137. .last-chapter {
  138. color: #969ba3;
  139. font-size: 13px;
  140. margin-top: 3px;
  141. font-weight: 500;
  142. word-wrap: break-word;
  143. overflow: hidden;
  144. text-overflow: ellipsis;
  145. display: -webkit-box;
  146. -webkit-box-orient: vertical;
  147. -webkit-line-clamp: 1;
  148. line-clamp: 1;
  149. text-align: left;
  150. }
  151. }
  152. }
  153. .book:hover {
  154. background: rgba(0, 0, 0, 0.1);
  155. transition-duration: 0.5s;
  156. }
  157. }
  158. .wrapper:last-child {
  159. margin-right: auto;
  160. }
  161. }
  162. .books-wrapper::-webkit-scrollbar {
  163. width: 0 !important;
  164. }
  165. @media screen and (max-width: 750px) {
  166. .books-wrapper {
  167. .wrapper {
  168. display: flex;
  169. flex-direction: column;
  170. .book {
  171. box-sizing: border-box;
  172. width: 100%;
  173. margin-bottom: 0;
  174. padding: 10px 20px;
  175. }
  176. }
  177. }
  178. }
  179. </style>