日:{"startDate":"2024-04-07","endDate":"2024-04-07","typeCN":"2024-04-07~2024-04-07"}
周:{"startDate":"2024-04-01","endDate":"2024-04-07","typeCN":"2024年第14周"}
月:{"startDate":"2024-04-01","endDate":"2024-04-08","typeCN":"2024年04月"}
日:{"startDate":"2024-04-07","endDate":"2024-04-07","typeCN":"2024-04-07~2024-04-07"}
<el-date-picker v-model="dayDate" type="daterange" format="yyyy年 MM月 dd日" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
dayDate: [new Date().getTime() - 8.64e7, new Date().getTime() - 8.64e7] //默认值昨天
pickerOptions: {
disabledDate: (time) => {
const t = 365 * 24 * 3600 * 1000
return time.getTime() > Date.now() - 8.64e7 || time.getTime() < Date.now() - 8.64e7 - t
},
},
月:{"startDate":"2024-04-01","endDate":"2024-04-08","typeCN":"2024年04月"}
<el-date-picker v-model="monthDate" type="month" format="yyyy 年 MM 月" :picker-options="monthOption"></el-date-picker>
data(){
return{
monthDate: new Date(),
monthOption: {
disabledDate: (time) => {
return time.getTime() > Date.now()
},
},
},
computed: {
// 月
monthHand() {
if (this.monthDate) {
const year = this.monthDate.getFullYear()
const monthIndex = this.monthDate.getMonth()
const firstDayOfMonth = new Date(year, monthIndex)
const tday = Date.now()
const lday = new Date(year, monthIndex + 1, 0).getTime()
const lastDayOfMonth = tday < lday ? tday : lday
return [moment(firstDayOfMonth).format('YYYY-MM-DD'),moment(lastDayOfMonth).format('YYYY-MM-DD'), moment(firstDayOfMonth).format('YYYY年MM月')]
}
return []
},
}
周:{"startDate":"2024-04-01","endDate":"2024-04-07","typeCN":"2024年第14周"}
<el-date-picker v-model="weekDate" type="week" format="yyyy 第 WW 周" :picker-options="weekOption"></el-date-picker>
data(){
return {
weekDate: new Date() - 7 * 24 * 3600 * 1000,
weekOption: {
disabledDate: (time) => {
return time.getTime() > Date.now()
},
firstDayOfWeek: 1,
},
},
computed:{
weekHand(){
if (this.weekDate) {
const now = new Date(this.weekDate)
const nowTime = now.getTime()
const day = now.getDay()
const oneDayTime = 24 * 60 * 60 * 1000
const sundayTime = nowTime + (7 - day) * oneDayTime
const todayaTime = new Date().getTime()
const startDate = moment(this.weekDate).startOf('week').add(1, 'days')
const endDate = todayaTime < sundayTime ? todayaTime : sundayTime
return [moment(startDate ).format('YYYY-MM-DD'), moment(endDate ).format('YYYY-MM-DD'), moment(startDate).format('YYYY年第W周')]
}
return []
},
}
}