3 changed files with 209 additions and 44 deletions
-
44src/views/lengingRanking/index.vue
-
162src/views/lengingRanking/index2.vue
-
47src/views/readStar/index.vue
@ -0,0 +1,162 @@ |
|||
<template> |
|||
<!-- 借阅排行榜 --> |
|||
<div class="screen-item lending-ranking"> |
|||
<div class="common-title">借阅排行榜</div> |
|||
<vue-seamless-scroll |
|||
ref="listData" |
|||
:data="rankingList" |
|||
:class-option="defaultOption" |
|||
class="big-module module-content" |
|||
> |
|||
<div |
|||
v-for="(item, index) in rankingList" |
|||
:key="index" |
|||
class="book-list-item" |
|||
> |
|||
<div class="book-img"> |
|||
<img :src="item.cover" :onerror="defaultImg"> |
|||
</div> |
|||
<div class="book-info"> |
|||
<h4 class="title-item">{{ item.TITLE }}</h4> |
|||
<p>{{ item.AUTHOR }}</p> |
|||
</div> |
|||
<div class="ranking-num"> |
|||
<svg v-if="index === 0" class="icon" aria-hidden="true"> |
|||
<use xlink:href="#icon-a-no1" /> |
|||
</svg> |
|||
<svg v-if="index === 1" class="icon" aria-hidden="true"> |
|||
<use xlink:href="#icon-a-no21" /> |
|||
</svg> |
|||
<svg v-if="index === 2" class="icon" aria-hidden="true"> |
|||
<use xlink:href="#icon-a-no3" /> |
|||
</svg> |
|||
<p>NO.{{ index + 1 }}</p> |
|||
</div> |
|||
</div> |
|||
</vue-seamless-scroll> |
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
import { FetchBorrowRank, FetchCoverByISBN, FetchSync36 } from '@/api/library' |
|||
|
|||
export default { |
|||
name: 'LengingRanking', |
|||
data() { |
|||
return { |
|||
defaultImg: 'this.src="' + require('@/assets/images/default-img.png') + '"', |
|||
rankingList: [] |
|||
} |
|||
}, |
|||
computed: { |
|||
defaultOption() { |
|||
return { |
|||
step: 1.1, // 滚动的速度 |
|||
hoverStop: false, // 是否开启鼠标悬停stop |
|||
singleHeight: 102, // 单步运动停止的高度(默认值0是无缝不停止的滚动) direction => 0/1 |
|||
openWatch: true, |
|||
waitTime: 2000 // 单步运动停止的时间(默认值1000ms) |
|||
} |
|||
} |
|||
}, |
|||
created() { |
|||
this.getBookRanking() |
|||
}, |
|||
mounted() { |
|||
}, |
|||
methods: { |
|||
getBorrowRank() { |
|||
FetchBorrowRank().then((res) => { |
|||
if (res.errCode === 0) { |
|||
this.rankingList = res.data |
|||
this.rankingList.forEach(item => { |
|||
this.getCoverByISBN(item.isbn.replace(/\-/g, ''), item) |
|||
}) |
|||
} else { |
|||
this.$message.error('接口错误') |
|||
} |
|||
}) |
|||
}, |
|||
formatDateTime(date, type) { |
|||
const year = date.getFullYear() |
|||
const month = String(date.getMonth() + 1).padStart(2, '0') |
|||
const day = String(date.getDate()).padStart(2, '0') |
|||
|
|||
let timePart = '00:00:00' |
|||
if (type === 'end') { |
|||
timePart = '23:59:59' |
|||
} |
|||
|
|||
return `${year}-${month}-${day} ${timePart}` |
|||
}, |
|||
getBookRanking() { |
|||
// const currentDate = new Date() // 获取当前日期 |
|||
// currentDate.setDate(currentDate.getDate() - 30) // 将当前日期减去30天 |
|||
// const year = currentDate.getFullYear() // 获取年份 |
|||
// const month = currentDate.getMonth() + 1 // 获取月份(注意月份从0开始,需要加1) |
|||
// const day = currentDate.getDate() // 获取日期 |
|||
// const formattedDate = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}` |
|||
|
|||
// const params = { |
|||
// 'libcode': this.libcode, |
|||
// 'starttime': formattedDate, |
|||
// 'endtime': this.getFormattedDate(new Date()), |
|||
// 'rownum': 10 |
|||
// } |
|||
|
|||
// 获取当前日期 |
|||
const currentDate = new Date() |
|||
currentDate.setDate(currentDate.getDate() - 30) // 将当前日期减去30天 |
|||
|
|||
// 获取开始日期(格式:YYYY-MM-DD 00:00:00) |
|||
const startDate = encodeURIComponent(this.formatDateTime(currentDate, 'start')) |
|||
|
|||
// 获取结束日期(格式:YYYY-MM-DD 23:59:59) |
|||
const endDate = encodeURIComponent(this.formatDateTime(new Date(), 'end')) |
|||
|
|||
const params = { |
|||
'libcode': this.libcode, |
|||
'starttime': startDate, |
|||
'endtime': endDate, |
|||
'rownum': 10 |
|||
} |
|||
|
|||
FetchSync36(params).then(res => { |
|||
const result = JSON.parse(res.data) |
|||
if (result.success && result.resultlist.length > 0) { |
|||
let data = [] |
|||
data = result.resultlist.sort((a, b) => b.TOTALNUM - a.TOTALNUM).slice(0, 10) |
|||
data.forEach(item => { |
|||
this.getCoverByISBN(item.ISBN.replace(/\-/g, ''), item) |
|||
}) |
|||
} else { |
|||
throw new Error('Failed' + this.libcode) |
|||
} |
|||
}).catch(error => { |
|||
console.error('Error', error) |
|||
}) |
|||
}, |
|||
getCoverByISBN(isbn, item) { |
|||
const params = { |
|||
isbn: isbn |
|||
} |
|||
FetchCoverByISBN(params).then((res) => { |
|||
console.log('RES', res) |
|||
if (res) { |
|||
item.cover = res |
|||
} else { |
|||
item.cover = '' |
|||
} |
|||
console.log(item.cover) |
|||
this.rankingList.push(item) |
|||
console.log('this.rankingList', this.rankingList) |
|||
this.$refs.listData.reset() |
|||
}) |
|||
} |
|||
} |
|||
} |
|||
</script> |
|||
|
|||
<style lang="scss"> |
|||
@import '~@/assets/styles/index.scss'; |
|||
</style> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue