Browse Source

借阅排行榜排序问题

master
xuhuajiao 8 hours ago
parent
commit
be701f1f42
  1. 52
      src/views/lengingRanking/index.vue

52
src/views/lengingRanking/index.vue

@ -52,7 +52,9 @@ export default {
data() {
return {
defaultImg: 'this.src="' + require('@/assets/images/default-img.png') + '"',
rankingList: []
rankingList: [],
itemHeight: 102, //
scrollHeight: 0 //
}
},
computed: {
@ -60,7 +62,7 @@ export default {
return {
step: 1.1, //
hoverStop: false, // stop
singleHeight: 102, // (0) direction => 0/1
singleHeight: this.itemHeight, //
openWatch: true,
waitTime: 2000, // (1000ms)
scrollHeight: 0
@ -124,21 +126,40 @@ export default {
getBorrowRank() {
FetchBorrowRank().then((res) => {
if (res.errCode === 0) {
const data = res.data || []
const originData = res.data || []
//
this.rankingList = []
//
const coverPromises = data.map(item => {
// Promise.alloriginData
const coverPromises = originData.map((item, index) => {
const isbn = item.isbn.replace(/\-/g, '')
return this.getCoverByISBN(isbn, item)
// Promise
return new Promise((resolve) => {
const params = { isbn }
FetchCoverByISBN(params).then((cover) => {
resolve(cover || '') //
}).catch(() => {
resolve('') //
})
})
//
Promise.all(coverPromises).then(() => {
})
//
Promise.all(coverPromises).then((coverList) => {
// originDataitem
this.rankingList = originData.map((item, index) => {
return {
...item, //
cover: coverList[index] // indexitemindex
}
})
this.$nextTick(() => {
if (this.$refs.listData) {
this.$refs.listData.reset()
}
})
console.log('和后台顺序一致的列表:', this.rankingList)
})
} else {
this.$message.error('接口错误')
@ -147,21 +168,6 @@ export default {
console.error('获取借阅排行失败', err)
this.$message.error('获取借阅排行失败')
})
},
// Promise便
getCoverByISBN(isbn, item) {
return new Promise((resolve) => {
const params = { isbn }
FetchCoverByISBN(params).then((res) => {
item.cover = res || ''
this.rankingList.push(item)
resolve()
}).catch(() => {
item.cover = ''
this.rankingList.push(item)
resolve()
})
})
}
}
}

Loading…
Cancel
Save