From 42d49984f665e96ed453e4758e692d4187a771fa Mon Sep 17 00:00:00 2001 From: sunyuting Date: Mon, 30 Mar 2020 00:02:45 +0800 Subject: [PATCH] fix loading last page at read page --- src/components/Read/Menu.vue | 23 +++++++++++++++-- src/components/Read/Read.vue | 48 +++++++++++++++++++++++++++--------- src/helper/api.js | 2 +- 3 files changed, 59 insertions(+), 14 deletions(-) diff --git a/src/components/Read/Menu.vue b/src/components/Read/Menu.vue index 95f75e1..00e4308 100644 --- a/src/components/Read/Menu.vue +++ b/src/components/Read/Menu.vue @@ -11,7 +11,7 @@
@@ -34,7 +34,8 @@ export default { data() { return { list: this.menuList, - sort: this.thisSort + sort: this.thisSort, + thisid: 0 } }, methods: { @@ -47,6 +48,24 @@ export default { this.list.sort((a, b) => a.sort - b.sort) } } + }, + watch:{ + thisSort(v,o){ + if(this.sort) { + this.thisid = this.pageId + }else{ + this.thisid = this.menuList.length - 1 - this.pageId + } + }, + pageId(v,o) { + if(v !== o) { + if(this.sort) { + this.thisid = this.pageId + }else{ + this.thisid = this.menuList.length - 1 - this.pageId + } + } + } } } \ No newline at end of file diff --git a/src/components/Read/Read.vue b/src/components/Read/Read.vue index 352f6fd..680673b 100644 --- a/src/components/Read/Read.vue +++ b/src/components/Read/Read.vue @@ -122,6 +122,8 @@ export default { this.getSet() this.list = list this.lastpage = list.length - 1 + if(this.bookthis == this.lastpage) this.sort = true + sessionStorage.setItem(`book.sort:${this.bookid}`, 'true') this.getData() }else { this.getList() @@ -182,10 +184,12 @@ export default { } }, menuGetData(index=0,id=0) { + this.title = this.list[index].title + document.title = `${this.title}-${Config.GlobalTitle}` this.bookthis = index this.prevbook = index this.status = 3 - this.params = { + this.params = { url: Config.ReadUrl(this.bookid,id), page: 'book', key: 'book', @@ -195,6 +199,10 @@ export default { } } this.getData() + let bis = this.bookthis + if(!this.sort) bis = this.list.length - 1 - index + localStorage.setItem(`book.n:${this.bookid}`, bis) + localStorage.setItem(`book.p:${this.bookid}`, this.prevbook) this.openmenu = !this.openmenu this.open = false if(this.xory) { @@ -211,7 +219,7 @@ export default { this.current = this.current - 1 this.makeWidth() }else { - if(this.prevbook >= 1) { + if(this.prevbook >= 1 && this.prevPage !== this.lastpage) { let next = this.prevbook if(this.sort) { next = next - 1 @@ -370,23 +378,41 @@ export default { if(height < -2000) { if(this.loading) { let next = this.bookthis + // console.log(next,this.lastpage) if(this.sort) { - next = next + 1 + if(next !== this.lastpage) { + next = next + 1 + this.bookthis = next + const nextid = this.list[next].id + this.$router.replace({path: `/read/${this.bookid}/${nextid}`}) + this.addPage('push') + }else { + this.loading = false + success() + this.$refs.myJRoll.jroll.scroller.querySelector('.jroll-infinite-tip').style.display = 'none' + } }else { - next = next - 1 + const n = this.lastpage - this.bookthis + const bookthis = localStorage.setItem(`book.n:${this.bookid}`, n) + if(next !== 0) { + next = next - 1 + this.bookthis = next + const nextid = this.list[next].id + this.$router.replace({path: `/read/${this.bookid}/${nextid}`}) + this.addPage('push') + }else{ + this.loading = false + success() + this.$refs.myJRoll.jroll.scroller.querySelector('.jroll-infinite-tip').style.display = 'none' + } } - this.bookthis = next - const nextid = this.list[next].id - // console.log(nextid) - this.$router.replace({path: `/read/${this.bookid}/${nextid}`}) - this.addPage('push') - success() + success() } } } }, pulldown(success) { - // console.log(this.prevbook) + // console.log(this.prevbook,this.sort) if(this.prevbook > 0) { // console.log(this.bookthis) let next = this.prevbook diff --git a/src/helper/api.js b/src/helper/api.js index 8ce27ae..b9d778a 100644 --- a/src/helper/api.js +++ b/src/helper/api.js @@ -308,7 +308,7 @@ const BookJson = (data = '') => { if(lsa) { const title = $(lsa).text() const id = makeLastId($(lsa).attr('href')) - console.log(id) + // console.log(id) if(id) { json.list = [...json.list, { id: id,