时间选择范围上下时段
This commit is contained in:
@ -62,15 +62,17 @@ export default {
|
||||
this.$emit('updateDate',this.dateRange)
|
||||
},
|
||||
timeLine(type){
|
||||
if(!this.dateRange || !this.dateRange[0] || !this.dateRange[1]) return
|
||||
const nowStartTimes = new Date(this.dateRange[0]).getTime(),nowEndTimes = new Date(this.dateRange[1]).getTime(),maxTime = new Date(this.defaultDateRange[1]).getTime()
|
||||
const nowDis = nowEndTimes - nowStartTimes//用户当前选择时间差 可能=0
|
||||
//baseTime,maxTime 毫秒数
|
||||
let baseTime = type === 'before' ? new Date(this.dateRange[0]).getTime() - ( 24 * 60 * 60 * 1000) :new Date(this.dateRange[1]).getTime() + ( 24 * 60 * 60 * 1000) ,
|
||||
maxTime = new Date(this.defaultDateRange[1]).getTime()
|
||||
//updateTime 毫秒数
|
||||
let updateTime = type === 'before' ? baseTime - 7 * 24 * 60 * 60 * 1000 : baseTime + 7 * 24 * 60 * 60 * 1000
|
||||
if(type === 'next' && updateTime >= maxTime) updateTime = maxTime
|
||||
const start = formatDate(type === 'before' ? updateTime : baseTime)
|
||||
const end = formatDate(type === 'before' ? baseTime : updateTime)
|
||||
this.dateRange = [start,end]
|
||||
const baseDis = this.dataUnit === 3 ? 24 * 60 * 60 * 1000 :this.dataUnit === 2 ? 60 * 60 * 1000 : 60 * 1000
|
||||
const calcDis = nowDis === 0 ? baseDis : nowDis
|
||||
let start = type === 'before' ? nowStartTimes - calcDis : nowStartTimes + calcDis
|
||||
start = Math.min(start,maxTime)
|
||||
let end = type === 'before' ? nowEndTimes - calcDis : nowEndTimes + calcDis
|
||||
end = Math.min(end,maxTime)
|
||||
this.dateRange = [formatDate(start,this.dataUnit !== 3),formatDate(end,this.dataUnit !== 3)]
|
||||
this.$emit('updateDate',this.dateRange)
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user