Browse Source

获取上周时间修改

master
xuhuajiao 8 months ago
parent
commit
6551dc1b97
  1. 167
      src/views/readStar/index.vue

167
src/views/readStar/index.vue

@ -1,74 +1,93 @@
<template>
<!-- 新书推荐 -->
<div class="screen-item read-star">
<div class="common-title">阅读之星</div>
<div ref="starList" class="medium-module module-content">
<div v-for="(item,index) in readstarList" :key="index" :class="['readstart-item', {'star1-bg':index === 0}, {'star2-bg':index === 1}, {'star3-bg':index === 2}]">
<svg v-if="index === 0" class="icon icon-star-1" aria-hidden="true">
<use xlink:href="#icon-a-1" />
</svg>
<svg v-else-if="index === 1" class="icon icon-star-2" aria-hidden="true">
<use xlink:href="#icon-a-21" />
</svg>
<svg v-else-if="index === 2" class="icon icon-star-3" aria-hidden="true">
<use xlink:href="#icon-a-3" />
</svg>
<span v-else class="star-num">{{ index+1 }}</span>
<p class="star-info title-item"> 读者{{ item.readerName }}上周借阅图书{{ item.borrowNum }}</p>
<p class="star-date">{{ mondayDate }}</p>
</div>
</div>
</div>
</template>
<script>
import { FetchBorrowStar } from '@/api/library'
import { parseTime } from '@/utils/index.js'
export default {
name: 'ReadStar',
data() {
return {
readstarList: [],
mondayDate: null
}
},
created() {
},
mounted() {
this.getBorrowStar()
},
methods: {
// list
getBorrowStar() {
FetchBorrowStar().then(res => {
if (res.errCode === 0) {
console.log(res)
this.readstarList = res.data
this.getMondayTime()
} else {
this.$message.error('接口错误')
}
})
},
//
getMondayTime() {
const today = new Date()
const year = today.getFullYear()
const month = today.getMonth() + 1
const day = today.getDate()
const newDate = new Date(year + '-' + month + '-' + day + ' 00:00:00')
const nowTime = newDate.getTime()
const weekDay = newDate.getDay()
const oneDayTime = 24 * 60 * 60 * 1000
const mondayTime = (1 - weekDay) * oneDayTime + nowTime
this.mondayDate = parseTime(mondayTime, '{y}-{m}-{d}')
}
}
}
</script>
<style lang="scss">
@import "~@/assets/styles/index.scss";
</style>
<template>
<!-- 新书推荐 -->
<div class="screen-item read-star">
<div class="common-title">阅读之星</div>
<div ref="starList" class="medium-module module-content">
<div v-for="(item,index) in readstarList" :key="index" :class="['readstart-item', {'star1-bg':index === 0}, {'star2-bg':index === 1}, {'star3-bg':index === 2}]">
<svg v-if="index === 0" class="icon icon-star-1" aria-hidden="true">
<use xlink:href="#icon-a-1" />
</svg>
<svg v-else-if="index === 1" class="icon icon-star-2" aria-hidden="true">
<use xlink:href="#icon-a-21" />
</svg>
<svg v-else-if="index === 2" class="icon icon-star-3" aria-hidden="true">
<use xlink:href="#icon-a-3" />
</svg>
<span v-else class="star-num">{{ index+1 }}</span>
<p class="star-info title-item"> 读者{{ item.readerName }}上周借阅图书{{ item.borrowNum }}</p>
<p class="star-date">{{ mondayDate }}</p>
</div>
</div>
</div>
</template>
<script>
import { FetchBorrowStar } from '@/api/library'
// import { parseTime } from '@/utils/index.js'
export default {
name: 'ReadStar',
data() {
return {
readstarList: [],
mondayDate: null
}
},
created() {
},
mounted() {
this.getBorrowStar()
},
methods: {
// list
getBorrowStar() {
FetchBorrowStar().then(res => {
if (res.errCode === 0) {
console.log(res)
this.readstarList = res.data
this.getMondayDate()
} else {
this.$message.error('接口错误')
}
})
},
//
// getMondayTime() {
// const today = new Date()
// const year = today.getFullYear()
// const month = today.getMonth() // 0
// const day = today.getDate()
// const newDate = new Date(year, month, day)
// const nowTime = newDate.getTime()
// const weekDay = newDate.getDay() // getDay() 06
// const oneDayTime = 24 * 60 * 60 * 1000
// //
// const daysToMonday = weekDay === 0 ? -6 : 1 - weekDay
// //
// const mondayTime = nowTime - daysToMonday * oneDayTime
// //
// this.mondayDate = this.parseTime(mondayTime, '{y}-{m}-{d}')
// console.log('this.mondayDate', this.mondayDate)
// },
getMondayDate() {
const today = new Date()
const day = today.getDay()
//
// 65
const diff = day === 0 ? -6 : 1 - day
//
today.setDate(today.getDate() + diff)
// --
this.mondayDate = today.toISOString().split('T')[0]
}
}
}
</script>
<style lang="scss">
@import "~@/assets/styles/index.scss";
</style>
Loading…
Cancel
Save