四零语境前端代码仓库
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.

264 lines
6.1 KiB

  1. <template>
  2. <view class="desk-container">
  3. <!-- 顶部搜索栏 -->
  4. <view class="header">
  5. <view class="search-container">
  6. <uv-search
  7. placeholder="请输入要查询的内容"
  8. :show-action="true"
  9. :action-style="{color: '#fff', backgroundColor: '#06DADC', borderRadius:'8rpx', width:'100rpx', height: '64rpx', lineHeight: '64rpx', borderRadius: '198rpx', text:'white', fontSize:'26rpx'}"
  10. shape="round"
  11. bg-color="#F3F3F3"
  12. color="#C6C6C6"
  13. height="32"
  14. margin="0"
  15. v-model="searchKeyword"
  16. searchIconColor="#8B8B8B"
  17. placeholderColor="#c6c6c6"
  18. @search="handleSearch"
  19. @clear="handleSearch"
  20. @custom="handleSearch"
  21. ></uv-search>
  22. </view>
  23. </view>
  24. <!-- 书籍网格 -->
  25. <view class="book-grid-container">
  26. <view class="book-grid">
  27. <view
  28. v-for="(book, index) in list"
  29. :key="index"
  30. class="book-grid-item"
  31. @click="goDetail(book)"
  32. @longpress="showDeleteConfirm(book, index)"
  33. >
  34. <view class="book-grid-cover">
  35. <image :src="book.book.booksImg" mode="aspectFill"></image>
  36. <!-- 删除按钮 -->
  37. <view class="delete-btn" @click.stop="showDeleteConfirm(book, index)">
  38. <uv-icon name="close" size="16" color="#fff"></uv-icon>
  39. </view>
  40. </view>
  41. <view class="book-grid-info">
  42. <text class="book-grid-title">{{ book.book.booksName }}</text>
  43. <view class="book-grid-meta">
  44. <text class="book-grid-grade">{{ book.book.categoryName }}/</text>
  45. <image src="/static/播放图标.png" class="book-grid-duration-icon" />
  46. <text class="book-grid-duration">{{ book.book.duration }}</text>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. <uv-loading-icon text="加载中" textSize="30rpx" v-if="isLoading"></uv-loading-icon>
  52. <uv-empty v-else-if="!list.length" text="暂无数据"></uv-empty>
  53. </view>
  54. </view>
  55. </template>
  56. <script>
  57. import MixinList from '@/mixins/list'
  58. export default {
  59. mixins: [MixinList],
  60. data() {
  61. return {
  62. mixinListApi: 'book.stand',
  63. mixinListConfig: {
  64. customOnShow: true
  65. },
  66. searchKeyword: '',
  67. }
  68. },
  69. methods: {
  70. mixinSetParams(){
  71. const params = {}
  72. if(this.searchKeyword){
  73. params.title = this.searchKeyword
  74. }
  75. return params
  76. },
  77. goDetail(book){
  78. uni.navigateTo({
  79. url: '/subPages/home/directory?id=' + book.bookId
  80. })
  81. },
  82. handleSearch(){
  83. this.list = []
  84. this.initPage()
  85. this.getList(true)
  86. },
  87. // 显示删除确认弹窗
  88. showDeleteConfirm(book, index) {
  89. uni.showModal({
  90. title: '确认删除',
  91. content: `确定要从书桌中移除《${book.book.booksName}》吗?`,
  92. confirmText: '删除',
  93. confirmColor: '#ff4757',
  94. success: (res) => {
  95. if (res.confirm) {
  96. this.deleteBook(book, index)
  97. }
  98. }
  99. })
  100. },
  101. // 删除书本
  102. async deleteBook(book, index) {
  103. try {
  104. uni.showLoading({
  105. title: '删除中...'
  106. })
  107. const res = await this.$api.book.delStand({
  108. id: book.id
  109. })
  110. uni.hideLoading()
  111. if (res.code === 200) {
  112. // 从列表中移除该项
  113. this.list.splice(index, 1)
  114. uni.showToast({
  115. title: '删除成功',
  116. icon: 'success'
  117. })
  118. } else {
  119. uni.showToast({
  120. title: res.message || '删除失败',
  121. icon: 'error'
  122. })
  123. }
  124. } catch (error) {
  125. uni.hideLoading()
  126. console.error('删除书本失败:', error)
  127. uni.showToast({
  128. title: '删除失败',
  129. icon: 'error'
  130. })
  131. }
  132. }
  133. },
  134. onShow() {
  135. // 只有登录才会获取书籍
  136. if (uni.getStorageSync('token')) {
  137. this.initPage()
  138. this.getList(true)
  139. }
  140. }
  141. }
  142. </script>
  143. <style lang="scss" scoped>
  144. .desk-container {
  145. background: #fff;
  146. min-height: 100vh;
  147. padding-bottom: 50rpx;
  148. }
  149. // 顶部搜索栏
  150. .header {
  151. display: flex;
  152. align-items: center;
  153. padding: 20rpx 32rpx;
  154. background: #fff;
  155. position: sticky;
  156. top: 0;
  157. left: 0;
  158. right: 0;
  159. .search-container {
  160. flex: 1;
  161. }
  162. }
  163. // 书籍网格容器
  164. .book-grid-container {
  165. padding: 20rpx 30rpx;
  166. }
  167. // 书籍网格布局
  168. .book-grid {
  169. display: flex;
  170. flex-wrap: wrap;
  171. gap: 32rpx;
  172. .book-grid-item {
  173. width: 208rpx;
  174. display: flex;
  175. flex-direction: column;
  176. .book-grid-cover {
  177. box-shadow: 0px 4px 4px 0px #C0BCBA75;
  178. width: 100%;
  179. height: 278rpx;
  180. border-radius: 16rpx;
  181. overflow: hidden;
  182. margin-bottom: 16rpx;
  183. position: relative;
  184. image {
  185. width: 100%;
  186. height: 100%;
  187. }
  188. .delete-btn {
  189. position: absolute;
  190. top: 8rpx;
  191. right: 8rpx;
  192. width: 32rpx;
  193. height: 32rpx;
  194. background: rgba(0, 0, 0, 0.6);
  195. border-radius: 50%;
  196. display: flex;
  197. align-items: center;
  198. justify-content: center;
  199. z-index: 10;
  200. &:active {
  201. background: rgba(0, 0, 0, 0.8);
  202. }
  203. }
  204. }
  205. .book-grid-info {
  206. padding: 6rpx;
  207. box-sizing: border-box;
  208. .book-grid-title {
  209. font-size: 28rpx;
  210. font-weight: 700;
  211. color: $primary-text-color;
  212. overflow: hidden;
  213. text-overflow: ellipsis;
  214. white-space: nowrap;
  215. }
  216. .book-grid-meta {
  217. display: flex;
  218. align-items: center;
  219. margin-top: 8rpx;
  220. .book-grid-duration-icon {
  221. width: 24rpx;
  222. height: 24rpx;
  223. margin-right: 12rpx;
  224. }
  225. .book-grid-grade {
  226. font-size: 24rpx;
  227. color: $secondary-text-color;
  228. margin-right: 8rpx;
  229. }
  230. .book-grid-duration {
  231. font-size: 24rpx;
  232. color: $secondary-text-color;
  233. }
  234. }
  235. }
  236. }
  237. }
  238. </style>