bookshelf-bookList.vue 6.6 KB

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