Browse Source

借阅排行榜排序问题

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