Browse Source

获取上周时间修改

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

43
src/views/readStar/index.vue

@ -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() 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 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()
//
// 65
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]
} }
} }
} }

Loading…
Cancel
Save