自定义的时间轴组件对录像记录进行加载渲染,播放器回调时间与下面时间轴相互联动,集拖动、点击、缩放、无限加载等于一体的时间轴组件。
let times = [
{
begin: new Date(new Date('2022-04-14 11:30:00')).getTime(),
end: new Date(new Date('2022-04-14 17:00:00')).getTime()
},
{
begin: new Date(new Date('2022-04-14 17:01:00')).getTime(),
end: new Date(new Date('2022-04-14 19:00:00')).getTime()
}
]
let TimeAxis = new TimeLine({
dom: document.getElementById('timeline'),
bg: '#000',
date: new Date(new Date('2022-04-14').toLocaleDateString()).getTime(),
cellStyle: {
background: 'rgba(24,208,217,0.5)'
},
timecell: [...times],
callback: (data) => {
// {mode: 触发方式 timestamp: 时间戳 valid: 是否有效}
console.log(data)
this.$emit('changeTime', data)
}
})
this.canvas.addEventListener('contextmenu', (e) => {
e.preventDefault();
});
this.canvas.addEventListener('mousemove', this.canvasMousemoveFunc.bind(this));
// 滚轮事件
this.canvas.addEventListener('mousewheel', this.mousewheelFunc.bind(this));
this.canvas.addEventListener('mousedown', this.mousedownFunc.bind(this));
this.canvas.addEventListener('mouseup', this.mouseupFunc.bind(this));
this.canvas.addEventListener('mouseout', this.mouseoutFunc.bind(this));
this.canvas.addEventListener('click', this.clickFunc.bind(this));
let times = [
{
begin: new Date(new Date('2022-04-14 11:30:00')).getTime(),
end: new Date(new Date('2022-04-14 17:00:00')).getTime(),
style: {
background: 'rgba(172,17,189,0.5)'
}
}
]
cellStyle: {
background: 'rgba(24,208,217,0.5)'
},
bg: '#000',
this.canvas.addEventListener('mousewheel', this.mousewheelFunc.bind(this));
mousewheelFunc(event) {
if (event && event.preventDefault) {
event.preventDefault()
} else {
window.event.returnValue = false;
return false;
}
let e = window.event || event;
let delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));
let posX = this.getCursorPositionX(e);
let middle_time = this.date + posX * (this.zoomHours * 3600 * 1000) / (this.canvasWidth); //ms 记住当前中间的时间
if (delta < 0) {
this.zoomHours = this.zoomHours - delta;
if (this.zoomHours >= 24) {
this.zoomHours = 24;//放大最大24小时
}
} else if (delta > 0) {// 放大
this.zoomHours = this.zoomHours - delta;
if (this.zoomHours <= 1) {
this.zoomHours = 1;//缩小最小1小时
}
}
this.clearCanvas();
this.date = middle_time - posX * (this.zoomHours * 3600 * 1000) / (this.canvasWidth);
this.initCanvasCtx()
}