bookshelf-readHistory.vue 9.4 KB

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