bookshelf-readHistory.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <view class="readHistory_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">
  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. <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 empty_height = ref((uni.getSystemInfoSync().windowHeight-80-30)+'px')
  53. let is_edit = ref(false)
  54. let edit_book_list = ref<Array<number>>([])
  55. let is_selected_all = ref(false)
  56. let bottom_tools_real_height = ref(98)
  57. let bottom_tools_all_height = ref(0)
  58. let top_button_list = ref(
  59. [{'name':'全部','status':config.book_action_status.QUAN_BU},
  60. {'name':'连载','status':config.book_action_status.LIAN_ZAI},
  61. {'name':'完结','status':config.book_action_status.WAN_JIE}]
  62. )
  63. let cur_button_status = ref(config.book_action_status.QUAN_BU)
  64. bottom_tools_all_height.value = bottom_tools_real_height.value + uni.getSystemInfoSync().safeAreaInsets.bottom
  65. const props = defineProps({
  66. book_list: Array<book_item_data>,
  67. })
  68. // watch(()=>props.book_list, (new_v,old_v)=>{
  69. // console.log('book_list-观察 新值:',new_v,'旧值:',old_v)
  70. // },{immediate:true})
  71. const emits = defineEmits(['clickBook','clickButtonStatus','clickDeleteBook','clickEdit'])
  72. function clickBook(book_data:book_item_data, index:number) {
  73. if(is_edit.value) {
  74. let index = edit_book_list.value.indexOf(book_data.book_id)
  75. if(index>-1) {
  76. edit_book_list.value.splice(index,1)
  77. } else {
  78. edit_book_list.value.push(book_data.book_id)
  79. }
  80. if(edit_book_list.value.length >= props.book_list.length) {
  81. if(is_selected_all.value==false) {
  82. is_selected_all.value = true
  83. }
  84. } else {
  85. if(is_selected_all.value==true) {
  86. is_selected_all.value = false
  87. }
  88. }
  89. } else {
  90. emits('clickBook',book_data,index)
  91. }
  92. }
  93. function clickButtonStatus(status:number) {
  94. if(cur_button_status.value == status) {
  95. return
  96. }
  97. cur_button_status.value = status
  98. emits('clickButtonStatus',status)
  99. }
  100. function clickEdit() {
  101. changeEditStatus()
  102. emits('clickEdit', is_edit.value)
  103. }
  104. function changeEditStatus() {
  105. is_edit.value = !is_edit.value
  106. if(is_edit.value) {
  107. uni.hideTabBar({
  108. animation:false
  109. })
  110. } else {
  111. uni.showTabBar({
  112. animation:false,
  113. })
  114. edit_book_list.value = []
  115. }
  116. }
  117. function clickSelectedAll() {
  118. edit_book_list.value = []
  119. if(is_selected_all.value) {
  120. is_selected_all.value = false
  121. } else {
  122. if(props.book_list) {
  123. for (let i = 0; i < props.book_list.length; i++) {
  124. let element = props.book_list[i]
  125. edit_book_list.value.push(element.book_id)
  126. }
  127. is_selected_all.value = true
  128. }
  129. }
  130. }
  131. function clickDelete() {
  132. if(edit_book_list.value.length==0) {
  133. util.showInfoToast('请选择书籍')
  134. return
  135. }
  136. util.showModal('是否删除?','',()=>{
  137. tools.deleteReadHistory(edit_book_list.value)
  138. changeEditStatus()
  139. emits('clickDeleteBook',edit_book_list.value)
  140. })
  141. }
  142. </script>
  143. <style lang="scss">
  144. .readHistory_content{
  145. display: flex;
  146. flex-direction: column;
  147. // background-color: purple;
  148. .top{
  149. display: flex;
  150. flex-direction: row;
  151. align-items: center;
  152. height: 80rpx;
  153. // background-color: red;
  154. &__info{
  155. display: flex;
  156. margin-left: 10rpx;
  157. &__item {
  158. position: relative;
  159. display: flex;
  160. justify-content: center;
  161. align-items: center;
  162. margin-left: 15rpx;
  163. flex-shrink: 0;
  164. width: 160rpx;
  165. height: 70rpx;
  166. // background-color: red;
  167. &__image{
  168. width: 100%;
  169. height: 100%;
  170. }
  171. &__name{
  172. position: absolute;
  173. font-size: 18px;
  174. color: #fff;
  175. }
  176. }
  177. }
  178. &__edit{
  179. position: absolute;
  180. display: flex;
  181. right: 20rpx;
  182. width: 120rpx;
  183. height: 100%;
  184. justify-content: center;
  185. align-items: center;
  186. // background-color: green;
  187. &__icon {
  188. flex-shrink: 0;
  189. width: 32rpx;
  190. height: 32rpx;
  191. margin-right: 8rpx;
  192. .image {
  193. width: 100%;
  194. height: 100%;
  195. }
  196. }
  197. &__name {
  198. font-size: 15px;
  199. }
  200. }
  201. &__edit-none {
  202. display: none;
  203. }
  204. }
  205. .book-list{
  206. display: flex;
  207. flex-direction: row; //横向排列
  208. flex-wrap: wrap; //换行排列
  209. padding: 1% 2%;
  210. // background-color: red;
  211. &__item {
  212. position: relative;
  213. display: flex;
  214. flex-direction: column;
  215. margin: 2% 2%;
  216. width: 46%;
  217. align-items: center;
  218. // background-color: purple;
  219. &__book-cover{
  220. width: 300rpx;
  221. height: 400rpx;
  222. flex-shrink: 0; //设置flex元素所有比例.默认是1,为0的时候不进行缩放
  223. .image{
  224. width: 100%;
  225. height: 100%;
  226. }
  227. }
  228. &__book-name{
  229. margin-top: 10rpx;
  230. display: -webkit-box;
  231. -webkit-line-clamp: 1;
  232. -webkit-box-orient: vertical;
  233. overflow: hidden;
  234. text-overflow: ellipsis;
  235. font-size: 19px;
  236. width: 90%;
  237. height: 100rpx;
  238. }
  239. &__book-info{
  240. margin-top: 10rpx;
  241. font-size: 17px;
  242. font-weight: 460;
  243. color: #777777;
  244. }
  245. &__edit-icon{
  246. position: absolute;
  247. top: 340rpx;
  248. right: 30rpx;
  249. width: 50rpx;
  250. height: 50rpx;
  251. flex-shrink: 0;
  252. .image{
  253. width: 100%;
  254. height: 100%;
  255. }
  256. }
  257. }
  258. }
  259. }
  260. </style>