time-axis-plus 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +348 -0
- package/index.cjs +2 -0
- package/index.es.js +896 -0
- package/index.umd.js +2 -0
- package/package.json +23 -0
package/index.es.js
ADDED
|
@@ -0,0 +1,896 @@
|
|
|
1
|
+
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".timeline-group[data-v-b90b2c6f]{font-size:0}.timeline-group .timeline-canvas[data-v-b90b2c6f]{background-color:#2b2f33}.timeline-group canvas[data-v-b90b2c6f]{display:block;touch-action:none}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
|
|
2
|
+
import { openBlock as x, createElementBlock as T, normalizeStyle as b } from "vue";
|
|
3
|
+
const y = {
|
|
4
|
+
borderColor: "rgb(151, 158, 167)",
|
|
5
|
+
// 上下边框线
|
|
6
|
+
graduationColor: "rgba(151, 158, 167, 1)",
|
|
7
|
+
// 刻度线
|
|
8
|
+
tickTextColor: "#ffffff",
|
|
9
|
+
// 刻度文字
|
|
10
|
+
hoverLineColor: "rgb(194, 202, 215)",
|
|
11
|
+
// 悬浮十字线
|
|
12
|
+
hoverTextColor: "rgb(0, 255, 0)",
|
|
13
|
+
// 悬浮时间文字
|
|
14
|
+
overviewBg: "rgb(43, 47, 51)",
|
|
15
|
+
// 概览条背景
|
|
16
|
+
overviewTickColor: "rgba(151, 158, 167, 0.35)",
|
|
17
|
+
// 概览条小时参考刻度
|
|
18
|
+
overviewWindowColor: "rgba(64, 196, 255, 0.15)",
|
|
19
|
+
// 概览条可视窗口填充
|
|
20
|
+
overviewWindowBorder: "rgb(64, 196, 255)",
|
|
21
|
+
// 概览条可视窗口描边
|
|
22
|
+
overviewPlayColor: "rgb(255, 92, 92)"
|
|
23
|
+
// 概览条播放位置线
|
|
24
|
+
};
|
|
25
|
+
class C {
|
|
26
|
+
constructor(t) {
|
|
27
|
+
if (!t)
|
|
28
|
+
throw new Error("timeAxis: options is required");
|
|
29
|
+
let e = typeof t.container == "string" ? document.getElementById(t.container) : t.container;
|
|
30
|
+
if (!e)
|
|
31
|
+
throw new Error("timeAxis: options.container is required(DOM 元素或 id 字符串)");
|
|
32
|
+
let i = {
|
|
33
|
+
visibleHours: 24,
|
|
34
|
+
minVisibleHours: 0.02,
|
|
35
|
+
// 可见时长下限(小时),即放大极限(可放大到秒级刻度)
|
|
36
|
+
maxVisibleHours: 24,
|
|
37
|
+
// 可见时长上限(小时),即缩小极限
|
|
38
|
+
graduationMinStep: 10,
|
|
39
|
+
// 可选刻度步长(秒),均能整除 86400;
|
|
40
|
+
// 步长按"相邻文字刻度间格数为 5 的倍数"挑选:
|
|
41
|
+
// 秒级 1/2/6/12 → 每分钟 60/30/10/5 格;分钟级 60~720 → 每小时 60/30/15/10/5 格
|
|
42
|
+
secondsPerStep: [1, 2, 6, 12, 60, 120, 240, 360, 720, 3600, 7200, 14400, 21600, 43200, 86400],
|
|
43
|
+
segmentStyle: {
|
|
44
|
+
background: "rgba(24,208,217,0.5)"
|
|
45
|
+
},
|
|
46
|
+
pointerOptions: {
|
|
47
|
+
beginY: 0,
|
|
48
|
+
endY: 30,
|
|
49
|
+
color: "rgb(64, 196, 255)",
|
|
50
|
+
width: 2
|
|
51
|
+
},
|
|
52
|
+
// 可视边界(毫秒时间戳),null 表示不限制
|
|
53
|
+
minTime: null,
|
|
54
|
+
maxTime: null,
|
|
55
|
+
// 轴起始时间(ms 时间戳),默认当天 0 点
|
|
56
|
+
startTime: this.dayStartOf(Date.now()),
|
|
57
|
+
// 画布背景色
|
|
58
|
+
backgroundColor: "#000",
|
|
59
|
+
// 点击空白区域时是否吸附到最近录像片段起点
|
|
60
|
+
snapToNearest: !1,
|
|
61
|
+
// 是否显示悬浮十字线与时间提示(移动端无悬浮场景,由组件按设备决定默认值)
|
|
62
|
+
hoverTip: !0,
|
|
63
|
+
// 播放指针居中:开启后播放推进(updateTime)时自动滚动视口,让指针固定在画布中央
|
|
64
|
+
centerPointer: !1,
|
|
65
|
+
// 居中让位恢复延迟(ms):手势暂停居中后,停止操作超过该时长自动恢复居中跟随
|
|
66
|
+
centerResumeDelay: 3e3,
|
|
67
|
+
// 双进度条:底部全天概览条(显示片段分布、可视窗口与播放位置,点击/拖动可跳转)
|
|
68
|
+
overview: !1,
|
|
69
|
+
overviewHeight: 20,
|
|
70
|
+
// 概览条高度(px)
|
|
71
|
+
overviewGap: 4,
|
|
72
|
+
// 概览条与时间轴的间距(px)
|
|
73
|
+
overviewStart: null,
|
|
74
|
+
// 概览范围起始时间(ms),null 自动推导
|
|
75
|
+
overviewEnd: null,
|
|
76
|
+
// 概览范围结束时间(ms),null 自动推导
|
|
77
|
+
// 有效时间区域 [{begin, end, style?}],内部会规范化去重叠
|
|
78
|
+
segments: []
|
|
79
|
+
};
|
|
80
|
+
this.options = Object.assign({}, i, t), this.options.container = e, this.options.visibleHours = Math.min(this.options.maxVisibleHours, Math.max(this.options.minVisibleHours, this.options.visibleHours)), this.configMinVisibleHours = this.options.minVisibleHours, this.options.segments = this.normalizeSegments(this.options.segments), this.options.segments.length && (this.currentTimestamp = this.options.segments[0].begin), this.options.segmentStyle && this.options.segmentStyle.background || (this.options.segmentStyle = {
|
|
81
|
+
background: "rgba(24,208,217,0.5)"
|
|
82
|
+
}), this.options.axisStyle = Object.assign({}, y, this.options.axisStyle || {}), this.options.startTime = this.clampStartTime(this.options.startTime), this.options.overviewStart == null && (this.options.overviewStart = this.options.minTime != null ? this.options.minTime : this.dayStartOf(this.options.startTime)), this.options.overviewEnd == null && (this.options.overviewEnd = this.options.maxTime != null ? this.options.maxTime : this.options.overviewStart + 24 * 60 * 60 * 1e3), this.isClick = !1, this.button = 0, this.isPressDown = !1, this.isDragPointer = !1, this.currentChecked = "", this.pinchStartDistance = 0, this.hoverState = null, this.centerPaused = !1, this.lastInteractTime = 0, this.initCanvas(), this.drawStatic();
|
|
83
|
+
}
|
|
84
|
+
initCanvas() {
|
|
85
|
+
this.options.container.style.position = "relative", this.canvas = document.createElement("canvas"), this.canvas.style.position = "absolute", this.canvas.style.left = "0", this.canvas.style.top = "0", this.overlayCanvas = document.createElement("canvas"), this.overlayCanvas.style.position = "absolute", this.overlayCanvas.style.left = "0", this.overlayCanvas.style.top = "0", this.options.container.appendChild(this.canvas), this.options.container.appendChild(this.overlayCanvas), this.canvasCtx = this.canvas.getContext("2d"), this.overlayCtx = this.overlayCanvas.getContext("2d"), this.options.overview && this.mountOverview(), this.initCanvasSize(), this.canvas.style.backgroundColor = this.options.backgroundColor, this.initEvents();
|
|
86
|
+
}
|
|
87
|
+
// 设置画布尺寸(按设备像素比放大缓冲,修复高分屏/移动端文字与线条发虚)
|
|
88
|
+
initCanvasSize() {
|
|
89
|
+
let t = window.devicePixelRatio || 1, e = this.options.container.clientWidth, i = this.options.container.clientHeight, s = this.options.overview ? Math.max(0, i - this.options.overviewHeight - this.options.overviewGap) : i, o = (a, u, v) => {
|
|
90
|
+
a.width = Math.round(e * t), a.height = Math.round(v * t), a.style.width = e + "px", a.style.height = v + "px", u.setTransform(t, 0, 0, t, 0, 0);
|
|
91
|
+
};
|
|
92
|
+
o(this.canvas, this.canvasCtx, s), o(this.overlayCanvas, this.overlayCtx, s), this.overviewCanvas && (o(this.overviewCanvas, this.overviewCtx, this.options.overviewHeight), this.overviewCanvas.style.top = s + this.options.overviewGap + "px"), this.canvasWidth = e, this.canvasHeight = s, this.options.minVisibleHours = Math.min(
|
|
93
|
+
this.configMinVisibleHours,
|
|
94
|
+
this.canvasWidth / (this.options.graduationMinStep + 2) / 3600
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
resize() {
|
|
98
|
+
this.initCanvasSize(), this.drawStatic();
|
|
99
|
+
}
|
|
100
|
+
// 重绘静态层(视野/数据变化时调用)
|
|
101
|
+
drawStatic() {
|
|
102
|
+
this.pxPerMs = this.canvasWidth / (this.options.visibleHours * 60 * 60 * 1e3), this.clearCanvas(), this.initBorders(), this.initSegments(this.options.segments || []), this.initGraduationsLines(this.options.startTime), this.drawOverlay();
|
|
103
|
+
}
|
|
104
|
+
// 重绘动态层(播放跟随/悬浮等高频场景只走这里)
|
|
105
|
+
drawOverlay() {
|
|
106
|
+
if (this.clearOverlay(), this.options.hoverTip && this.hoverState) {
|
|
107
|
+
let { x: t, time: e } = this.hoverState;
|
|
108
|
+
this.drawLine(this.overlayCtx, {
|
|
109
|
+
beginX: t,
|
|
110
|
+
beginY: 0,
|
|
111
|
+
endX: t,
|
|
112
|
+
endY: this.canvasHeight,
|
|
113
|
+
color: this.options.axisStyle.hoverLineColor,
|
|
114
|
+
width: 1,
|
|
115
|
+
center: !0
|
|
116
|
+
// 线中心对准悬浮文字所在的时间坐标
|
|
117
|
+
}), this.overlayCtx.fillStyle = this.options.axisStyle.hoverTextColor, this.overlayCtx.textAlign = "center", this.overlayCtx.font = "normal normal 12px Arial,sans-serif", this.overlayCtx.fillText(this.formatDate("yyyy-MM-dd hh:mm:ss", e), t, 18);
|
|
118
|
+
}
|
|
119
|
+
this.isClick && this.currentTimestamp != null && this.drawPointer(), this.drawOverview();
|
|
120
|
+
}
|
|
121
|
+
// 初始化边框
|
|
122
|
+
initBorders() {
|
|
123
|
+
let t = this.options.axisStyle.borderColor;
|
|
124
|
+
this.drawLine(this.canvasCtx, {
|
|
125
|
+
beginX: 0,
|
|
126
|
+
beginY: 0,
|
|
127
|
+
endX: this.canvasWidth,
|
|
128
|
+
endY: 0,
|
|
129
|
+
color: t,
|
|
130
|
+
width: 1
|
|
131
|
+
}), this.drawLine(this.canvasCtx, {
|
|
132
|
+
beginX: 0,
|
|
133
|
+
beginY: this.canvasHeight,
|
|
134
|
+
endX: this.canvasWidth,
|
|
135
|
+
endY: this.canvasHeight,
|
|
136
|
+
color: t,
|
|
137
|
+
width: 1
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
// 画线(默认奇数宽度 +0.5 半像素对齐,保证边框等整数坐标线清晰不发虚;
|
|
141
|
+
// 刻度/指针/悬浮线等按时间定位的竖线传 center: true,线中心严格落在给定坐标上,
|
|
142
|
+
// 确保 1px 细刻度、2px 文字刻度与文字标签三者对齐)
|
|
143
|
+
drawLine(t, { beginX: e, beginY: i, endX: s, endY: o, color: a, width: u, center: v }) {
|
|
144
|
+
let h = !v && u % 2 === 1 ? 0.5 : 0;
|
|
145
|
+
t.beginPath(), t.moveTo(e + h, i + h), t.lineTo(s + h, o + h), t.strokeStyle = a, t.lineWidth = u, t.stroke();
|
|
146
|
+
}
|
|
147
|
+
// 有效时间区域
|
|
148
|
+
initSegments(t) {
|
|
149
|
+
t.forEach((e, i) => {
|
|
150
|
+
this.drawSegment(e, i);
|
|
151
|
+
}), this.canvasCtx.font = "normal normal 12px Arial,sans-serif", this.canvasCtx.fillStyle = this.options.axisStyle.tickTextColor;
|
|
152
|
+
}
|
|
153
|
+
// 填充时间段
|
|
154
|
+
drawSegment(t, e) {
|
|
155
|
+
let i = this.options.segmentStyle.background;
|
|
156
|
+
t.style && t.style.background && (i = t.style.background);
|
|
157
|
+
let s = this.pxPerMs * (t.begin - this.options.startTime), o = (t.end - t.begin) * this.pxPerMs;
|
|
158
|
+
this.canvasCtx.fillStyle = i, this.canvasCtx.font = "normal normal 12px Arial,sans-serif", this.canvasCtx.fillRect(s, 0, o, this.canvasHeight), this.canvasCtx.fillStyle = this.options.axisStyle.tickTextColor;
|
|
159
|
+
}
|
|
160
|
+
// 初始化刻度线(步长自适应,最小可到 1 秒)
|
|
161
|
+
initGraduationsLines(t) {
|
|
162
|
+
let e = this.canvasWidth, i = e / (this.options.visibleHours * 60 * 60), s = this.options.graduationMinStep / i, o = this.options.secondsPerStep.find((l) => l > s), a = o * i, u = e / a, v = this.ms_to_next_step(t, o), h = v * this.pxPerMs, r = o < 60 && i * 60 >= 50;
|
|
163
|
+
for (let l = 0; l <= u; l++) {
|
|
164
|
+
let m = t + v + l * o * 1e3, d = h + l * a, c = new Date(Math.round(m)), f = 10, g = 1;
|
|
165
|
+
if (c.getHours() === 0 && c.getMinutes() === 0 && c.getSeconds() === 0) {
|
|
166
|
+
f = 24, g = 2;
|
|
167
|
+
let p = this.formatDate("MM-dd", m);
|
|
168
|
+
this.canvasCtx.textAlign = "center", this.canvasCtx.fillStyle = this.options.axisStyle.tickTextColor, this.canvasCtx.font = "normal normal 12px Arial,sans-serif", this.canvasCtx.fillText(p, d, 34);
|
|
169
|
+
} else if (c.getMinutes() === 0 && c.getSeconds() === 0) {
|
|
170
|
+
f = 19, g = 2;
|
|
171
|
+
let p = this.formatDate(o < 60 ? "hh:mm:ss" : "hh:mm", m);
|
|
172
|
+
this.canvasCtx.fillStyle = this.options.axisStyle.tickTextColor, this.canvasCtx.textAlign = "center", this.canvasCtx.font = "normal normal 12px Arial,sans-serif", this.canvasCtx.fillText(p, d, 29);
|
|
173
|
+
} else if (r && c.getSeconds() === 0) {
|
|
174
|
+
f = 14, g = 2;
|
|
175
|
+
let p = this.formatDate("hh:mm:ss", m);
|
|
176
|
+
this.canvasCtx.fillStyle = this.options.axisStyle.tickTextColor, this.canvasCtx.textAlign = "center", this.canvasCtx.font = "normal normal 12px Arial,sans-serif", this.canvasCtx.fillText(p, d, 24);
|
|
177
|
+
}
|
|
178
|
+
this.drawLine(this.canvasCtx, {
|
|
179
|
+
beginX: d,
|
|
180
|
+
beginY: 0,
|
|
181
|
+
endX: d,
|
|
182
|
+
endY: f,
|
|
183
|
+
color: this.options.axisStyle.graduationColor,
|
|
184
|
+
width: g,
|
|
185
|
+
center: !0
|
|
186
|
+
// 1px 细刻度与 2px 文字刻度中心统一落在 leftPx
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
// 绘制播放指针(动态层;三角箭头为最后绘制的 path,供 isPointInPath 命中判定)
|
|
191
|
+
drawPointer() {
|
|
192
|
+
let t = this.pxPerMs * (this.currentTimestamp - this.options.startTime), e = this.overlayCtx;
|
|
193
|
+
e.beginPath(), e.moveTo(t, 0), e.lineTo(t, this.options.pointerOptions.endY), e.strokeStyle = this.options.pointerOptions.color, e.lineWidth = this.options.pointerOptions.width, e.stroke(), e.beginPath();
|
|
194
|
+
let i = 12 / Math.sin(Math.PI / 3.5);
|
|
195
|
+
e.moveTo(t, this.options.pointerOptions.endY - 1), e.lineTo(t - i / 2, 40), e.lineTo(t + i / 2, 40), e.closePath(), e.fillStyle = this.options.pointerOptions.color, e.fill();
|
|
196
|
+
}
|
|
197
|
+
// 时间戳所在日期的 0 点
|
|
198
|
+
dayStartOf(t) {
|
|
199
|
+
let e = new Date(t);
|
|
200
|
+
return e.setHours(0, 0, 0, 0), e.getTime();
|
|
201
|
+
}
|
|
202
|
+
// 绘制全天概览条(片段分布、当前可视窗口、播放指针位置)
|
|
203
|
+
drawOverview() {
|
|
204
|
+
if (!this.overviewCanvas)
|
|
205
|
+
return;
|
|
206
|
+
let t = this.overviewCtx, e = this.canvasWidth, i = this.options.overviewHeight;
|
|
207
|
+
t.clearRect(0, 0, e, i);
|
|
208
|
+
let s = this.options.overviewEnd - this.options.overviewStart;
|
|
209
|
+
if (s <= 0)
|
|
210
|
+
return;
|
|
211
|
+
let o = e / s;
|
|
212
|
+
t.fillStyle = this.options.axisStyle.overviewBg, t.fillRect(0, 0, e, i), t.strokeStyle = this.options.axisStyle.overviewTickColor, t.lineWidth = 1;
|
|
213
|
+
let a = 60 * 60 * 1e3;
|
|
214
|
+
for (let r = this.dayStartOf(this.options.overviewStart); r <= this.options.overviewEnd; r += a) {
|
|
215
|
+
if (r < this.options.overviewStart)
|
|
216
|
+
continue;
|
|
217
|
+
let l = (r - this.options.overviewStart) * o;
|
|
218
|
+
t.beginPath(), t.moveTo(l, 0), t.lineTo(l, 4), t.stroke();
|
|
219
|
+
}
|
|
220
|
+
let u = i / 2 - 3;
|
|
221
|
+
(this.options.segments || []).forEach((r) => {
|
|
222
|
+
let l = Math.max(r.begin, this.options.overviewStart), m = Math.min(r.end, this.options.overviewEnd);
|
|
223
|
+
m <= l || (t.fillStyle = r.style && r.style.background || this.options.segmentStyle.background, t.fillRect((l - this.options.overviewStart) * o, u, Math.max((m - l) * o, 1), 6));
|
|
224
|
+
});
|
|
225
|
+
let v = (this.options.startTime - this.options.overviewStart) * o, h = this.options.visibleHours * 60 * 60 * 1e3 * o;
|
|
226
|
+
if (t.fillStyle = this.options.axisStyle.overviewWindowColor, t.fillRect(v, 0, h, i), t.strokeStyle = this.options.axisStyle.overviewWindowBorder, t.strokeRect(v + 0.5, 0.5, Math.max(h - 1, 0), i - 1), this.isClick && this.currentTimestamp != null) {
|
|
227
|
+
let r = (this.currentTimestamp - this.options.overviewStart) * o;
|
|
228
|
+
r >= 0 && r <= e && this.drawLine(t, {
|
|
229
|
+
beginX: r,
|
|
230
|
+
beginY: 0,
|
|
231
|
+
endX: r,
|
|
232
|
+
endY: i,
|
|
233
|
+
color: this.options.axisStyle.overviewPlayColor,
|
|
234
|
+
width: 1,
|
|
235
|
+
center: !0
|
|
236
|
+
// 与上方时间轴指针同一时间坐标,中心对齐
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// 距下一个刻度边界的偏移毫秒数(按本地零点刻度对齐,step 单位为秒且能整除 86400)
|
|
241
|
+
ms_to_next_step(t, e) {
|
|
242
|
+
let i = new Date(t), o = (i.getHours() * 3600 + i.getMinutes() * 60 + i.getSeconds()) % e;
|
|
243
|
+
return (o ? e - o : 0) * 1e3 - i.getMilliseconds();
|
|
244
|
+
}
|
|
245
|
+
// 轴起始时间钳制到 [minTime, maxTime] 边界内
|
|
246
|
+
clampStartTime(t) {
|
|
247
|
+
if (this.options.minTime == null && this.options.maxTime == null)
|
|
248
|
+
return t;
|
|
249
|
+
let e = this.options.visibleHours * 60 * 60 * 1e3;
|
|
250
|
+
return this.options.maxTime != null && t + e > this.options.maxTime && (t = this.options.maxTime - e), this.options.minTime != null && t < this.options.minTime && (t = this.options.minTime), t;
|
|
251
|
+
}
|
|
252
|
+
// 时间点钳制到边界内
|
|
253
|
+
clampTime(t) {
|
|
254
|
+
return this.options.minTime != null && t < this.options.minTime && (t = this.options.minTime), this.options.maxTime != null && t > this.options.maxTime && (t = this.options.maxTime), t;
|
|
255
|
+
}
|
|
256
|
+
// 注册事件(保存引用以便 destroy 时移除);事件绑定在顶层动态层画布上
|
|
257
|
+
initEvents() {
|
|
258
|
+
this.overlayCanvas && (this.contextmenuHandler = (t) => {
|
|
259
|
+
t.preventDefault();
|
|
260
|
+
}, this.mousemoveHandler = this.canvasMousemoveFunc.bind(this), this.wheelHandler = this.mousewheelFunc.bind(this), this.mousedownHandler = this.mousedownFunc.bind(this), this.mouseupHandler = this.mouseupFunc.bind(this), this.mouseoutHandler = this.mouseoutFunc.bind(this), this.touchstartHandler = this.touchStartFunc.bind(this), this.touchmoveHandler = this.touchMoveFunc.bind(this), this.touchendHandler = this.touchEndFunc.bind(this), this.overlayCanvas.addEventListener("contextmenu", this.contextmenuHandler), this.overlayCanvas.addEventListener("mousemove", this.mousemoveHandler), this.overlayCanvas.addEventListener("wheel", this.wheelHandler, { passive: !1 }), this.overlayCanvas.addEventListener("mousedown", this.mousedownHandler), this.overlayCanvas.addEventListener("mouseup", this.mouseupHandler), this.overlayCanvas.addEventListener("mouseout", this.mouseoutHandler), this.overlayCanvas.addEventListener("touchstart", this.touchstartHandler, { passive: !1 }), this.overlayCanvas.addEventListener("touchmove", this.touchmoveHandler, { passive: !1 }), this.overlayCanvas.addEventListener("touchend", this.touchendHandler));
|
|
261
|
+
}
|
|
262
|
+
// ===== 概览层(overview)生命周期:供初始化与 updateOptions 动态开关复用 =====
|
|
263
|
+
// 挂载概览层:创建 canvas、上下文并绑定交互事件
|
|
264
|
+
mountOverview() {
|
|
265
|
+
this.overviewCanvas || (this.overviewCanvas = document.createElement("canvas"), this.overviewCanvas.style.position = "absolute", this.overviewCanvas.style.left = "0", this.options.container.appendChild(this.overviewCanvas), this.overviewCtx = this.overviewCanvas.getContext("2d"), this.bindOverviewEvents());
|
|
266
|
+
}
|
|
267
|
+
// 绑定概览层交互事件:点击/拖动跳转(鼠标与单指触摸)
|
|
268
|
+
bindOverviewEvents() {
|
|
269
|
+
this.overviewCanvas && (this.overviewMousedownHandler = this.overviewMousedownFunc.bind(this), this.overviewMousemoveHandler = () => {
|
|
270
|
+
this.overviewCanvas.style.cursor = "pointer";
|
|
271
|
+
}, this.overviewTouchstartHandler = this.overviewTouchFunc.bind(this), this.overviewTouchmoveHandler = this.overviewTouchFunc.bind(this), this.overviewCanvas.addEventListener("mousedown", this.overviewMousedownHandler), this.overviewCanvas.addEventListener("mousemove", this.overviewMousemoveHandler), this.overviewCanvas.addEventListener("touchstart", this.overviewTouchstartHandler, { passive: !1 }), this.overviewCanvas.addEventListener("touchmove", this.overviewTouchmoveHandler, { passive: !1 }));
|
|
272
|
+
}
|
|
273
|
+
// 卸载概览层:移除交互事件与 canvas,置空引用
|
|
274
|
+
unmountOverview() {
|
|
275
|
+
this.overviewCanvas && (this.overviewCanvas.removeEventListener("mousedown", this.overviewMousedownHandler), this.overviewCanvas.removeEventListener("mousemove", this.overviewMousemoveHandler), this.overviewCanvas.removeEventListener("touchstart", this.overviewTouchstartHandler), this.overviewCanvas.removeEventListener("touchmove", this.overviewTouchmoveHandler), this.overviewCanvas.remove(), this.overviewCanvas = null, this.overviewCtx = null);
|
|
276
|
+
}
|
|
277
|
+
// 销毁实例,移除全部事件监听与 canvas
|
|
278
|
+
destroy() {
|
|
279
|
+
this.overlayCanvas && (this.overlayCanvas.removeEventListener("contextmenu", this.contextmenuHandler), this.overlayCanvas.removeEventListener("mousemove", this.mousemoveHandler), this.overlayCanvas.removeEventListener("wheel", this.wheelHandler), this.overlayCanvas.removeEventListener("mousedown", this.mousedownHandler), this.overlayCanvas.removeEventListener("mouseup", this.mouseupHandler), this.overlayCanvas.removeEventListener("mouseout", this.mouseoutHandler), this.overlayCanvas.removeEventListener("touchstart", this.touchstartHandler), this.overlayCanvas.removeEventListener("touchmove", this.touchmoveHandler), this.overlayCanvas.removeEventListener("touchend", this.touchendHandler), this.overlayCanvas.remove(), this.overlayCanvas = null), this.unmountOverview(), this.canvas && (this.canvas.remove(), this.canvas = null), document.onmousemove = null, document.onmouseup = null;
|
|
280
|
+
}
|
|
281
|
+
canDragPointer(t) {
|
|
282
|
+
let e = t.offsetX, i = t.offsetY, s = window.devicePixelRatio || 1;
|
|
283
|
+
return this.overlayCtx.isPointInPath(e * s, i * s);
|
|
284
|
+
}
|
|
285
|
+
setPointer(t) {
|
|
286
|
+
this.canDragPointer(t) ? (this.options.container.style.cursor = "pointer", this.isDragPointer = !0, this.isMoveTriangle = !0) : (!this.isPressDown || this.button) && (this.isPressDown && this.isMoveTriangle || (this.isDragPointer = !1, this.isMoveTriangle = !1, this.options.container.style.cursor = ""));
|
|
287
|
+
}
|
|
288
|
+
// 鼠标点击(按下)
|
|
289
|
+
mousedownFunc(t) {
|
|
290
|
+
t.button === 0 ? (this.isPressDown = !0, this.button = t.button, this.canDragPointer(t) ? this.currentChecked = "pointer" : this.currentChecked = "axis", document.onmousemove = (e) => {
|
|
291
|
+
this.mousemoveFunc(e);
|
|
292
|
+
}, document.onmouseup = (e) => {
|
|
293
|
+
this.mouseupFunc(e), document.onmousemove = null, document.onmouseup = null;
|
|
294
|
+
}, this.isDown = !0, this.g_mousedownCursor = this.getCursorPositionX(t)) : t.button;
|
|
295
|
+
}
|
|
296
|
+
// 画布悬浮(未按下时):只重绘动态层,显示十字线与时间提示
|
|
297
|
+
canvasMousemoveFunc(t) {
|
|
298
|
+
if (this.isPressDown)
|
|
299
|
+
return;
|
|
300
|
+
let e = this.getCursorPositionX(t);
|
|
301
|
+
this.setPointer(t), this.hoverState = {
|
|
302
|
+
x: e,
|
|
303
|
+
time: this.options.startTime + e / this.pxPerMs
|
|
304
|
+
}, this.drawOverlay();
|
|
305
|
+
}
|
|
306
|
+
// 鼠标拖动(轴或指针)
|
|
307
|
+
mousemoveFunc(t) {
|
|
308
|
+
let e = this.getCursorPositionX(t);
|
|
309
|
+
if (this.setPointer(t), this.isMove = !0, this.markUserInteract(), this.currentChecked === "axis") {
|
|
310
|
+
let i = e - this.g_mousedownCursor;
|
|
311
|
+
this.options.startTime = this.clampStartTime(this.options.startTime - Math.round(i / this.pxPerMs)), this.g_mousedownCursor = e, this.hoverState = {
|
|
312
|
+
x: e,
|
|
313
|
+
time: this.options.startTime + e / this.pxPerMs
|
|
314
|
+
}, this.drawStatic();
|
|
315
|
+
} else this.currentChecked === "pointer" && (this.currentTimestamp = this.clampTime(this.options.startTime + e / this.pxPerMs), this.g_mousedownCursor = e, this.hoverState = { x: e, time: this.currentTimestamp }, this.drawOverlay());
|
|
316
|
+
}
|
|
317
|
+
// 鼠标抬起
|
|
318
|
+
mouseupFunc(t) {
|
|
319
|
+
if (this.isPressDown && this.button === 0)
|
|
320
|
+
if (this.isPressDown = !1, this.isMove)
|
|
321
|
+
this.isMove = !1, this.currentChecked === "pointer" && (this.returnTime = this.currentTimestamp, this.returnCheckTime("drag", this.returnTime), this.drawOverlay()), this.currentChecked = "";
|
|
322
|
+
else {
|
|
323
|
+
this.isClick = !0;
|
|
324
|
+
let e = this.getCursorPositionX(t), i = this.clampTime(this.options.startTime + e / this.pxPerMs);
|
|
325
|
+
this.currentTimestamp = this.returnTime = i, this.returnCheckTime("click", this.returnTime), this.drawOverlay();
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
// 滚轮事件(滚轮上滑放大、下滑缩小)
|
|
329
|
+
mousewheelFunc(t) {
|
|
330
|
+
t.preventDefault(), this.markUserInteract();
|
|
331
|
+
let e = t.deltaY < 0 ? 1 : -1, i = this.getCursorPositionX(t), s = this.options.startTime + i / this.pxPerMs;
|
|
332
|
+
e < 0 ? this.options.visibleHours = Math.min(this.options.maxVisibleHours, this.options.visibleHours * 1.25) : e > 0 && (this.options.visibleHours = Math.max(this.options.minVisibleHours, this.options.visibleHours / 1.25));
|
|
333
|
+
let o = this.canvasWidth / (this.options.visibleHours * 60 * 60 * 1e3);
|
|
334
|
+
this.options.startTime = this.clampStartTime(s - i / o), this.drawStatic();
|
|
335
|
+
}
|
|
336
|
+
mouseoutFunc(t) {
|
|
337
|
+
this.hoverState = null, this.drawOverlay();
|
|
338
|
+
}
|
|
339
|
+
// ===== 移动端触摸手势(单指点击/拖动,双指捏合缩放) =====
|
|
340
|
+
touchStartFunc(t) {
|
|
341
|
+
if (t.preventDefault(), t.touches.length === 1)
|
|
342
|
+
this.mousedownFunc(this.normalizeTouchEvent(t.touches[0]));
|
|
343
|
+
else if (t.touches.length === 2) {
|
|
344
|
+
this.isPressDown = !1, this.isMove = !1, this.currentChecked = "", document.onmousemove = null, document.onmouseup = null, this.pinchStartDistance = this.getTouchDistance(t.touches), this.pinchStartVisibleHours = this.options.visibleHours;
|
|
345
|
+
let e = this.getTouchCenterX(t.touches) - this.overlayCanvas.getBoundingClientRect().left;
|
|
346
|
+
this.pinchCenterPosX = e, this.pinchCenterTime = this.options.startTime + e / this.pxPerMs;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
touchMoveFunc(t) {
|
|
350
|
+
if (t.preventDefault(), t.touches.length === 1 && this.isPressDown)
|
|
351
|
+
this.mousemoveFunc(this.normalizeTouchEvent(t.touches[0]));
|
|
352
|
+
else if (t.touches.length === 2 && this.pinchStartDistance) {
|
|
353
|
+
this.markUserInteract();
|
|
354
|
+
let e = this.getTouchDistance(t.touches) / this.pinchStartDistance;
|
|
355
|
+
this.options.visibleHours = Math.min(this.options.maxVisibleHours, Math.max(this.options.minVisibleHours, this.pinchStartVisibleHours / (e * e)));
|
|
356
|
+
let i = this.canvasWidth / (this.options.visibleHours * 60 * 60 * 1e3);
|
|
357
|
+
this.options.startTime = this.clampStartTime(this.pinchCenterTime - this.pinchCenterPosX / i), this.drawStatic();
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
touchEndFunc(t) {
|
|
361
|
+
if (this.pinchStartDistance && t.touches.length < 2) {
|
|
362
|
+
this.pinchStartDistance = 0, this.isPressDown = !1, this.isMove = !1, this.currentChecked = "", document.onmousemove = null, document.onmouseup = null;
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
this.isPressDown && t.changedTouches.length && (this.mouseupFunc(this.normalizeTouchEvent(t.changedTouches[0])), document.onmousemove = null, document.onmouseup = null);
|
|
366
|
+
}
|
|
367
|
+
// 把触摸点归一化为合成鼠标事件对象(补齐鼠标处理函数依赖的字段)
|
|
368
|
+
normalizeTouchEvent(t) {
|
|
369
|
+
let e = this.overlayCanvas.getBoundingClientRect();
|
|
370
|
+
return {
|
|
371
|
+
button: 0,
|
|
372
|
+
pageX: t.pageX,
|
|
373
|
+
pageY: t.pageY,
|
|
374
|
+
clientX: t.clientX,
|
|
375
|
+
clientY: t.clientY,
|
|
376
|
+
offsetX: t.clientX - e.left,
|
|
377
|
+
offsetY: t.clientY - e.top
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
// 两指间距(像素)
|
|
381
|
+
getTouchDistance(t) {
|
|
382
|
+
let e = t[0].clientX - t[1].clientX, i = t[0].clientY - t[1].clientY;
|
|
383
|
+
return Math.sqrt(e * e + i * i);
|
|
384
|
+
}
|
|
385
|
+
// 两指中心 X(clientX 坐标系)
|
|
386
|
+
getTouchCenterX(t) {
|
|
387
|
+
return (t[0].clientX + t[1].clientX) / 2;
|
|
388
|
+
}
|
|
389
|
+
// ===== 概览条交互(点击/拖动跳转,可视窗口居中于目标时间) =====
|
|
390
|
+
// 概览条上坐标换算为时间,并把上方时间轴的可视窗口居中到该时间
|
|
391
|
+
overviewSeek(t) {
|
|
392
|
+
let e = this.overviewCanvas.getBoundingClientRect();
|
|
393
|
+
if (e.width <= 0)
|
|
394
|
+
return;
|
|
395
|
+
this.markUserInteract();
|
|
396
|
+
let i = Math.min(e.width, Math.max(0, t - e.left)), s = this.options.overviewStart + i / e.width * (this.options.overviewEnd - this.options.overviewStart);
|
|
397
|
+
this.options.startTime = this.clampStartTime(s - this.options.visibleHours * 60 * 60 * 1e3 / 2), this.drawStatic();
|
|
398
|
+
}
|
|
399
|
+
// 概览条鼠标按下:立即跳转并进入拖动跟随
|
|
400
|
+
overviewMousedownFunc(t) {
|
|
401
|
+
t.button === 0 && (this.overviewSeek(t.clientX), document.onmousemove = (e) => {
|
|
402
|
+
this.overviewSeek(e.clientX);
|
|
403
|
+
}, document.onmouseup = () => {
|
|
404
|
+
document.onmousemove = null, document.onmouseup = null;
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
// 概览条触摸(单指点击/拖动跳转)
|
|
408
|
+
overviewTouchFunc(t) {
|
|
409
|
+
t.preventDefault(), t.touches.length && this.overviewSeek(t.touches[0].clientX);
|
|
410
|
+
}
|
|
411
|
+
// 鼠标指针X位置
|
|
412
|
+
getCursorPositionX(t) {
|
|
413
|
+
let e = 0;
|
|
414
|
+
return t || (t = window.event), t.pageX || t.pageY ? e = t.pageX : (t.clientX || t.clientY) && (e = t.clientX + document.body.scrollLeft + document.documentElement.scrollLeft), e -= this.overlayCanvas.getBoundingClientRect().left, e;
|
|
415
|
+
}
|
|
416
|
+
// 清除静态层
|
|
417
|
+
clearCanvas() {
|
|
418
|
+
this.canvasCtx.clearRect(0, 0, this.canvasWidth, this.canvasHeight);
|
|
419
|
+
}
|
|
420
|
+
// 清除动态层
|
|
421
|
+
clearOverlay() {
|
|
422
|
+
this.overlayCtx.clearRect(0, 0, this.canvasWidth, this.canvasHeight);
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* 返回点击或者拖动的时间点
|
|
426
|
+
* @param handle 触发方式{click,drag};回调中吸附续播会覆盖为 snap
|
|
427
|
+
* @param currentTime 选中时间戳{1637164800000}
|
|
428
|
+
*/
|
|
429
|
+
returnCheckTime(t, e) {
|
|
430
|
+
var o, a, u, v;
|
|
431
|
+
let i = Math.floor(e);
|
|
432
|
+
if (this.options.segments.findIndex((h) => i >= h.begin && i <= h.end) >= 0)
|
|
433
|
+
(a = (o = this.options).changeCallback) == null || a.call(o, {
|
|
434
|
+
mode: t,
|
|
435
|
+
// 触发方式
|
|
436
|
+
timestamp: i,
|
|
437
|
+
// 时间戳
|
|
438
|
+
valid: !0,
|
|
439
|
+
// 是否有效
|
|
440
|
+
nextBegin: this.getNextSegment(i)
|
|
441
|
+
// 选中时间往后最近的一段录像(完整信息),无则 null
|
|
442
|
+
});
|
|
443
|
+
else {
|
|
444
|
+
let h = i, r = !1, l = t;
|
|
445
|
+
if (this.options.snapToNearest && this.options.segments && this.options.segments.length) {
|
|
446
|
+
let m = this.getNextSegment(i);
|
|
447
|
+
m && (h = Math.floor(m.begin), r = !0, l = "snap", this.currentTimestamp = this.clampTime(h));
|
|
448
|
+
}
|
|
449
|
+
(v = (u = this.options).changeCallback) == null || v.call(u, {
|
|
450
|
+
mode: l,
|
|
451
|
+
// 触发方式{click,drag,snap}
|
|
452
|
+
timestamp: h,
|
|
453
|
+
valid: r,
|
|
454
|
+
// 按原始选中时间往后查最近一段;snap 时即被吸附到的那段,续播直接从它开始
|
|
455
|
+
nextBegin: this.getNextSegment(i)
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
formatDate(t, e) {
|
|
460
|
+
let i = e ? new Date(e) : /* @__PURE__ */ new Date();
|
|
461
|
+
t = t || "yyyy-MM-dd";
|
|
462
|
+
const s = {
|
|
463
|
+
"M+": i.getMonth() + 1,
|
|
464
|
+
// 月份
|
|
465
|
+
"d+": i.getDate(),
|
|
466
|
+
// 日
|
|
467
|
+
"h+": i.getHours(),
|
|
468
|
+
// 小时
|
|
469
|
+
"m+": i.getMinutes(),
|
|
470
|
+
// 分
|
|
471
|
+
"s+": i.getSeconds(),
|
|
472
|
+
// 秒
|
|
473
|
+
"q+": Math.floor((i.getMonth() + 3) / 3),
|
|
474
|
+
// 季度
|
|
475
|
+
S: i.getMilliseconds()
|
|
476
|
+
// 毫秒
|
|
477
|
+
};
|
|
478
|
+
/(y+)/.test(t) && (t = t.replace(RegExp.$1, (i.getFullYear() + "").substr(4 - RegExp.$1.length)));
|
|
479
|
+
for (const o in s)
|
|
480
|
+
new RegExp("(" + o + ")").test(t) && (t = t.replace(RegExp.$1, RegExp.$1.length == 1 ? s[o] : ("00" + s[o]).substr(("" + s[o]).length)));
|
|
481
|
+
return t;
|
|
482
|
+
}
|
|
483
|
+
updateDatas(t) {
|
|
484
|
+
this.options.visibleHours = Math.min(this.options.maxVisibleHours, Math.max(this.options.minVisibleHours, t.visibleHours)), this.options.startTime = t.startTime, t.minTime !== void 0 && (this.options.minTime = t.minTime), t.maxTime !== void 0 && (this.options.maxTime = t.maxTime), t.overviewStart != null && (this.options.overviewStart = t.overviewStart), t.overviewEnd != null && (this.options.overviewEnd = t.overviewEnd), this.options.startTime = this.clampStartTime(this.options.startTime), this.options.segments = this.normalizeSegments(t.segments), !this.options.segments.some((i) => this.currentTimestamp >= i.begin && this.currentTimestamp <= i.end) && this.options.segments.length && (this.currentTimestamp = this.options.segments[0].begin), this.drawStatic();
|
|
485
|
+
}
|
|
486
|
+
// 通用配置更新:传入 json 配置对象,逐项合并到 options 并按需重建/重绘
|
|
487
|
+
// 支持运行时动态开关 overview(重建/销毁概览层),以及样式/边界/片段/视口等更新
|
|
488
|
+
// 与 updateDatas 的区别:updateDatas 面向数据刷新,updateOptions 面向任意配置项(含影响 canvas 结构的 overview)
|
|
489
|
+
updateOptions(t) {
|
|
490
|
+
if (!t || typeof t != "object") return;
|
|
491
|
+
const e = this.options.overview, i = ["axisStyle", "segments", "visibleHours", "startTime"];
|
|
492
|
+
Object.keys(t).forEach((s) => {
|
|
493
|
+
t[s] === void 0 || i.includes(s) || (this.options[s] = t[s]);
|
|
494
|
+
}), t.axisStyle && (this.options.axisStyle = Object.assign({}, this.options.axisStyle, t.axisStyle)), t.segments !== void 0 && (this.options.segments = this.normalizeSegments(t.segments)), t.visibleHours !== void 0 && (this.options.visibleHours = Math.min(this.options.maxVisibleHours, Math.max(this.options.minVisibleHours, t.visibleHours))), t.startTime !== void 0 && (this.options.startTime = t.startTime), (t.startTime !== void 0 || t.minTime !== void 0 || t.maxTime !== void 0) && (this.options.startTime = this.clampStartTime(this.options.startTime)), t.overview !== void 0 && t.overview !== e && (this.options.overview ? this.mountOverview() : this.unmountOverview()), ["overview", "overviewHeight", "overviewGap"].some((s) => t[s] !== void 0) && this.initCanvasSize(), t.backgroundColor !== void 0 && this.canvas && (this.canvas.style.backgroundColor = t.backgroundColor), t.segments !== void 0 && !this.options.segments.some((o) => this.currentTimestamp >= o.begin && this.currentTimestamp <= o.end) && this.options.segments.length && (this.currentTimestamp = this.options.segments[0].begin), this.drawStatic();
|
|
495
|
+
}
|
|
496
|
+
// 更新播放指针时间(默认走快速通道:只重绘动态层,不触发静态层重绘;
|
|
497
|
+
// 开启 centerPointer 后,播放推进时滚动视口让指针固定在画布中央,此时需重绘静态层)
|
|
498
|
+
updateTime(t) {
|
|
499
|
+
var s, o;
|
|
500
|
+
let e = this.clampTime(t);
|
|
501
|
+
this.currentTimestamp = e, this.returnTime = e, this.isClick = !0, this.options.centerPointer && !this.isCenterPaused() ? (this.options.startTime = this.clampStartTime(e - this.options.visibleHours * 60 * 60 * 1e3 / 2), this.drawStatic()) : this.drawOverlay();
|
|
502
|
+
let i = (this.options.segments || []).some((a) => e >= a.begin && e <= a.end);
|
|
503
|
+
(o = (s = this.options).playCallback) == null || o.call(s, {
|
|
504
|
+
timestamp: Math.floor(e),
|
|
505
|
+
// 时间戳
|
|
506
|
+
valid: i
|
|
507
|
+
// 是否处于有效录像区
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
// 标记用户手势交互:暂停播放指针居中并记录时刻,供 centerResumeDelay 延时恢复
|
|
511
|
+
markUserInteract() {
|
|
512
|
+
this.centerPaused = !0, this.lastInteractTime = Date.now();
|
|
513
|
+
}
|
|
514
|
+
// 居中让位是否生效:手势暂停期间返回 true;停止操作超过 centerResumeDelay 后自动恢复居中
|
|
515
|
+
isCenterPaused() {
|
|
516
|
+
return this.centerPaused ? this.isPressDown || this.pinchStartDistance ? !0 : Date.now() - this.lastInteractTime >= this.options.centerResumeDelay ? (this.centerPaused = !1, !1) : !0 : !1;
|
|
517
|
+
}
|
|
518
|
+
// ===== 对外视口控制 API =====
|
|
519
|
+
// 获取当前视口(轴起始时间与可见时长)
|
|
520
|
+
getViewport() {
|
|
521
|
+
return { startTime: this.options.startTime, visibleHours: this.options.visibleHours };
|
|
522
|
+
}
|
|
523
|
+
// 设置视口(两参数均可省略;自动钳制到边界与缩放限制内)
|
|
524
|
+
setViewport(t, e) {
|
|
525
|
+
e != null && (this.options.visibleHours = Math.min(this.options.maxVisibleHours, Math.max(this.options.minVisibleHours, e))), t != null && (this.options.startTime = this.clampStartTime(t)), this.drawStatic();
|
|
526
|
+
}
|
|
527
|
+
// 把指定时间滚动到画布中央(不改变选中/播放状态)
|
|
528
|
+
scrollTo(t) {
|
|
529
|
+
this.options.startTime = this.clampStartTime(t - this.options.visibleHours * 60 * 60 * 1e3 / 2), this.drawStatic();
|
|
530
|
+
}
|
|
531
|
+
// 立即结束手势让位并恢复居中:清除暂停态,把当前播放时间滚动到画布中央
|
|
532
|
+
resumeCenter() {
|
|
533
|
+
this.centerPaused = !1, this.lastInteractTime = 0, this.scrollTo(this.currentTimestamp);
|
|
534
|
+
}
|
|
535
|
+
// 以画布中心为锚点按倍率缩放(factor > 1 放大,< 1 缩小)
|
|
536
|
+
zoomBy(t) {
|
|
537
|
+
if (!(t > 0))
|
|
538
|
+
return;
|
|
539
|
+
let e = this.options.startTime + this.options.visibleHours * 60 * 60 * 1e3 / 2;
|
|
540
|
+
this.options.visibleHours = Math.min(this.options.maxVisibleHours, Math.max(this.options.minVisibleHours, this.options.visibleHours / t)), this.options.startTime = this.clampStartTime(e - this.options.visibleHours * 60 * 60 * 1e3 / 2), this.drawStatic();
|
|
541
|
+
}
|
|
542
|
+
// 放大一档
|
|
543
|
+
zoomIn() {
|
|
544
|
+
this.zoomBy(1.25);
|
|
545
|
+
}
|
|
546
|
+
// 缩小一档
|
|
547
|
+
zoomOut() {
|
|
548
|
+
this.zoomBy(0.8);
|
|
549
|
+
}
|
|
550
|
+
// 从指定时间往后(begin >= time)的全部录像片段,按 begin 升序,元素为片段完整信息(含 style);
|
|
551
|
+
// segments 设计上当前时间之后可能存在多段,业务侧可直接用作跨空白续播的播放列表
|
|
552
|
+
getNextSegments(t) {
|
|
553
|
+
return (this.options.segments || []).filter((e) => e.begin >= t).sort((e, i) => e.begin - i.begin);
|
|
554
|
+
}
|
|
555
|
+
// 从指定时间往后(时间更大方向)找最近的录像片段,找不到返回 null;
|
|
556
|
+
// 即 getNextSegments 的首条,不依赖 segments 原始排序
|
|
557
|
+
getNextSegment(t) {
|
|
558
|
+
return this.getNextSegments(t)[0] || null;
|
|
559
|
+
}
|
|
560
|
+
// ===== 片段规范化:消除重叠 =====
|
|
561
|
+
// 规则(与业务约定):
|
|
562
|
+
// 1. 完全重叠(后段被前段完全覆盖)→ 舍弃后段,以前面那段的样式为准;完全相同保留靠前一段
|
|
563
|
+
// 2. 部分重叠 → 以重叠开始位置(后段 begin)分割:前段截断尾部,重叠区归后段、各自样式为准
|
|
564
|
+
// 3. 首尾邻接(前段 end == 后段 begin)→ 不合并,保留业务原始分段边界
|
|
565
|
+
// 返回浅拷贝新数组,不修改业务传入的原始数据
|
|
566
|
+
normalizeSegments(t) {
|
|
567
|
+
if (!Array.isArray(t))
|
|
568
|
+
return [];
|
|
569
|
+
let e = t.filter((s) => s && s.end > s.begin).sort((s, o) => s.begin - o.begin || o.end - s.end), i = [];
|
|
570
|
+
return e.forEach((s) => {
|
|
571
|
+
let o = i[i.length - 1];
|
|
572
|
+
if (!o || s.begin >= o.end) {
|
|
573
|
+
i.push(Object.assign({}, s));
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
s.end <= o.end || (o.end = s.begin, o.end > o.begin ? i.push(Object.assign({}, s)) : i[i.length - 1] = Object.assign({}, s));
|
|
577
|
+
}), i;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
const S = (n, t) => {
|
|
581
|
+
const e = n.__vccOpts || n;
|
|
582
|
+
for (const [i, s] of t)
|
|
583
|
+
e[i] = s;
|
|
584
|
+
return e;
|
|
585
|
+
}, H = {
|
|
586
|
+
name: "TimeAxisPlus",
|
|
587
|
+
props: {
|
|
588
|
+
width: {
|
|
589
|
+
type: [Number, String],
|
|
590
|
+
default: "100%"
|
|
591
|
+
},
|
|
592
|
+
// 高度,数字按 px 处理,默认 40px
|
|
593
|
+
height: {
|
|
594
|
+
type: [Number, String],
|
|
595
|
+
default: 40
|
|
596
|
+
},
|
|
597
|
+
// 轴起始时间(左缘时间戳,ms),默认当天 0 点
|
|
598
|
+
startTime: {
|
|
599
|
+
type: Number,
|
|
600
|
+
// 默认当天 0 点
|
|
601
|
+
default: () => {
|
|
602
|
+
const n = /* @__PURE__ */ new Date();
|
|
603
|
+
return n.setHours(0, 0, 0, 0), n.getTime();
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
// 有效时间区域 [{begin, end, style?}];无需预先去重叠,组件内部自动规范化:
|
|
607
|
+
// 完全重叠舍后段(前段样式为准)、部分重叠按重叠起始位置分割(各自样式为准)、邻接不合并;
|
|
608
|
+
// 回调里的片段(如 nextBegin)为规范化后的结果
|
|
609
|
+
segments: {
|
|
610
|
+
type: Array,
|
|
611
|
+
default: () => []
|
|
612
|
+
},
|
|
613
|
+
// 可见时长(小时)
|
|
614
|
+
visibleHours: {
|
|
615
|
+
type: Number,
|
|
616
|
+
default: 24
|
|
617
|
+
},
|
|
618
|
+
// PC 端缩小极限:可见时长上限(小时)
|
|
619
|
+
maxVisibleHours: {
|
|
620
|
+
type: Number,
|
|
621
|
+
default: 24
|
|
622
|
+
},
|
|
623
|
+
// 移动端缩小极限:可见时长上限(小时),默认更小以避免刻度文字拥挤
|
|
624
|
+
mobileMaxVisibleHours: {
|
|
625
|
+
type: Number,
|
|
626
|
+
default: 12
|
|
627
|
+
},
|
|
628
|
+
// 可视边界:起始时间戳(ms),默认不限制(监控回放可传当天 0 点)
|
|
629
|
+
minTime: {
|
|
630
|
+
type: Number,
|
|
631
|
+
default: null
|
|
632
|
+
},
|
|
633
|
+
// 可视边界:结束时间戳(ms),默认不限制(监控回放可传当天 24 点)
|
|
634
|
+
maxTime: {
|
|
635
|
+
type: Number,
|
|
636
|
+
default: null
|
|
637
|
+
},
|
|
638
|
+
// 点击空白区域时是否吸附到最近录像片段起点
|
|
639
|
+
snapToNearest: {
|
|
640
|
+
type: Boolean,
|
|
641
|
+
default: !1
|
|
642
|
+
},
|
|
643
|
+
// 悬浮十字线与时间提示开关,不传(null)时按设备自动决定:PC 启用、移动端隐藏
|
|
644
|
+
hoverTip: {
|
|
645
|
+
type: Boolean,
|
|
646
|
+
default: null
|
|
647
|
+
},
|
|
648
|
+
// 播放指针居中:开启后播放推进(updateTime)时自动滚动视口,让指针固定在画布中央
|
|
649
|
+
centerPointer: {
|
|
650
|
+
type: Boolean,
|
|
651
|
+
default: !1
|
|
652
|
+
},
|
|
653
|
+
// 居中让位恢复延迟(ms):手势暂停居中后,停止操作超过该时长自动恢复居中跟随
|
|
654
|
+
centerResumeDelay: {
|
|
655
|
+
type: Number,
|
|
656
|
+
default: 3e3
|
|
657
|
+
},
|
|
658
|
+
// 双进度条:底部是否显示全天概览条(显示播放位置与可视窗口,点击/拖动跳转)
|
|
659
|
+
overview: {
|
|
660
|
+
type: Boolean,
|
|
661
|
+
default: !1
|
|
662
|
+
},
|
|
663
|
+
// 概览条高度(px)
|
|
664
|
+
overviewHeight: {
|
|
665
|
+
type: Number,
|
|
666
|
+
default: 20
|
|
667
|
+
},
|
|
668
|
+
// 概览范围起始时间(ms),默认取可视边界或起始日期全天
|
|
669
|
+
overviewStart: {
|
|
670
|
+
type: Number,
|
|
671
|
+
default: null
|
|
672
|
+
},
|
|
673
|
+
// 概览范围结束时间(ms)
|
|
674
|
+
overviewEnd: {
|
|
675
|
+
type: Number,
|
|
676
|
+
default: null
|
|
677
|
+
},
|
|
678
|
+
movePlay: {
|
|
679
|
+
type: Boolean,
|
|
680
|
+
default: !1
|
|
681
|
+
},
|
|
682
|
+
clickPlay: {
|
|
683
|
+
type: Boolean,
|
|
684
|
+
default: !0
|
|
685
|
+
},
|
|
686
|
+
// 画布背景色
|
|
687
|
+
backgroundColor: {
|
|
688
|
+
type: String,
|
|
689
|
+
default: "#000"
|
|
690
|
+
},
|
|
691
|
+
// 轴样式配置,支持只传部分字段(逐项覆盖默认值):
|
|
692
|
+
// borderColor / graduationColor / tickTextColor / hoverLineColor / hoverTextColor /
|
|
693
|
+
// overviewBg / overviewTickColor / overviewWindowColor / overviewWindowBorder / overviewPlayColor
|
|
694
|
+
axisStyle: {
|
|
695
|
+
type: Object,
|
|
696
|
+
default: () => ({})
|
|
697
|
+
}
|
|
698
|
+
},
|
|
699
|
+
data() {
|
|
700
|
+
return {
|
|
701
|
+
axis: null,
|
|
702
|
+
ro: null,
|
|
703
|
+
isMobile: !1
|
|
704
|
+
};
|
|
705
|
+
},
|
|
706
|
+
computed: {
|
|
707
|
+
// 按设备类型选择缩小极限,PC 与移动端分开控制
|
|
708
|
+
effectiveMaxVisibleHours() {
|
|
709
|
+
return this.isMobile ? this.mobileMaxVisibleHours : this.maxVisibleHours;
|
|
710
|
+
},
|
|
711
|
+
// 悬浮提示生效值:显式传值优先,未传则移动端隐藏、PC 显示
|
|
712
|
+
effectiveHoverTip() {
|
|
713
|
+
return this.hoverTip == null ? !this.isMobile : this.hoverTip;
|
|
714
|
+
}
|
|
715
|
+
},
|
|
716
|
+
watch: {
|
|
717
|
+
segments: {
|
|
718
|
+
deep: !0,
|
|
719
|
+
handler() {
|
|
720
|
+
this.updateAxis();
|
|
721
|
+
}
|
|
722
|
+
},
|
|
723
|
+
startTime() {
|
|
724
|
+
this.updateAxis();
|
|
725
|
+
},
|
|
726
|
+
visibleHours() {
|
|
727
|
+
this.updateAxis();
|
|
728
|
+
},
|
|
729
|
+
effectiveMaxVisibleHours(n) {
|
|
730
|
+
this.axis && (this.axis.options.maxVisibleHours = n);
|
|
731
|
+
},
|
|
732
|
+
effectiveHoverTip(n) {
|
|
733
|
+
this.axis && (this.axis.options.hoverTip = n);
|
|
734
|
+
},
|
|
735
|
+
minTime() {
|
|
736
|
+
this.updateAxis();
|
|
737
|
+
},
|
|
738
|
+
maxTime() {
|
|
739
|
+
this.updateAxis();
|
|
740
|
+
},
|
|
741
|
+
snapToNearest(n) {
|
|
742
|
+
this.axis && (this.axis.options.snapToNearest = n);
|
|
743
|
+
},
|
|
744
|
+
centerPointer(n) {
|
|
745
|
+
this.axis && (this.axis.options.centerPointer = n);
|
|
746
|
+
},
|
|
747
|
+
centerResumeDelay(n) {
|
|
748
|
+
this.axis && (this.axis.options.centerResumeDelay = n);
|
|
749
|
+
},
|
|
750
|
+
axisStyle: {
|
|
751
|
+
deep: !0,
|
|
752
|
+
handler(n) {
|
|
753
|
+
this.axis && (this.axis.options.axisStyle = Object.assign({}, this.axis.options.axisStyle, n), this.axis.drawStatic());
|
|
754
|
+
}
|
|
755
|
+
},
|
|
756
|
+
overview(n) {
|
|
757
|
+
console.log(9999887), this.axis && this.axis.updateOptions({ overview: n });
|
|
758
|
+
},
|
|
759
|
+
overviewStart() {
|
|
760
|
+
this.updateAxis();
|
|
761
|
+
},
|
|
762
|
+
overviewEnd() {
|
|
763
|
+
this.updateAxis();
|
|
764
|
+
}
|
|
765
|
+
},
|
|
766
|
+
created() {
|
|
767
|
+
this.isMobile = window.matchMedia("(pointer: coarse)").matches || /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);
|
|
768
|
+
},
|
|
769
|
+
mounted() {
|
|
770
|
+
this.$nextTick(() => {
|
|
771
|
+
this.initTimeAxis();
|
|
772
|
+
}), window.addEventListener("resize", this.resizeHandler), this.watchSize();
|
|
773
|
+
},
|
|
774
|
+
beforeUnmount() {
|
|
775
|
+
window.removeEventListener("resize", this.resizeHandler), this.ro && (this.ro.disconnect(), this.ro = null), this.axis && (this.axis.destroy(), this.axis = null);
|
|
776
|
+
},
|
|
777
|
+
methods: {
|
|
778
|
+
// 尺寸格式化:数字按 px,字符串原样使用(如 '100%')
|
|
779
|
+
formatSize(n) {
|
|
780
|
+
return typeof n == "number" ? `${n}px` : n;
|
|
781
|
+
},
|
|
782
|
+
watchSize() {
|
|
783
|
+
typeof ResizeObserver > "u" || (this.ro = new ResizeObserver(() => {
|
|
784
|
+
this.$nextTick(() => {
|
|
785
|
+
this.axis && this.axis.resize();
|
|
786
|
+
});
|
|
787
|
+
}), this.ro.observe(this.$refs.TimelineGroup));
|
|
788
|
+
},
|
|
789
|
+
initTimeAxis() {
|
|
790
|
+
this.axis = new C({
|
|
791
|
+
container: this.$refs.TimelineGroup,
|
|
792
|
+
backgroundColor: this.backgroundColor,
|
|
793
|
+
width: this.width,
|
|
794
|
+
height: this.height,
|
|
795
|
+
startTime: this.startTime,
|
|
796
|
+
visibleHours: this.visibleHours,
|
|
797
|
+
maxVisibleHours: this.effectiveMaxVisibleHours,
|
|
798
|
+
minTime: this.minTime,
|
|
799
|
+
maxTime: this.maxTime,
|
|
800
|
+
snapToNearest: this.snapToNearest,
|
|
801
|
+
hoverTip: this.effectiveHoverTip,
|
|
802
|
+
centerPointer: this.centerPointer,
|
|
803
|
+
centerResumeDelay: this.centerResumeDelay,
|
|
804
|
+
axisStyle: this.axisStyle,
|
|
805
|
+
overview: this.overview,
|
|
806
|
+
overviewHeight: this.overviewHeight,
|
|
807
|
+
overviewStart: this.overviewStart,
|
|
808
|
+
overviewEnd: this.overviewEnd,
|
|
809
|
+
// 未自带 style 的片段的默认样式
|
|
810
|
+
segmentStyle: {
|
|
811
|
+
background: "rgba(24,208,217,0.5)"
|
|
812
|
+
},
|
|
813
|
+
segments: this.segments,
|
|
814
|
+
changeCallback: (n) => {
|
|
815
|
+
this.$emit("changeTime", n);
|
|
816
|
+
},
|
|
817
|
+
playCallback: (n) => {
|
|
818
|
+
this.$emit("playTime", n);
|
|
819
|
+
}
|
|
820
|
+
}), console.log(this.axis);
|
|
821
|
+
},
|
|
822
|
+
// props 变化后重新渲染
|
|
823
|
+
updateAxis() {
|
|
824
|
+
this.axis && this.axis.updateDatas({
|
|
825
|
+
visibleHours: this.visibleHours,
|
|
826
|
+
startTime: this.startTime,
|
|
827
|
+
segments: this.segments,
|
|
828
|
+
minTime: this.minTime,
|
|
829
|
+
maxTime: this.maxTime,
|
|
830
|
+
overviewStart: this.overviewStart,
|
|
831
|
+
overviewEnd: this.overviewEnd
|
|
832
|
+
});
|
|
833
|
+
},
|
|
834
|
+
// 更新时间
|
|
835
|
+
updateTime(n) {
|
|
836
|
+
this.axis.updateTime(n);
|
|
837
|
+
},
|
|
838
|
+
// ===== 对外视口控制 API(转发到画布实例) =====
|
|
839
|
+
// 获取当前视口 {startTime, visibleHours}
|
|
840
|
+
getViewport() {
|
|
841
|
+
return this.axis ? this.axis.getViewport() : null;
|
|
842
|
+
},
|
|
843
|
+
// 设置视口(两参数均可省略)
|
|
844
|
+
setViewport(n, t) {
|
|
845
|
+
this.axis && this.axis.setViewport(n, t);
|
|
846
|
+
},
|
|
847
|
+
// 把指定时间滚动到画布中央
|
|
848
|
+
scrollTo(n) {
|
|
849
|
+
this.axis && this.axis.scrollTo(n);
|
|
850
|
+
},
|
|
851
|
+
// 立即结束手势让位并恢复居中(清除暂停态并把当前播放时间滚动到画布中央)
|
|
852
|
+
resumeCenter() {
|
|
853
|
+
this.axis && this.axis.resumeCenter();
|
|
854
|
+
},
|
|
855
|
+
// 放大一档
|
|
856
|
+
zoomIn() {
|
|
857
|
+
this.axis && this.axis.zoomIn();
|
|
858
|
+
},
|
|
859
|
+
// 缩小一档
|
|
860
|
+
zoomOut() {
|
|
861
|
+
this.axis && this.axis.zoomOut();
|
|
862
|
+
},
|
|
863
|
+
// 从指定时间往后找最近录像片段,找不到返回 null
|
|
864
|
+
getNextSegment(n) {
|
|
865
|
+
return this.axis ? this.axis.getNextSegment(n) : null;
|
|
866
|
+
},
|
|
867
|
+
// 从指定时间往后的全部录像片段(begin 升序,完整信息),可作续播播放列表
|
|
868
|
+
getNextSegments(n) {
|
|
869
|
+
return this.axis ? this.axis.getNextSegments(n) : [];
|
|
870
|
+
},
|
|
871
|
+
// 运行时更新配置(传入 json,转发到画布实例):支持动态开关 overview、改样式/边界/片段等
|
|
872
|
+
updateOptions(n) {
|
|
873
|
+
this.axis && this.axis.updateOptions(n);
|
|
874
|
+
},
|
|
875
|
+
// 窗口变化
|
|
876
|
+
resizeHandler() {
|
|
877
|
+
this.axis && this.axis.resize();
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
function M(n, t, e, i, s, o) {
|
|
882
|
+
return x(), T("div", {
|
|
883
|
+
class: "timeline-group",
|
|
884
|
+
ref: "TimelineGroup",
|
|
885
|
+
style: b({ width: o.formatSize(e.width), height: o.formatSize(e.height) })
|
|
886
|
+
}, null, 4);
|
|
887
|
+
}
|
|
888
|
+
const w = /* @__PURE__ */ S(H, [["render", M], ["__scopeId", "data-v-b90b2c6f"]]);
|
|
889
|
+
w.install = (n) => {
|
|
890
|
+
n.component(w.name, w);
|
|
891
|
+
};
|
|
892
|
+
export {
|
|
893
|
+
w as TimeAxisPlus,
|
|
894
|
+
w as default,
|
|
895
|
+
C as timeAxis
|
|
896
|
+
};
|