bookshelf-bookList.vue 7.9 KB

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