添加datetime左侧快捷方式功能,类似elementUI的那种
太棒了!感谢大佬解决我燃眉之急!不过时间范围的处理我又加了一些方法,不足之处欢迎讨论。 `import moment from 'moment'; //快捷时间段 periodList ,这里是我们需要的快捷时间段 this.periodList=[ {name:'近5分钟',key:0,type:'minute',value:-5}, {name:'近30分钟',key:1,type:'minute',value:-30}, {name:'近1小时',key:2,type:'hour',value:-1}, {name:'近6小时',key:3,type:'hour',value:-6}, {name:'近12小时',key:4,type:'hour',value:-12}, {name:'近1天',key:7,type:'day',value:-1}, {name:'近3天',key:8,type:'day',value:-3}, {name:'近7天',key:9,type:'day',value:-7}, ];
//快捷时间段处理方法最终返回一个laydate需要的时间范围
//YYYY-MM-DD HH:mm:ss - YYYY-MM-DD HH:mm:ss
changeCurrentTime(time){
var now = moment().format('YYYY-MM-DD HH:mm:ss');
const start = moment(now);
this.endTime= moment().format('YYYY-MM-DD HH:mm:ss');
this.startTime = moment(start).add(time.value, time.type).format('YYYY-MM-DD HH:mm:ss');
this.getRunStatus();
return ${this.startTime} - ${this.endTime};
}
//laydate实例中的调用方法
laydate.render({
elem: '#timeRange'
,type: 'datetime'
,range: true,
theme: 'laydate-btn-type',
shortcuts:[
{
text: '近30分钟',
onClick:(inst)=> {
inst.setValue(this.changeCurrentTime(this.periodList[1]));
}
},
]
`
好多年提的 PR 了一直卡着,我强迫症给关了,有人需要此功能的话可参考该 PR,工作愉快~ 🫡