pickerOptions: { disabledDate(time) { return time.getTime() > Date.now(); }, shortcuts: [ { text: '昨日', onClick(picker) { this.relativeTime = 'now-1d' const end = new Date(); const start = new Date(); start.setTime(start.getTime() - 3600 * 1000 * 24 * 1); end.setTime(end.getTime() - 3600 * 1000 * 24 * 1); picker.$emit('pick', [start, end]); console.log(this.relativeTime) } }, { text: '近3日', onClick(picker) { console.log(picker) const end = new Date(); const start = new Date(); start.setTime(start.getTime() - 3600 * 1000 * 24 * 3); end.setTime(end.getTime() - 3600 * 1000 * 24 * 1); picker.$emit('pick', [start, end]); this.relativeTime = 'now-3d' } }, { text: '近7日', onClick(picker) { console.log(picker) const end = new Date(); const start = new Date(); start.setTime(start.getTime() - 3600 * 1000 * 24 * 7); end.setTime(end.getTime() - 3600 * 1000 * 24 * 1); picker.$emit('pick', [start, end]); this.relativeTime = 'now-7d' } }, { text: '近30日', onClick(picker) { const end = new Date(); const start = new Date(); start.setTime(start.getTime() - 3600 * 1000 * 24 * 30); end.setTime(end.getTime() - 3600 * 1000 * 24 * 1); picker.$emit('pick', [start, end]); this.relativeTime = 'now-30d' } }, { text: '近60日', onClick(picker) { const end = new Date(); const start = new Date(); start.setTime(start.getTime() - 3600 * 1000 * 24 * 60); end.setTime(end.getTime() - 3600 * 1000 * 24 * 1); picker.$emit('pick', [start, end]); this.relativeTime = 'now-60d' } }, { text: '近90日', onClick(picker) { const end = new Date(); const start = new Date(); start.setTime(start.getTime() - 3600 * 1000 * 24 * 90); end.setTime(end.getTime() - 3600 * 1000 * 24 * 1); picker.$emit('pick', [start, end]); this.relativeTime = 'now-90d' } }, { text: '近180日', onClick(picker) { const end = new Date(); const start = new Date(); start.setTime(start.getTime() - 3600 * 1000 * 24 * 180); end.setTime(end.getTime() - 3600 * 1000 * 24 * 1); picker.$emit('pick', [start, end]); this.relativeTime = 'now-180d' } }, { text: '近365日', onClick(picker) { const end = new Date(); const start = new Date(); start.setTime(start.getTime() - 3600 * 1000 * 24 * 365); end.setTime(end.getTime() - 3600 * 1000 * 24 * 1); picker.$emit('pick', [start, end]); this.relativeTime = 'now-365d' } }, { text: '近3周', onClick(picker) { const oDate = new Date(); oDate.setTime(oDate.getTime() - 3600 * 1000 * 24 * 21); var day = oDate.getDay() var start = new Date(), end = new Date(); if (day == 0) { start.setDate(oDate.getDate()); end.setDate(oDate.getDate() + 21); } else { start.setTime(oDate.getTime() - 3600 * 1000 * 24 *(day-1)); end.setTime(oDate.getTime() + 3600 * 1000 * 24 * (21- day)); } picker.$emit('pick', [start, end]); this.relativeTime = 'now-3w' } }, { text: '近6周', onClick(picker) { const oDate = new Date(); oDate.setTime(oDate.getTime() - 3600 * 1000 * 24 * 42); var day = oDate.getDay() var start = new Date(), end = new Date(); if (day == 0) { start.setDate(oDate.getDate()); end.setDate(oDate.getDate() + 21); } else { start.setTime(oDate.getTime() - 3600 * 1000 * 24 *(day-1)); end.setTime(oDate.getTime() + 3600 * 1000 * 24 * (42- day)); } picker.$emit('pick', [start, end]); this.relativeTime = 'now-6w' } }, { text: '近12周', onClick(picker) { const oDate = new Date(); oDate.setTime(oDate.getTime() - 3600 * 1000 * 24 * 84); var day = oDate.getDay() var start = new Date(), end = new Date(); if (day == 0) { start.setDate(oDate.getDate()); end.setDate(oDate.getDate() + 21); } else { start.setTime(oDate.getTime() - 3600 * 1000 * 24 *(day-1)); end.setTime(oDate.getTime() + 3600 * 1000 * 24 * (84- day)); } picker.$emit('pick', [start, end]); this.relativeTime = 'now-12w' } }, { text: '近24周', onClick(picker) { const oDate = new Date(); oDate.setTime(oDate.getTime() - 3600 * 1000 * 24 * 168); var day = oDate.getDay() var start = new Date(), end = new Date(); if (day == 0) { start.setDate(oDate.getDate()); end.setDate(oDate.getDate() + 21); } else { start.setTime(oDate.getTime() - 3600 * 1000 * 24 *(day-1)); end.setTime(oDate.getTime() + 3600 * 1000 * 24 * (168- day)); } picker.$emit('pick', [start, end]); this.relativeTime = 'now-24w' } }, { text: '近3个月', onClick(picker) { const oDate = new Date(); var year = oDate.getFullYear(); var month = oDate.getMonth(); var start, end; if (month == 0) { year-- start = new Date(year, 11, 1) end = new Date(year, 11, 31) } else { start = new Date(year, month - 3, 1) end = new Date(year, month, 0); } picker.$emit('pick', [start, end]); this.relativeTime = 'now-3m' } }, { text: '近6个月', onClick(picker) { const oDate = new Date(); var year = oDate.getFullYear(); var month = oDate.getMonth(); var start, end; if (month == 0) { year-- start = new Date(year, 11, 1) end = new Date(year, 11, 31) } else { start = new Date(year, month - 6, 1) end = new Date(year, month, 0); } picker.$emit('pick', [start, end]); this.relativeTime = 'now-6m' } }, { text: '近12个月', onClick(picker) { const oDate = new Date(); var year = oDate.getFullYear(); var month = oDate.getMonth(); var start, end; if (month == 0) { year-- start = new Date(year, 11, 1) end = new Date(year, 11, 31) } else { start = new Date(year, month - 12, 1) end = new Date(year, month, 0); } picker.$emit('pick', [start, end]); this.relativeTime = 'now-12m' } }, { text: '近24个月', onClick(picker) { const oDate = new Date(); var year = oDate.getFullYear(); var month = oDate.getMonth(); var start, end; if (month == 0) { year-- start = new Date(year, 11, 1) end = new Date(year, 11, 31) } else { start = new Date(year, month - 24, 1) end = new Date(year, month, 0); } picker.$emit('pick', [start, end]); this.relativeTime = 'now-24m' } }, { text: '月至今', onClick(picker) { let date = new Date() if (date.getDate() == 1) { const oDate = new Date(); let year = oDate.getFullYear(); let month = oDate.getMonth(); let start, end; if (month == 0) { year-- start = new Date(year, 11, 1) end = new Date(year, 11, 31) } else { start = new Date(year, month - 1, 1) end = new Date(year, month, 0); } picker.$emit('pick', [start, end]); this.relativeTime = 'far1' } else { const end = new Date(); const start = new Date(); start.setDate(1); end.setTime(end.getTime() - 3600 * 1000 * 24 * 1); picker.$emit('pick', [start, end]); this.relativeTime = 'far1' } } }, { text: '年至今', onClick(picker) { const end = new Date(); const start = new Date(); start.setMonth(0); start.setDate(1); end.setTime(end.getTime() - 3600 * 1000 * 24 * 1); picker.$emit('pick', [start, end]); this.relativeTime = 'far12' } }, ]
element-ui 日期选择器快捷时间
最新推荐文章于 2024-08-20 14:12:03 发布