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

267 lines
6.2 KiB

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