bookshelf-bookList.vue 8.3 KB

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