|
@ -23,7 +23,7 @@ |
|
|
|
|
|
|
|
|
<script> |
|
|
<script> |
|
|
import { FetchBorrowStar } from '@/api/library' |
|
|
import { FetchBorrowStar } from '@/api/library' |
|
|
import { parseTime } from '@/utils/index.js' |
|
|
|
|
|
|
|
|
// import { parseTime } from '@/utils/index.js' |
|
|
export default { |
|
|
export default { |
|
|
name: 'ReadStar', |
|
|
name: 'ReadStar', |
|
|
data() { |
|
|
data() { |
|
@ -44,26 +44,45 @@ export default { |
|
|
if (res.errCode === 0) { |
|
|
if (res.errCode === 0) { |
|
|
console.log(res) |
|
|
console.log(res) |
|
|
this.readstarList = res.data |
|
|
this.readstarList = res.data |
|
|
this.getMondayTime() |
|
|
|
|
|
|
|
|
this.getMondayDate() |
|
|
} else { |
|
|
} else { |
|
|
this.$message.error('接口错误') |
|
|
this.$message.error('接口错误') |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
// 获取本周一 |
|
|
// 获取本周一 |
|
|
getMondayTime() { |
|
|
|
|
|
|
|
|
// 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() 返回的是0(周日)到6(周六) |
|
|
|
|
|
// 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 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 day = today.getDay() |
|
|
|
|
|
|
|
|
|
|
|
// 计算当前日期与本周周一之间的天数差 |
|
|
|
|
|
// 如果今天是周日,则差值为6;如果是周六,则差值为5,依此类推 |
|
|
|
|
|
const diff = day === 0 ? -6 : 1 - day |
|
|
|
|
|
|
|
|
const nowTime = newDate.getTime() |
|
|
|
|
|
const weekDay = newDate.getDay() |
|
|
|
|
|
const oneDayTime = 24 * 60 * 60 * 1000 |
|
|
|
|
|
|
|
|
// 减去计算出的天数差,得到本周周一的日期 |
|
|
|
|
|
today.setDate(today.getDate() + diff) |
|
|
|
|
|
|
|
|
const mondayTime = (1 - weekDay) * oneDayTime + nowTime |
|
|
|
|
|
this.mondayDate = parseTime(mondayTime, '{y}-{m}-{d}') |
|
|
|
|
|
|
|
|
// 返回本周周一的日期,格式化为年-月-日 |
|
|
|
|
|
this.mondayDate = today.toISOString().split('T')[0] |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|