Skip to content

Commit

Permalink
fix loading last page at read page
Browse files Browse the repository at this point in the history
  • Loading branch information
sunyuting committed Mar 29, 2020
1 parent 546bc26 commit 42d4998
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
23 changes: 21 additions & 2 deletions src/components/Read/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</header>
<div>
<ul class="row" v-for="(item,index) in list" :key="index" @click="getData(index,item.id)">
<li class="col listitle" :style="pageId === index? 'color:#842424':null">{{item.title}}</li>
<li class="col listitle" :style="thisid === index? 'color:#842424':null">{{item.title}}</li>
</ul>
</div>
</div>
Expand All @@ -34,7 +34,8 @@ export default {
data() {
return {
list: this.menuList,
sort: this.thisSort
sort: this.thisSort,
thisid: 0
}
},
methods: {
Expand All @@ -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
}
}
}
}
}
</script>
48 changes: 37 additions & 11 deletions src/components/Read/Read.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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',
Expand All @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/helper/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 42d4998

Please sign in to comment.