国标GB28181协议视频平台EasyGBS二次开发过程中如何使用录像轴组件?
国标平台EasyGBS支持用户根据自己的需求自由进行二次开发,即便是试用版本也支持调用二次开发接口,接口丰富全面,可以满足大多数用户的需求。
本文我们要讲的是二次开发中的录像轴组件,由于有用户问到,所以讲一下这个组件是怎么使用的。
1.在项目导入PlayTimeAxis.vue组件
1 2 3 4 5 6 7 | import PlayTimeAxis from "./PlayTimeAxis.vue" ; export default { components: { PlayTimeAxis } } |
2.在项目中引入PlayTimeAxis组件。组件中有两个属性videos是用来接收录像段,然后展示接收到对应的时间段录像。timeChange是返回点击某一点时间的回调。
videos需要传入一个数组对象,格式如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | let videos = [{ currentVideoIndex: 0, dayTime: "20210603" , duration: 9367, endAt: "2021-06-03T02:37:29" , hmsTime: "0:1:22" , startAt: "2021-06-03T00:01:22" , }] timeChange会返回一个对象,格式如下: onTimeChange(data) { //data 的数据格式 // { // currentTime: 862, // currentVideoIndex: 20, // dayTime: "20210606", // duration: 1127, // endAt: "2021-06-06T11:42:25", // hmsTime: "11:23:38", // startAt: "2021-06-06T11:23:38", // } } <PlayTimeAxis :videos= "videos" @timeChange= "onTimeChange" > </PlayTimeAxis> |
PlayTimeAxis.vue组件完整代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | <template> <div class = "time-rule" > <div class = "time-day" ref = "day" :style= "{ left: timeDayX + 'px'}" > <div : class = "['time-minute', minuteActiveClass(n - 1)]" :title= "minuteTitle(n - 1)" v- for = "n in 1440" :key= "n" @click.prevent= "clickMinute(n - 1)" ></div> <div : class = "[ n==1 ? 'time-text-first' : 'time-text']" v- for = "n in 24" :key= "n" >{{hourText(n - 1)}}</div> </div> <div class = "time-cursor" :style= "{ left: timeCursorX + 'px'}" ref = "cursor" > <div class = "time-cursor-text" >{{timeCursorText}}</div> </div> </div> </template> <script> import moment from 'moment' export default { data() { return { timeCursorX: 0, timeDayX: 0, bMoving: false , } }, props: { videos: { type: Array, default : [] } }, mounted() { let cursor = this .$refs.cursor; let day = this .$refs.day; let rule = this .$el; let _this = this ; function moveCursor(e) { let originPageX = $(cursor).data( "originPageX" ); let dx = e.pageX - originPageX; _this.timeCursorX = $(cursor).position().left + dx; $(cursor).data( "originPageX" , e.pageX); } function touchMoveCursor(e) { let touch = e.originalEvent.targetTouches[0]; let originPageX = $(cursor).data( "originPageX" ); let dx = touch.pageX - originPageX; _this.timeCursorX = $(cursor).position().left + dx; $(cursor).data( "originPageX" , touch.pageX); } function moveDay(e) { let originPageX = $(day).data( "originPageX" ); let dx = e.pageX - originPageX; _this.timeDayX = $(day).position().left + dx; $(day).data( "originPageX" , e.pageX); } function touchMoveDay(e) { let touch = e.originalEvent.targetTouches[0]; let originPageX = $(day).data( "originPageX" ); let dx = touch.pageX - originPageX; _this.timeDayX = $(day).position().left + dx; $(day).data( "originPageX" , touch.pageX); } $(cursor). on ( "mousedown" , function (e) { $(cursor).data( "originPageX" , e.pageX); _this.bMoving = true ; $(document). on ( "mousemove" , moveCursor).one( "mouseup" , function (e) { $(document).off( "mousemove" , moveCursor); $(cursor).removeData( "originPageX" ); _this.triggerTimeChange(); _this.bMoving = false ; }) }). on ( "touchstart" , function (e) { let touch = e.originalEvent.targetTouches[0]; $(cursor).data( "originPageX" , touch.pageX); _this.bMoving = true ; $(document). on ( "touchmove" , touchMoveCursor).one( "touchend" , function (e) { $(document).off( "touchmove" , touchMoveCursor); $(cursor).removeData( "originPageX" ); _this.triggerTimeChange(); _this.bMoving = false ; }) }) $(day). on ( "mousedown" , function (e) { $(day).data( "originPageX" , e.pageX); _this.bMoving = true ; $(document). on ( "mousemove" , moveDay).one( "mouseup" , function (e) { $(document).off( "mousemove" , moveDay); $(day).removeData( "originPageX" ); _this.triggerTimeChange(1); _this.bMoving = false ; }) }). on ( "touchstart" , function (e) { let touch = e.originalEvent.targetTouches[0]; $(day).data( "originPageX" , touch.pageX); _this.bMoving = true ; $(document). on ( "touchmove" , touchMoveDay).one( "touchend" , function (e) { $(document).off( "touchmove" , touchMoveDay); $(day).removeData( "originPageX" ); _this.triggerTimeChange(); _this.bMoving = false ; }) }) }, watch: { videos: function (val) { this .triggerTimeChange(); } }, methods: { hourText(n) { let h = moment().hour(n).minute(0).second(0); return h.format( "HH:mm" ); }, minuteActiveClass(n) { let m = moment().hour(0).minute(n); let mtext = m.format( "HH:mm" ); return Object.keys( this .activeMinutes).indexOf(mtext) >= 0 ? "active" : "" ; }, minuteTitle(n) { let m = moment().hour(0).minute(n); let mtext = m.format( "HH:mm" ); return Object.keys( this .activeMinutes).indexOf(mtext) >= 0 ? mtext : "" ; }, clickMinute(n, bTrigger = true ) { if ( this .bMoving) return ; this .timeCursorX = n + this .timeDayX; if (bTrigger) { this .triggerTimeChange(); } }, dataTime(value) { //'01:01:60' out:Number let arr = value.split( ':' ).map((i) => { return +i }); return ((arr[0] * 60 * 60) + (arr[1] * 60) + (arr[2])); }, triggerTimeChange(r) { if (r === 1) return this .$emit( "timeChange" , this .activeMinutes[ this .timeCursorText]); } }, computed: { timeCursorText() { if ( this .timeCursorX >= $( this .$el).innerWidth()) { this .timeCursorX = $( this .$el).innerWidth() - 1; } if ( this .timeCursorX < 0) { this .timeCursorX = 0; } if ( this .timeDayX < $( this .$el).innerWidth() - $( this .$refs.day).outerWidth()) { this .timeDayX = $( this .$el).innerWidth() - $( this .$refs.day).outerWidth(); } if ( this .timeDayX > 0) { this .timeDayX = 0; } if ( this .timeCursorX - this .timeDayX >= 1440) { this .timeDayX = $( this .$el).innerWidth() - $( this .$refs.day).outerWidth(); this .timeCursorX = $( this .$el).innerWidth() - 1; } if ( this .timeCursorX === 0) { let lenTx = this .videos.length if (lenTx !== 0) { lenTx = lenTx - 1 let strTx = this .videos[lenTx].endAt strTx = strTx.substring(strTx.length - 8); let entTx = this .dataTime(strTx) this .timeCursorX = entTx * 100 / 6000 - 60000 } } var m = moment().hour(0).minute( this .timeCursorX - this .timeDayX); return m.format( "HH:mm" ); }, activeMinutes() { let minutes = {}; for ( let video of this .videos) { let m = moment(video.startAt, "YYYYMMDDHHmmss" ); let s = parseInt(video.duration); if (s > 8640000) { this .$message({ type: 'error' , message: "录像" + video.start_time + "时间戳错误" }) continue } let mtext = m.format( "HH:mm" ); minutes[mtext] = Object.assign({ currentTime: 0 }, video); for ( let i = 1; i <= s; i++) { m.add(1, "seconds" ); let _mtext = m.format( "HH:mm" ); if (_mtext != mtext) { mtext = _mtext; minutes[mtext] = Object.assign({ currentTime: i }, video); } } } return minutes; } } } </script> <style lang= "less" scoped> .time-rule { overflow: hidden; position: relative; height: 50px; margin: 0 auto; width: 100%; font-size: 12px; max-width: 1440px; background-color: #e5e5e5; } .time-day { position: absolute; left: 0; top: 0; height: 100%; width: 1440px; cursor: pointer; -ms-user- select : none; user- select : none; } .time-minute { float : left; width: 1px; height: 8px; margin: 0; cursor: default ; } .time-minute.active { background-color: red; cursor: pointer; } .time-text { float : left; width: 60px; border-left: 1px solid #999; border-top: 1px solid #999; box-sizing: border-box; -ms-user- select : none; user- select : none; text-align: center; height: 25px; line-height: 25px; } .time-text-first { .time-text; border-left: 0; } .time-cursor { position: absolute; left: 0; top: 0; height: 30px; width: 2px; background-color: red; text-align: center; } .time-cursor-text { position: absolute; padding: 0 5px; width: 60px; left: -30px; top: 30px; border: 1px solid red; height: 15px; line-height: 15px; cursor: move; background-color: white; -ms-user- select : none; user- select : none; } </style> |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 提示词工程——AI应用必不可少的技术
· 字符编码:从基础到乱码解决
· 地球OL攻略 —— 某应届生求职总结
2020-06-16 国标GB28181流媒体服务器EasyGBS开发oss云存储功能怎样建立分支代码?
2020-06-16 海康摄像头注册进国标GB28181流媒体平台EasyGBS无法接入怎么办?
2020-06-16 国标GB/T28181流媒体平台EasyGBS如何实现视频流的向上级联?
2020-06-16 国标GB/T28181流媒体服务器EasyGBS新版研发——设备数据无法保存
2020-06-16 国标GB/T28181流媒体服务器EasyGBS新版研发——设备信息清零问题
2020-06-16 国标GB/T28181流媒体平台EasyGBS级联时怎么添加上级平台并分配设备通道?