bookshelf-bookList.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <view class="bookList_content" :style="{width:window_width}">
  3. <view :class="book_list.length>0?'top':'top-none'">
  4. <view class='top__info'>
  5. {{is_edit?'':'全部'}}
  6. </view>
  7. <view class="top__edit" @click="clickEdit">{{is_edit?'取消':'编辑'}}</view>
  8. </view>
  9. <view class="book-list" :style="{marginBottom:is_edit?bottom_tools_all_height+'rpx':0}">
  10. <view class="book-list__item" v-for="(item,index) in book_list" :key="index"
  11. @click="clickBook(item,index)">
  12. <view class="book-list__item__book-cover">
  13. <image class="image" :src="item.book_cover" mode="aspectFill"></image>
  14. </view>
  15. <view class="book-list__item__book-name">
  16. {{item.book_name}}
  17. </view>
  18. <view class="book-list__item__book-info">
  19. {{util.isNull(item.start_read_chapter_id)?'1':item.start_read_chapter_id}}章 / {{item.chapter_count}}章
  20. </view>
  21. <view class="book-list__item__edit-icon" v-if="is_edit">
  22. <uni-icons :type="edit_book_list.indexOf(item.book_id)==-1?'circle':'circle-filled'" size="35"></uni-icons>
  23. </view>
  24. </view>
  25. </view>
  26. <view v-if="is_edit" class="bottom-tools" :style="{height:bottom_tools_all_height+'rpx'}">
  27. <view class="bottom-tools__all" :style="{height:bottom_tools_real_height+'rpx'}" @click="clickSelectedAll">
  28. {{ is_selected_all?'取消全选':'全选' }}
  29. </view>
  30. <view class="bottom-tools__delete bottom-tools__all" :style="{height:bottom_tools_real_height+'rpx'}" @click="clickDelete">
  31. 删除({{edit_book_list.length}})
  32. </view>
  33. </view>
  34. </view>
  35. </template>
  36. <script setup lang="ts">
  37. import { ref, watch } from 'vue';
  38. import { book_item_data } from '../../data/data';
  39. import { util } from '../../framework/util';
  40. import { tools } from '../../framework/tools';
  41. let window_width = ref(uni.getSystemInfoSync().windowWidth + 'px')
  42. let is_edit = ref(false)
  43. let edit_book_list = ref<Array<number>>([])
  44. let is_selected_all = ref(false)
  45. let bottom_tools_real_height = ref(98)
  46. let bottom_tools_all_height = ref(0)
  47. bottom_tools_all_height.value = bottom_tools_real_height.value + uni.getSystemInfoSync().safeAreaInsets.bottom
  48. const props = defineProps({
  49. book_list: Array<book_item_data>,
  50. })
  51. // watch(()=>props.book_list, (new_v,old_v)=>{
  52. // console.log('book_list-观察 新值:',new_v,'旧值:',old_v)
  53. // },{immediate:true})
  54. const emits = defineEmits(['clickBook','clickDeleteBook'])
  55. function clickBook(book_data:book_item_data, index:number) {
  56. if(is_edit.value) {
  57. let index = edit_book_list.value.indexOf(book_data.book_id)
  58. if(index>-1) {
  59. edit_book_list.value.splice(index,1)
  60. } else {
  61. edit_book_list.value.push(book_data.book_id)
  62. }
  63. if(edit_book_list.value.length >= props.book_list.length) {
  64. if(is_selected_all.value==false) {
  65. is_selected_all.value = true
  66. }
  67. } else {
  68. if(is_selected_all.value==true) {
  69. is_selected_all.value = false
  70. }
  71. }
  72. } else {
  73. emits('clickBook',book_data,index)
  74. }
  75. }
  76. function clickEdit() {
  77. changeEditStatus()
  78. }
  79. function changeEditStatus() {
  80. is_edit.value = !is_edit.value
  81. if(is_edit.value) {
  82. uni.hideTabBar({
  83. animation:false
  84. })
  85. } else {
  86. uni.showTabBar({
  87. animation:false,
  88. })
  89. edit_book_list.value = []
  90. }
  91. }
  92. function clickSelectedAll() {
  93. edit_book_list.value = []
  94. if(is_selected_all.value) {
  95. is_selected_all.value = false
  96. } else {
  97. if(props.book_list) {
  98. for (let i = 0; i < props.book_list.length; i++) {
  99. let element = props.book_list[i]
  100. edit_book_list.value.push(element.book_id)
  101. }
  102. is_selected_all.value = true
  103. }
  104. }
  105. }
  106. function clickDelete() {
  107. if(edit_book_list.value.length==0) {
  108. util.showInfoToast('请选择书籍')
  109. return
  110. }
  111. tools.deleteBookshelf(edit_book_list.value, ()=>{
  112. changeEditStatus()
  113. })
  114. emits('clickDeleteBook',edit_book_list.value)
  115. }
  116. </script>
  117. <style lang="scss">
  118. .bookList_content{
  119. display: flex;
  120. flex-direction: column;
  121. .top{
  122. display: flex;
  123. flex-direction: row;
  124. justify-content: space-between;
  125. align-items: center;
  126. height: 80rpx;
  127. background-color: red;
  128. &__info{
  129. display: flex;
  130. padding-left: 20rpx;
  131. }
  132. &__edit{
  133. display: flex;
  134. width: 120rpx;
  135. height: 100%;
  136. justify-content: center;
  137. align-items: center;
  138. // background-color: green;
  139. }
  140. }
  141. .top-none {
  142. display: none;
  143. }
  144. .book-list{
  145. display: flex;
  146. flex-direction: row; //横向排列
  147. flex-wrap: wrap; //换行排列
  148. padding: 1% 2%;
  149. // background-color: red;
  150. &__item {
  151. position: relative;
  152. display: flex;
  153. flex-direction: column;
  154. margin: 2% 2%;
  155. width: 46%;
  156. align-items: center;
  157. // background-color: purple;
  158. &__book-cover{
  159. width: 300rpx;
  160. height: 400rpx;
  161. flex-shrink: 0; //设置flex元素所有比例.默认是1,为0的时候不进行缩放
  162. .image{
  163. width: 100%;
  164. height: 100%;
  165. }
  166. }
  167. &__book-name{
  168. margin-top: 10rpx;
  169. display: -webkit-box;
  170. align-items: center;
  171. -webkit-line-clamp: 1;
  172. -webkit-box-orient: vertical;
  173. overflow: hidden;
  174. text-overflow: ellipsis;
  175. }
  176. &__book-info{
  177. margin-top: 10rpx;
  178. }
  179. &__edit-icon{
  180. position: absolute;
  181. top: 10rpx;
  182. right: 10rpx;
  183. // width: 60rpx;
  184. // height: 60rpx;
  185. // background-color: red;
  186. }
  187. }
  188. }
  189. .bottom-tools{
  190. position: fixed;
  191. left: 0%;
  192. right: 0%;
  193. bottom: 0%;
  194. width: 100%;
  195. // height: 98rpx;
  196. display: flex;
  197. justify-content: space-between;
  198. background-color: #ffffff;
  199. &__all{
  200. display: flex;
  201. width: 50%;
  202. height: 100%;
  203. justify-content: center;
  204. align-items: center;
  205. background-color: green;
  206. }
  207. &__delete{
  208. background-color: paleturquoise;
  209. }
  210. }
  211. }
  212. </style>