Commit 1846bf5f by 李乾广

修改bug

1 parent 95ca659a
......@@ -13,6 +13,7 @@
"less": "^4.2.0",
"less-loader": "^11.1.3",
"moment": "^2.29.4",
"vant": "^2.12.54",
"vue": "^2.6.14",
"vue-router": "^3.5.1"
},
......
......@@ -2,6 +2,9 @@ import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui';
import Vant from 'vant';
import 'vant/lib/index.css';
Vue.use(Vant);
import 'element-ui/lib/theme-chalk/index.css'
Vue.config.productionTip = false
Vue.use(ElementUI)
......
<template>
<div class="extension-page">
<div class="j-player-wrapper">
<j-player ref="jplay"
:type="playerType"
......@@ -7,16 +8,22 @@
:player-address="params.address"
:channel-id="params.channelId"
:datetime-range="params.datetimeRange"
:datetime-range="datetimeRange"
/>
</div>
<!-- 时间线组件 -->
<div class="extension-time-box">
<videoTime ref="videoTime" @videoTimeChange="videoTimeChange" @ptzControlClick="ptzControlClick" @ptzControlStop="ptzControlStop"/>
</div>
</div>
</template>
<script>
import { getUrlParams } from './utils';
import JPlayer from '@/components/jPlayer';
import videoTime from './videoTime';
import moment from "moment";
/**
* 此部分负责:
* 1. iframe通信postmessage
......@@ -27,11 +34,12 @@ export default {
name: 'JPlayerExtension',
components: {
JPlayer,
videoTime,
},
data() {
return {
playerType: 'live',
datetimeRange: [],
params: {
// channelId: '20000000001310000011',
channelId: '',
......@@ -39,9 +47,6 @@ export default {
prefixUrl: '',
watermark: '',
// 回放参数
playerType: 'live',
datetimeRange: [],
},
}
},
......@@ -49,6 +54,24 @@ export default {
this.init();
},
methods: {
// 时间线改变
videoTimeChange(val) {
this.playerType = moment(val).format('YYYY-MM-DD HH:mm:ss') == moment().format('YYYY-MM-DD HH:mm:ss')?'live':'playback';
if(this.playerType == 'playback'){
this.datetimeRange = [new Date(moment(val).format("YYYY-MM-DD HH:mm:ss")).getTime(),new Date().getTime()]
}
},
// 云台控制
ptzControlClick(type) {
console.log(type)
// this.$refs.jplay.ptzController(type);
},
// 云台控制结束
ptzControlStop() {
// this.$refs.jplay.ptzController('stop');
},
init() {
// 通过URL获取相关参数
const urlParamsMap = getUrlParams(window.location.hash);
......@@ -78,8 +101,8 @@ export default {
<style lang="scss" scoped>
.j-player-wrapper {
width: 100%;
height: 100%;
width: 100vw;
height: 56vw;
overflow: hidden;
}
</style>
<template>
<canvas
class="timeline-canvas"
@touchmove="touchmove"
@touchend="touchend"
@touchstart="touchstart"
onselectstart="return false;"
:style="`background-color: ${this.colors.background}; cursor: ${isMobile ? 'default' : 'pointer'}`"
:height="height"
ref="canvas"
></canvas>
</template>
<script>
import moment from "moment";
/**
* timeline-canvas canvas的绘制的时间轴组件
* @description 可用于视频、录像播放或实时数据展示等业务
* @tutorial https://gitee.com/my87/timeline-canvas
* @property {Number String} width 时间轴宽度,支持固定(不需要带单位)和百分比,默认自适应父容 (默认100%)
* @property {String Number} height 时间轴高度,非必要可以忽 (默认60)
* @property {String} startMeddleTime启动时间,未传参时会根据 timeRange 计算;timeRange 参数也未传采用当前时间
* @property {Array String } timeRange 时间轴绘制的时间范 (默认当天)
* @property {Array} markTime 区域进行标记,可以自定义背景颜色和文
* @property {Boolean} isAutoPlay 开启后时间轴将以 1s 的速度前进进(默认false)
* @property {Object} colors 自定义颜色
* @Methods {Function} play(date) 当未开启自动播放,时可以手动播放 date:播放的起始时间
* @Methods {Function} stop 手动暂停播放
* @event {Function} click 当时间和播放状态发生变化时触发,只有当开启 isAutoPlay=true 才有状态变化
* @event {Function} change 图片上传成功时触发
* @example <TimeLineCanvas ref="time_line" @click="clickCanvas" @change="changeDate" :mark-time="markTime" :time-range="time_range" :isAutoPlay="isAutoPlay" :startMeddleTime="startMeddleTime"/>
*/
export default {
name:'TimeLineCanvas',
props: {
width: {
type: [Number, String],
default: "100%",
},
//
height: {
type:[Number, String],
default: 40,
},
// 中间的时间,
startMeddleTime: String,
// 时间范围
timeRange: {
type: [Array, String],
default() {
return "";
},
},
// 需要标记的时间
markTime: {
type: Array,
default() {
return [];
},
},
//是否自动播放
isAutoPlay: {
type: Boolean,
default: false,
},
colors: {
type: Object,
default() {
return {
//背景
background: "transparent",
//中间线
meddleLine: "rgba(64, 196, 255,0.6)",
//中间时间
meddleDate: "red", // "rgb(64, 196, 255)",
//移动线
moveLine: "rgba(255,17,17,0.95)",
//移动时间
moveDate: "#009966",
//刻度线
scaleLine: "rgba(255,255,255,0.9)",
// 小刻度线
minscaleLine: "rgba(255,255,255,0.5)",
//刻度条
scaleBar: "transparent",
};
},
},
//最小像素秒(每1px对应的秒数,保证时间轴的宽度缩小情况下时间刻度不会压缩在一起)
minPxSecond: {
type: Number,
default: 120,
},
},
data() {
return {
//像素比
dpr: 1,
// realTimeRange: [],
// 整个canvas显示多少个小时
whole_hour: 6.5,
// canvas的画布宽度
canvasWidth: 1000,
//中间时间
meddleTime: "",
// 移动时鼠标有没有按下
mouseDown: false,
// 鼠标按下时的位置
mouseDownPosition: "",
// 鼠标按下时中间的时间,
mouseDownMeddleTime: "",
// 鼠标按下时有没有移动
isMove: false,
//是否手机端
isMobile: false,
//两端之间距离
distance: 0,
//是否在播放中
isPlay: false,
// 鼠标移动时移动到的时间
mouseMoveTime:"",
};
},
beforeDestroy() {
this.stop()
},
mounted() {
this.canvas = this.$refs.canvas;
//是否为手机端
// this.isMobile = /Mobi/i.test(navigator.userAgent); //navigator.userAgent.match(/Mobi/i);
this.isMobile = true; //navigator.userAgent.match(/Mobi/i);
// 屏幕大小监听
window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", this.resize, false);
// 计算默认中间时间
this.setStartMeddleTime();
this.ctx = this.canvas.getContext("2d");
//初始化
this.init();
// 自动播放
if (this.isAutoPlay) {
this.play();
}
},
methods: {
init() {
this.canvas = this.$refs.canvas;
let width = this.width;
//自适应父容器宽度 this.width参数支持百分比设置
let parentWidth = this.canvas.parentElement.clientWidth;
if (/^(\d|[1-9]\d|100)%$/.test(this.width)) {
width = Math.floor((this.width.replace("%", "") / 100) * parentWidth);
}
//移动端像素模糊问题处理
//是由于dpr像素比造成的,扩大canvas画布的像素,使1个canvas像素和1个物理像素相等
this.dpr = window.devicePixelRatio; // 假设dpr为2
// //获取css的宽高
// const { width: cssWidth, height: cssHeight } = this.canvas.getBoundingClientRect();
// // 设置图像大小
this.canvas.style.width = `${width}px`;
this.canvas.style.height = `${this.height}px`;
// 设置画布大小
this.canvas.width = Math.round(width * this.dpr);
this.canvas.height = Math.round(this.height * this.dpr);
// 由于画布扩大,canvas的坐标系也跟着扩大,
// 按照原先的坐标系绘图内容会缩小, 所以需要将绘制比例放大
this.ctx.scale(this.dpr, this.dpr);
this.canvasWidth = this.canvas.width / this.dpr;
this.drow();
},
// 监听窗口大小
resize() {
if (window.orientation === 180 || window.orientation === 0) {
// "竖屏";
}
if (window.orientation === 90 || window.orientation === -90) {
//"横屏";
}
//有时屏幕尺寸变化了,而容器的尺寸还未改变的情况下的处理
if (this.canvas.style.width === this.canvas.parentElement.clientWidth + "px") {
setTimeout(() => {
this.resize();
}, 10);
} else {
//重新初始化
this.init();
}
},
//进度条停止播放
stop() {
if (this.isPlay) {
this.isPlay = false;
this.$emit("change", this.meddleTime, "stop");
}
if (this.interval_play) clearInterval(this.interval_play);
},
/**
* 进度条播放(每次走一秒)
* @param {String|Date} date 启动时间,不传启动时间为this.meddleTime
*/
play(date) {
this.isPlay = true;
clearInterval(this.interval_play);
if (date) {
this.meddleTime = date;
}
this.interval_play = setInterval(() => {
//中间时间增加1s
this.meddleTime = moment(this.meddleTime).add(1, "s").format("YYYY-MM-DD HH:mm:ss");
let status =
this.realTimeRange[1] && new Date(this.meddleTime).getTime() >= new Date(this.realTimeRange[1]).getTime()
? "end"
: "play";
this.$emit("change", this.meddleTime, status);
// 开发过程中热更新时,会在每更新一次就开启一个setInterval,前面又不释放
// 没有释放定时任务会报错,所有在异常就视为前个任务并清理掉
try {
this.drow();
} catch (ee) {
console.log(ee);
clearInterval(this.interval_play);
}
if (!this.isPlay || status == "end") {
clearInterval(this.interval_play);
}
}, 1000);
},
//移动端滑动
touchmove(e) {
let touches = e.touches;
e.offsetX = touches[0].pageX;
e.offsetY = touches[0].pageY;
//双指缩放 (在本组件上因区域的限制不适合用双指缩放手势)
if (touches.length < 2) {
this.mousemove(e);
}
},
//滑动结束
touchend(e) {
let touches = e.changedTouches;
e.offsetX = touches[0].pageX;
e.offsetY = touches[0].pageY; //pc 与m的值是否相同
this.mouseup(e);
},
//滑动开始
touchstart(e) {
let touches = e.touches;
e.offsetX = touches[0].pageX;
e.offsetY = touches[0].pageY;
//双指事件(在本组件上因区域的限制不适合用双指缩放手势)
if (touches.length >= 2) {
e.preventDefault();
this.distance = this.getDistance({ x: e.offsetX, y: e.offsetY }, { x: touches[1].pageX, y: touches[1].pageX });
}
this.mousedown(e);
},
// 鼠标移动
mousemove(e) {
this.drow();
if (this.mouseDown) {
this.mouseDownMove(e);
this.isMove = true;
}
}, //126 10:00
// 滚动鼠标滚轮
mousewheel(e) {
e.preventDefault();
if (e.wheelDelta > 0) {
// 时间变短
this.whole_hour -= 4;
this.whole_hour < 1 && (this.whole_hour = 1);
} else {
// 时间变长
if (this.whole_hour < 4) {
this.whole_hour = 4;
} else {
this.whole_hour += 4;
this.whole_hour > 24 && (this.whole_hour = 24);
}
}
this.drow();
},
// 按下鼠标
mousedown(e) {
this.mouseDown = true;
this.mouseDownPosition = e.offsetX;
this.mouseDownMeddleTime = this.meddleTime;
this.isMove = false;
},
// 抬起鼠标
mouseup(e) {
console.log(e)
console.log(this.isPlay)
this.mouseDown = false;
// 没有滑动或鼠标移动(视为点击操作),就渲染中间时间(另外的是在移动事件里渲染)。
if (!this.isMove) {
let date = e.offsetX * this.px_second * 1000 + this.firstTime;
date = this.boundary_time(date);
let _date = moment(date).format("YYYY-MM-DD HH:mm:ss");
this.meddleTime = _date;
this.drow();
}
// 释放时确定时间选择
// change事件会在自动播放返回播放中的实时时间
this.$emit("change", this.meddleTime, "start");
//click事件只有在释放时才返回时间
this.$emit("click", this.meddleTime);
// 自动播放
if (this.isAutoPlay) {
this.play();
}
},
// 鼠标按下移动(组合事件)
mouseDownMove(e) {
this.stop();
// 记录点击位置与滑动后的坐标距离
let offset = this.mouseDownPosition - e.offsetX;
// console.log(offset)
// 点击时的中间时间 + 坐标距离差转换后的时间 = 移动后的中间时间
let date = new Date(this.mouseDownMeddleTime).getTime() + offset * this.px_second * 1000;
date = this.boundary_time(date);
this.meddleTime = moment(date).format("YYYY-MM-DD HH:mm:ss");
this.$emit("mouseMove", this.meddleTime);
},
drow() {
//重置高宽清空画布
this.canvas.width = this.canvas.width;
this.canvas.height = this.canvas.height;
this.ctx.scale(this.dpr, this.dpr);
this.drowMark();
this.drowScaleLine();
this.drowMeddleLine(this.meddleTime);
},
// 画中间时间的线
drowMeddleLine(time) {
this.ctx.beginPath();
this.ctx.moveTo((this.canvasWidth / 2) - 3, 0);
// this.ctx.lineTo(this.canvasWidth / 2, 40);
this.ctx.lineTo((this.canvasWidth / 2) + 3,0);
this.ctx.lineTo((this.canvasWidth / 2) + 0.5,2);
this.ctx.lineTo((this.canvasWidth / 2) + 0.5,38);
this.ctx.lineTo((this.canvasWidth / 2) + 3,40);
this.ctx.lineTo((this.canvasWidth / 2) - 3,40);
this.ctx.lineTo((this.canvasWidth / 2) - 0.5,38);
this.ctx.lineTo((this.canvasWidth / 2) - 0.5,2);
this.ctx.closePath();
this.ctx.strokeStyle = this.colors.meddleLine;
// this.ctx.lineWidth = 2
this.ctx.stroke();
this.ctx.fillStyle=this.colors.meddleLine;
this.ctx.fill();
this.ctx.font = `12px serif`;
// this.ctx.fillText(time, this.canvasWidth / 2 - 50, 40);
},
// 画刻度线
drowScaleLine() {
// // 画canvas上部分的颜色
// this.ctx.fillStyle = "rgba(69, 72, 76, 0.5)";
// this.ctx.fillRect(0, 0, this.canvasWidth, 20);
// 画第一个刻度线
let time = new Date(this.getFirstLineTime()).getTime() - this.firstTime;
//几个像素点后画第一个刻度
let p = time / 1000 / this.px_second;
// 每条线之间的间隔 scaleLine_minute来确定每个格代表多长时间
let line_px = (this.scaleLine_minute * 60) / this.px_second;
for (let i = p; i <= (this.canvasWidth + 1); i += line_px) {
let date = this.firstTime + i * this.px_second * 1000;
let time1 = moment(date).format("HH:mm");
if (
(this.realTimeRange[0] && date < new Date(this.realTimeRange[0]).getTime()) ||
(this.realTimeRange[1] && date > (new Date(this.realTimeRange[1]).getTime() + 1000))
) {
continue;
}
let time = moment(date).format("HH:mm");
this.ctx.beginPath();
this.ctx.moveTo(i, 5);
this.ctx.lineTo(i, this.showTime(time) ? 17 : 10);
this.ctx.strokeStyle = this.showTime(time)?this.colors.scaleLine:this.colors.minscaleLine;
this.ctx.lineWidth = 1;
this.ctx.stroke();
this.ctx.fillStyle = this.colors.scaleLine;
this.ctx.font = `12px serif`;
if (i==0&&time == "00:00") {
// let show_time = moment(date).format("YYYY-MM-DD");
this.ctx.fillText(time, i, 32);
} else if (time == "00:00") {
// let show_time = moment(date).format("YYYY-MM-DD");
this.ctx.fillText(time, i- 30, 32);
} else if (this.showTime(time)) {
this.ctx.fillText(time, i - 15, 32);
}
}
},
// 计算默认中间时间
setStartMeddleTime() {
//根据可活动时间范围计算中间值
let time;
if (this.realTimeRange[0] && this.realTimeRange[1]) {
time = moment(
(new Date(this.realTimeRange[0]).getTime() + new Date(this.realTimeRange[1]).getTime()) / 2
).format("YYYY-MM-DD HH:mm:ss");
}
//设置默认中间时间(优先级:startMeddleTime参数指定>按有可活动时间范围计算>当前时间)
this.meddleTime = this.startMeddleTime || time || moment(new Date()).format("YYYY-MM-DD HH:mm:ss");
},
//获取刻度上的第一个时间
getFirstLineTime() {
const start = moment(this.firstTime);
//第一个时间不一定刚好落在刻度上,计算少了多少分才能到第一个刻度上(开始位置留白)
let remainder = this.scaleLine_minute - (start.minute() % this.scaleLine_minute);
remainder = remainder == this.scaleLine_minute ? 0:remainder;
return start.add(remainder, "minutes").format("YYYY-MM-DD HH:mm");
},
// 刻度时间显示(按级别显示)
showTime(time) {
// 每2时级
if (this.whole_hour >= 16) {
return [
"00:00",
"01:00",
"02:00",
"03:00",
"04:00",
"05:00",
"06:00",
"07:00",
"08:00",
"09:00",
"10:00",
"11:00",
"12:00",
"13:00",
"14:00",
"15:00",
"16:00",
"17:00",
"18:00",
"19:00",
"20:00",
"21:00",
"22:00",
"23:00",
].includes(time);
}
// 每1时级
if (this.whole_hour >= 6) {
return [
"00:00",
"01:00",
"02:00",
"03:00",
"04:00",
"05:00",
"06:00",
"07:00",
"08:00",
"09:00",
"10:00",
"11:00",
"12:00",
"13:00",
"14:00",
"15:00",
"16:00",
"17:00",
"18:00",
"19:00",
"20:00",
"21:00",
"22:00",
"23:00",
].includes(time);
}
// 每20分
if (this.whole_hour >= 4) {
return ["00", "20", "40"].find((item) => time.endsWith(item));
}
// 每10分
return ["00", "10", "20", "30", "40", "50"].find((item) => time.endsWith(item));
},
// 画标记的时间
drowMark() {
// 画canvas上部分的颜色
this.ctx.fillStyle = this.colors.scaleBar;
this.ctx.fillRect(0, 5, this.canvasWidth, 10);
this.markTime.forEach((item) => {
//标签所有范围超出时间区域(realTimeRange)就不渲染
if (
(this.realTimeRange[0] && new Date(item.endTime).getTime() < new Date(this.realTimeRange[0]).getTime()) ||
(this.realTimeRange[1] && new Date(item.beginTime).getTime() > new Date(this.realTimeRange[1]).getTime())
) {
return;
}
this.ctx.fillStyle = item.bgColor;
// 标签起点超时间效区域realTimeRange[0]就用realTimeRange[0]做为起点时间
let beginTime =
this.realTimeRange[0] && new Date(item.beginTime).getTime() < new Date(this.realTimeRange[0]).getTime()
? this.realTimeRange[0]
: item.beginTime;
// 标签终点超时间效区域realTimeRange[1]就用realTimeRange[1]做为终点时间
let endTime =
this.realTimeRange[1] && new Date(item.endTime).getTime() > new Date(this.realTimeRange[1]).getTime()
? this.realTimeRange[1]
: item.endTime;
let sx = (new Date(beginTime).getTime() - this.firstTime) / 1000 / this.px_second;
let ex = (new Date(endTime).getTime() - this.firstTime) / 1000 / this.px_second;
this.ctx.fillRect(sx, 0, ex - sx, 40);
});
},
//获取点坐标的距离(用于移动端双指放大缩小手势识别)
getDistance(a, b) {
const x = a.x - b.x;
const y = a.y - b.y;
return Math.hypot(x, y); // Math.sqrt(x * x + y * y);
},
//超出有效时间范围,返回边界值
boundary_time(date) {
//超出起点有效区域
if (this.realTimeRange[0] && date < new Date(this.realTimeRange[0]).getTime()) {
return new Date(this.realTimeRange[0]).getTime();
}
// 超出端点有效区域
else if (this.realTimeRange[1] && date > new Date(this.realTimeRange[1]).getTime()) {
return new Date(this.realTimeRange[1]).getTime();
} else {
return date;
}
},
//获取标记对象
getMark(date) {
return this.markTime.find(
(item) =>
new Date(item.beginTime).getTime() < new Date(date).getTime() &&
new Date(date).getTime() < new Date(item.endTime).getTime()
);
},
/**
*设置时间
* @param {String} date 中间时间
* @param @param {String| Array} timeRange 可切换到新时间范围(如下个录像时段),可选参数
*/
// setDate(date, timeRange) {
// if (timeRange) {
// this.setTimeRange(timeRange);
// }
// this.meddleTime = date;
// this.drow();
// },
/**
*设置时间轴可活动的时间区域
* @param {String| Array} timeRange 时间范围,不传默认组件timeRange参数原始值
*/
// setTimeRange(timeRange) {
// this.realTimeRange = timeRange || this.timeRange;
// if (typeof this.realTimeRange == "string") {
// let date = this.realTimeRange ? moment(this.realTimeRange).format("YYYY-MM-DD") : moment().format("YYYY-MM-DD");
// this.realTimeRange = [date + " 00:00:00", date + " 23:59:59:59"];
// }
// },
},
computed: {
// canvas最左边的时间的时间戳(滑动计算时间)
// firstTime() {
// return new Date(this.realTimeRange[0]).getTime();
// },
firstTime() {
return new Date(this.meddleTime).getTime() - ((this.px_second * this.canvasWidth) / 2) * 1000;
},
// 每个像素点对应多少秒(像素转时间和刻度)
px_second() {
let second = (this.whole_hour * 60 * 60) / this.canvasWidth;
// 保证不管缩小到什么宽度,刻度线都不会挤压在一起
if (second > this.minPxSecond) second = this.minPxSecond;
return second;
},
// 计算timeRange 兼容string |Array转换
realTimeRange() {
if (typeof this.timeRange == "string") {
let date = this.timeRange ? moment(this.timeRange).format("YYYY-MM-DD") : moment().format("YYYY-MM-DD");
return [date + " 00:00:00", date + " 23:59:59:59"];
} else {
return this.timeRange;
}
},
// 每个刻度线之间的多分钟(画刻度)
scaleLine_minute() {
if (this.whole_hour >= 20) {
//30分钟半小时
return 10;
}
if (this.whole_hour >= 16) {
return 20;
}
if (this.whole_hour >= 12) {
return 15;
}
if (this.whole_hour >= 8) {
return 10;
}
if (this.whole_hour >= 4) {
return 10;
}
return 2;
},
//计算需要重新绘制的参数,方便统一监听
changeProps() {
let { startMeddleTime, timeRange } = this;
this.setStartMeddleTime();
return { startMeddleTime, timeRange };
},
},
watch: {
//监听需要重新绘制的参数
changeProps: function (newV) {
this.drow();
},
},
};
// import Hammer from "./assets/hammerjs";
</script>
<style scoped lang="less">
.timeline-canvas{
// width:calc(100% - 80px)!important;
}
</style>
\ No newline at end of file
<template>
<div>
<div class="time-page">
<!-- 时间轴 -->
<div class="time-axis">
<div class="timeline-canvas-box">
<TimeLineCanvas id="timeline-canvas" ref="time_line" @click="clickCanvas" @change="changeDate" :mark-time="markTime" :time-range="timeRange" :isAutoPlay="isAutoPlay" :startMeddleTime="startMeddleTime" @mouseMove="mouseMoveDate"/>
</div>
</div>
<!-- 日期操作区 -->
<div class="date-axis">
<!-- 日期选择 -->
<div class="day-select-btn" @click="showDaySelectShow = true">
{{showDayStr}}
<i class="el-icon-caret-bottom day-select-btn-icon"></i>
</div>
<!-- 准确时间选择 -->
<div class="date-time-box">
<div class="date-time-left" @click="fastChangeStartTime(-10)">
10S
<img class="date-time-img" src="../../assets/kuaitui.png" alt="">
</div>
<div class="date-time-content" @click="timeSelectShow">
{{startTime}}
</div>
<div class="date-time-right" :class="[isCanFastRight?'date-time-right-show':'']" @click="fastChangeStartTime(10)">
<img v-if="isCanFastRight" class="date-time-img" src="../../assets/kuaijin.png" alt="">
<img v-else class="date-time-img" src="../../assets/kuaijin_no.png" alt="">
10S
</div>
</div>
<!-- 操作按钮 -->
<div class="operating-box">
<van-button v-if="isNoBack" type="info" size="mini" @click="ptzControlChange">{{ptzControlShow?'隐藏云台':'打开云台'}}</van-button>
<van-button v-else type="info" size="mini" @click="backRealTime">返回实时</van-button>
<!-- <div v-if="isNoBack" class="operating-btn" @click="ptzControlChange">{{ptzControlShow?'隐藏云台':'打开云台'}}</div> -->
<!-- <div v-else class="operating-btn" @click="backRealTime">返回实时</div> -->
</div>
</div>
<!-- 云台控制模块 -->
<div class="ptz-control-box" v-if="ptzControlShow">
<div class="ptz-control-left-box" :class="[ptzControlType=='left'?'ptz-left':ptzControlType=='top'?'ptz-top':ptzControlType=='right'?'ptz-right':ptzControlType=='bottom'?'ptz-bottom':'']">
<div class="ptz-control-left" @mousedown="ptzControlOneClick('left')" @mouseup="ptzControlStop" @mouseleave="ptzControlStop" @touchstart="ptzControlOneClick('left')" @touchend="ptzControlStop"></div>
<div class="ptz-control-top" @mousedown="ptzControlOneClick('top')" @mouseup="ptzControlStop" @mouseleave="ptzControlStop" @touchstart="ptzControlOneClick('top')" @touchend="ptzControlStop"></div>
<div class="ptz-control-right" @mousedown="ptzControlOneClick('right')" @mouseup="ptzControlStop" @mouseleave="ptzControlStop" @touchstart="ptzControlOneClick('right')" @touchend="ptzControlStop"></div>
<div class="ptz-control-bottom" @mousedown="ptzControlOneClick('bottom')" @mouseup="ptzControlStop" @mouseleave="ptzControlStop" @touchstart="ptzControlOneClick('bottom')" @touchend="ptzControlStop"></div>
<div class="ptz-control-content"></div>
</div>
<div class="ptz-control-right-box">
<div class="ptz-control-jia" @mousedown="ptzControlOneClick('jia')" @mouseup="ptzControlStop" @mouseleave="ptzControlStop" @touchstart="ptzControlOneClick('jia')" @touchend="ptzControlStop">+</div>
<div class="ptz-control-jian" @mousedown="ptzControlOneClick('jian')" @mouseup="ptzControlStop" @mouseleave="ptzControlStop" @touchstart="ptzControlOneClick('jian')" @touchend="ptzControlStop">-</div>
</div>
</div>
<!-- 日历下拉框 -->
<van-calendar v-model="showDaySelectShow" @confirm="showDayChange" color="rgb(1,167,245)" :min-date="minDay" :max-date="maxDay" row-height="40" :show-subtitle="false"/>
<!-- 时间下拉框 -->
<van-popup v-model="showTimeSelectShow" round position="bottom">
<van-picker show-toolbar title="播放时间选择" :columns="timeColumns" :default-index="defaultIndex" @cancel="timeSelectHide" @confirm="timeSelectConfirm"/>
</van-popup>
</div>
</div>
</template>
<script>
import TimeLineCanvas from "./timeline-canvas-wx.vue";
import moment from "moment";
export default {
name:'videoTime',
data() {
return {
startTimePickerOptions: {
selectableRange: '00:00:00 - 00:00:01'
},
showDayStr: moment().format('MM月DD日'),
showDay: moment().format('YYYY-MM-DD'),
showDaySelectShow:false,
showTimeSelectShow:false,
defaultIndex:'',
nowPlayTime: '',
timeAccuracy: '24',
splitScreen: 1,
startTime: '',
isAutoPlay: true,
width: "100%",
startMeddleTime: "",
timeRange: [],
markTime: [],
isNoBack:true,
maxDay: new Date(),
minDay: new Date(2022,1,1),
ptzControlShow:false,
isCanFastRight:false,
timeColumns:[],
ptzControlType:'',
}
},
components: {
TimeLineCanvas,
},
mounted() {
let that = this
this.timeRange = [moment().format('YYYY-MM-DD 00:00:00'), moment().format('YYYY-MM-DD 23:59:59')]
this.startTimePickerOptions.selectableRange = '00:00:00 - ' + moment().format('HH:mm:ss')
this.startTime = moment().format('HH:mm:ss')
this.nowPlayTime = this.startTime
this.startMeddleTime = moment().format('YYYY-MM-DD HH:mm:ss')
this.proTimeColumns()
},
beforeDestroy() {
this.stopPlay()
},
methods: {
startPlay() {
if(this.isAutoPlay) {
this.stopPlay()
}
this.isNoBack = true
this.timeRange = [moment().format('YYYY-MM-DD 00:00:00'), moment().format('YYYY-MM-DD 23:59:59')]
this.markTime = [{
beginTime: moment().format('YYYY-MM-DD 00:00:00'),
endTime: moment().format('YYYY-MM-DD HH:mm:ss'),
bgColor: "rgba(255,153,0,0.4)",
text: "",
}]
this.startTimePickerOptions.selectableRange = '00:00:00 - ' + moment().format('HH:mm:ss')
this.startTime = moment().format('HH:mm:ss')
this.showDayStr = moment().format('MM月DD日')
this.showDay = moment().format('YYYY-MM-DD')
this.startMeddleTime = moment().format('YYYY-MM-DD HH:mm:ss')
this.$refs.time_line.play(moment().format('YYYY-MM-DD HH:mm:ss'));
this.isAutoPlay = true
},
stopPlay() {
this.isAutoPlay = false
this.isNoBack = true
this.markTime = []
this.timeRange = [moment().format('YYYY-MM-DD 00:00:00'), moment().format('YYYY-MM-DD 23:59:59')]
this.startTime = moment().format('HH:mm:ss')
this.showDayStr = moment().format('MM月DD日')
this.showDay = moment().format('YYYY-MM-DD')
this.startMeddleTime = moment().format('YYYY-MM-DD HH:mm:ss')
if(this.$refs.time_line) {
this.$refs.time_line.stop();
}
},
showDayChange(val,type) {
console.log(val)
this.showDaySelectShow = false
this.showDayStr = moment(val).format('MM月DD日')
this.showDay = moment(val).format('YYYY-MM-DD')
if (this.showDay == moment().format('YYYY-MM-DD') &&!type) {
this.isNoBack = true
this.startTime = moment().format('HH:mm:ss')
this.startTimePickerOptions.selectableRange = '00:00:00 - ' + moment().format('HH:mm:ss')
this.markTime = [{
beginTime: moment().format('YYYY-MM-DD 00:00:00'),
endTime: moment().format('YYYY-MM-DD HH:mm:ss'),
bgColor: "rgba(255,153,0,0.4)",
text: "",
}]
} else {
this.isNoBack = false
this.startTimePickerOptions.selectableRange = '00:00:00 - 23:59:59'
this.markTime = [{
beginTime: this.showDay + ' 00:00:00',
endTime: this.showDay + ' 23:59:59',
bgColor: "rgba(255,153,0,0.4)",
text: "",
}]
}
this.startMeddleTime = moment(this.showDay + ' ' + this.startTime).format('YYYY-MM-DD HH:mm:ss')
if(!type) {
this.$emit('videoTimeChange',this.startMeddleTime)
}
if(this.timeAccuracy == '24') {
this.timeRange = [this.showDay + ' 00:00:00', this.showDay + ' 23:59:59']
} else {
let startTime = moment(this.startMeddleTime).subtract((this.timeAccuracy/2), "hours").format('YYYY-MM-DD HH:mm:ss')
let endTime = moment(this.startMeddleTime).add((this.timeAccuracy/2), "hours").format('YYYY-MM-DD HH:mm:ss')
startTime = moment(startTime).format('YYYY-MM-DD') != this.showDay?this.showDay + ' 00:00:00':startTime;
endTime = moment(endTime).format('YYYY-MM-DD') != this.showDay?this.showDay + ' 23:59:59':endTime;
this.timeRange = [startTime, endTime]
}
this.nowPlayTime = moment(this.startMeddleTime).format('HH:mm:ss')
this.ptzControlShow = false
this.isCanFast()
this.proTimeColumns()
},
// 开始播放时间改变
startTimeChange(val) {
this.showTimeSelectShow = false
this.startTime = val
this.startMeddleTime = moment(this.showDay + ' ' + val).format('YYYY-MM-DD HH:mm:ss')
this.$emit('videoTimeChange',this.startMeddleTime)
this.nowPlayTime = moment(val).format('HH:mm:ss')
this.isNoBack = this.startMeddleTime == moment().format('YYYY-MM-DD HH:mm:ss')
this.ptzControlShow = false
this.isCanFast()
},
// 时间选择点击
timeSelectShow() {
this.showTimeSelectShow = true
},
timeSelectHide() {
this.showTimeSelectShow = false
},
timeSelectConfirm(val) {
this.showTimeSelectShow = false
console.log(val)
let timsStr = val.join(':')
this.startTimeChange(timsStr)
},
// 返回实时
backRealTime() {
this.startTime = moment().format('HH:mm:ss')
this.showDayChange(moment().format('YYYY-MM-DD'))
this.ptzControlShow = false
this.isCanFastRight = false
},
// 时间轴方法
clickCanvas(date) {
// console.log(date);
this.startTime = moment(date).format('HH:mm:ss')
this.isNoBack = moment(date).format('YYYY-MM-DD HH:mm:ss') == moment().format('YYYY-MM-DD HH:mm:ss')
this.ptzControlShow = false
this.$emit('videoTimeChange',date)
this.isCanFast()
},
changeDate(date, status) {
// console.log("选择时间:" + date + " 播放状态:" + status);
this.nowPlayTime = moment(date).format('HH:mm:ss')
if(!this.showTimeSelectShow){
this.startTime = this.nowPlayTime
}
this.isCanFast()
this.$forceUpdate()
if(this.startTime == '23:59:59') {
setTimeout(()=>{
this.startTime = '00:00:00'
this.showDayChange(moment(date).add(1,'days').format('YYYY-MM-DD'),'start')
this.$refs.time_line.play(moment(date).add(1,'days').format('YYYY-MM-DD 00:00:00'));
},900)
} else {
this.proTimeColumns()
}
if (moment(date).format('YYYY-MM-DD') == moment().format('YYYY-MM-DD')) {
this.markTime = [{
beginTime: moment().format('YYYY-MM-DD 00:00:00'),
endTime: moment().format('YYYY-MM-DD HH:mm:ss'),
bgColor: "rgba(255,153,0,0.4)",
text: "",
}]
}
// 更新时间下拉选项
},
// 配置时间下拉选项列表
proTimeColumns() {
if(this.showTimeSelectShow){
return false;
}
let startTimeArr = this.startTime.split(':')
let timeColumns = []
let maxHour = 23
let maxMin = 59
let maxSec = 59
if (this.showDay == moment().format('YYYY-MM-DD')) {
let nowDate = new Date()
maxHour = nowDate.getHours()
maxMin = nowDate.getMinutes()
maxSec = nowDate.getSeconds()
}
this.defaultIndex = startTimeArr[0]
for(let a = 0; a <= maxHour;a++) {
timeColumns[a] = {
text: a<10?'0'+a:a+'',
defaultIndex:startTimeArr[1]*1,
children:[]
}
let showMaxMin = a==maxHour?maxMin:59;
for(let b=0;b<=showMaxMin;b++) {
timeColumns[a].children.push({
text:b<10?'0'+b:b+'',
defaultIndex:startTimeArr[2]*1,
children:[]
})
let showMaxSec = a==maxHour&&b==maxMin?maxSec:59;
for(let c=0;c<=showMaxSec;c++) {
timeColumns[a].children[b].children.push({
text:c<10?'0'+c:c+'',
})
}
}
}
this.timeColumns = timeColumns
},
// 判断当前时间是否可以进行快进
isCanFast() {
let playTime = new Date(this.showDay + ' ' + this.startTime).getTime()
let nowTime = new Date().getTime()
this.isCanFastRight = (nowTime - playTime) > 10000
},
// 时间线移动
mouseMoveDate(date) {
this.startTime = moment(date).format('HH:mm:ss')
this.ptzControlShow = false
this.$forceUpdate()
},
// 云台控制显示
ptzControlChange() {
this.ptzControlShow = !this.ptzControlShow
},
// 云台控制单击
ptzControlOneClick(type) {
this.ptzControlType = type
this.$emit('ptzControlClick',type)
},
// 云台控制结束
ptzControlStop() {
this.ptzControlType = ''
this.$emit('ptzControlStop')
},
// 快退/快进
fastChangeStartTime(val) {
let newTime = val>0?moment(this.showDay + ' ' + this.startTime).add(val, "seconds").format('YYYY-MM-DD HH:mm:ss'):moment(this.showDay + ' ' + this.startTime).subtract(val*-1, "seconds").format('YYYY-MM-DD HH:mm:ss');
let newDay = newTime.slice(0,10)
if(newDay == this.showDay) {
this.startTimeChange(newTime.slice(11))
} else {
this.startTime = newTime.slice(11)
this.showDayChange(newDay)
}
},
}
}
</script>
<style scoped lang="less">
.time-page {
background: rgba(0, 0, 0, 0.7);
width: 100%;
height: 82px;
position: relative;
.time-operation-module {
padding: 0 10px;
height: 40px;
display: flex;
align-items: center;
justify-content: space-between;
position: relative;
top:3px;
.operation-module-left {
position: relative;
z-index: 2;
display: inline-flex;
align-items: center;
color: #ffffff;
.lookPic{
// margin-left: 20px;
color: #ffffff;
font-size: 15px;
cursor: pointer;
}
}
.operation-module-center{
position: absolute;
top:0px;
left:0px;
width: 100%;
height: 100%;
z-index: 1;
display: flex;
align-items: center;
justify-content: center;
.go-back-realtime-btn {
margin-left: 20px;
}
.time-input-box{
width: 110px;
display: inline-flex;
align-items: center;
height: 26px;
border: 1px solid #dcdcdc;
border-radius: 4px;
color:#fff;
.time-input-list{
width: 85px;
height: 26px;
border-right: 1px solid #dcdcdc;
display: inline-flex;
align-items: center;
justify-content: center;
}
.time-input-btn{
cursor: pointer;
width: 25px;
font-size: 14px;
display: inline-flex;
align-items: center;
justify-content: center;
}
.time-input-line{
height: 26px;
line-height: 26px;
}
/deep/.el-input{
width: 24px;
display: inline-flex;
align-items: center;
}
/deep/.el-input__inner{
padding: 0px!important;
background: transparent!important;
color:#fff!important;
border: 0px!important;
box-shadow: none!important;
text-align: center!important;
}
}
}
.operation-module-right {
position: relative;
z-index: 2;
display: inline-flex;
align-items: center;
color: #ffffff;
.fullScreen{
font-size: 16px;
cursor: pointer;
}
.split-screen-control {
display: inline-flex;
height: 100%;
align-items: center;
color: #ffffff;
margin-right: 20px;
.split-screen-text {
display: inline-flex;
align-items: center;
justify-content: center;
width: 40px;
text-align: center;
color: #ffffff;
}
.el-dropdown{
height: 100%;
display: inline-flex;
align-items: center;
cursor: pointer;
}
}
.time-line-accuracy {
height: 100%;
display: inline-flex;
align-items: center;
color: #ffffff;
margin-right: 20px;
.time-accuracy-text {
display: inline-block;
width: 65px;
text-align: center;
color: #ffffff;
}
}
.play-time-show {
font-size: 12px !important;
color: #ffffff;
margin-right: 20px;
}
}
/deep/.el-input {
height: 26px !important;
.el-input__inner {
padding-right: 10px;
}
}
}
.time-axis {
display: flex;
align-items: center;
justify-content: center;
padding: 0;
border-bottom: 1px solid #666666;
.timeline-icon-box {
display: inline-flex;
align-items: center;
justify-content: center;
background: rgba(255, 255, 255, 0.8);
color: #111;
border-radius: 20px;
height: 24px;
width: 24px;
font-size: 16px;
cursor: pointer;
}
.timeline-canvas-box{
width: 100%;
height: 40px;
position: relative;
}
}
.date-axis{
height: 40px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 10px;
.day-select-btn{
display: inline-flex;
align-items: center;
font-size: 14px;
color:#fff;
width: 76px;
.day-select-btn-icon{
margin-left: 2px;
}
}
.date-time-box{
display: inline-flex;
align-items: center;
color:#fff;
.date-time-left{
height: 40px;
font-size: 12px;
display: inline-flex;
align-items: center;
}
.date-time-right{
height: 40px;
font-size: 12px;
display: inline-flex;
align-items: center;
color:#aaa;
}
.date-time-right-show{
color:#fff;
}
.date-time-img{
width: 16px;
height: 16px;
margin: 0 2px;
position: relative;
top:-1px;
}
.date-time-content{
width: 54.5px;
border: 1px solid #ffffff;
border-radius: 3px;
padding: 3px;
font-size: 14px;
margin: 0 7px;
}
}
.operating-box{
width: 76px;
color: #ffffff;
font-size: 14px;
text-align: right;
.operating-btn{
color: #ffffff;
font-size: 14px;
}
}
}
.timeline-canvas-bg{
width: 100%;
height: 83px;
position: absolute;
bottom:0px;
left:0px;
z-index: 10;
}
.ptz-control-box{
width: 100vw;
display: flex;
align-items: center;
justify-content: center;
position: absolute;
top:130px;
.ptz-control-left-box{
width: 150px;
height: 150px;
background: rgba(215,215,215,0.9);
position: relative;
border-radius: 100px;
overflow: hidden;
.ptz-control-left{
position: absolute;
width: 0;
height: 0;
border-top: 14px solid transparent;
border-bottom: 14px solid transparent;
border-right: 18px solid #83c5e0;
position: absolute;
display: inline-block;
top: calc(50% - 14px);
left: 10px;
}
.ptz-control-top{
position: absolute;
width: 0;
height: 0;
border-left: 14px solid transparent;
border-right: 14px solid transparent;
border-bottom: 18px solid #83c5e0;
position: absolute;
display: inline-block;
left: calc(50% - 14px);
top: 10px;
}
.ptz-control-right{
position: absolute;
width: 0;
height: 0;
border-top: 14px solid transparent;
border-bottom: 14px solid transparent;
border-left: 18px solid #83c5e0;
position: absolute;
display: inline-block;
top: calc(50% - 14px);
left: calc(100% - 28px);
}
.ptz-control-bottom{
position: absolute;
width: 0;
height: 0;
border-left: 14px solid transparent;
border-right: 14px solid transparent;
border-top: 18px solid #83c5e0;
position: absolute;
display: inline-block;
left: calc(50% - 14px);
top: calc(100% - 28px);
}
.ptz-control-content{
width: 50px;
height: 50px;
background: #03a7ef;
position: absolute;
border-radius: 50px;
left: calc(50% - 25px);
top: calc(50% - 25px);
}
}
.ptz-left{
background-image: linear-gradient(90deg, rgba(131,197,224,0.8) 0%, rgba(100, 143, 252, 0) 30%);
}
.ptz-top{
background-image: linear-gradient(rgba(131,197,224,0.8) 0%, rgba(100, 143, 252, 0) 30%);
}
.ptz-right{
background-image: linear-gradient(270deg, rgba(131,197,224,0.8) 0%, rgba(100, 143, 252, 0) 30%);
}
.ptz-bottom{
background-image: linear-gradient(0deg, rgba(131,197,224,0.8) 0%, rgba(100, 143, 252, 0) 30%);
}
.ptz-control-right-box{
display: inline-flex;
align-items: center;
justify-content: center;
color: #03a7ef;
margin-left: 50px;
.ptz-control-jia,.ptz-control-jian{
width: 30px;
height: 30px;
line-height: 30px;
text-align: center;
font-size: 30px;
border-radius: 4px;
border: 1px solid #03a7ef;
&:active{
background-image: radial-gradient(circle at center,rgba(29,141,216,.8) 0,rgba(100,143,252,0) 80%);
}
}
.ptz-control-jia{
margin-right: 30px;
}
}
}
}
/deep/.el-button--primar:hover{
background-color: rgba(64,118,247,0.7) !important;
border-color: rgba(64,118,247,0.7) !important;
}
/deep/.el-input-group__append{
padding: 0 3px!important;
.el-button{
padding: 0px!important;
margin: 0px!important;
}
}
.split-screen-img{
width: 20px;
height: 20px;
}
/deep/.van-calendar__popup{
height: 64%!important;
}
</style>
\ No newline at end of file
......@@ -87,20 +87,12 @@
<script>
import videoTime from './videoTime.vue'
import jPlayer from '@/components/jPlayer';
// import jPlayer0 from '../jPlayer/index.vue'
// import jPlayer1 from '../jPlayer/index.vue'
// import jPlayer2 from '../jPlayer/index.vue'
// import jPlayer3 from '../jPlayer/index.vue'
import moment from 'moment'
export default {
name: 'JPlayerWeb',
components:{
videoTime,
jPlayer,
// jPlayer0,
// jPlayer1,
// jPlayer2,
// jPlayer3
},
data() {
return {
......@@ -153,9 +145,10 @@ export default {
}
},
mounted() {
window.playWebVideo = this.playWebVideo;
},
methods: {
init(obj) {
playWebVideo(obj) {
if (!obj.address || !obj.channelId) {
console.error('传递URL参数有误,请确认 address 和 channelId 是否正确。');
return false
......
......@@ -5,15 +5,16 @@
<el-button type="primary" @click="addPlayer({channelId: '20000000001310000008',address: '52.130.155.147'})">添加视频一</el-button>
<el-button type="primary" @click="addPlayer({channelId: '20000000001310000008',address: '52.130.155.147'})">添加视频二</el-button>
</div>
<indexPlayer ref="indexPlayer" />
<iframe id="iframe" name="iframe" ref="iframe" style="width: 100vw;height:calc(100vh - 60px);" src="http://localhost:9091/#/jplayer-web" frameborder="0"></iframe>
<!-- <iframe name="iframe" ref="iframe" style="width: 100vw;height:calc(100vh - 60px);" src="http://192.168.1.117:8080/" frameborder="0"></iframe> -->
</div>
</template>
<script>
import indexPlayer from './index.vue';
// import indexPlayer from './index.vue';
export default {
name: 'jplayerWebDemo',
components: {
indexPlayer,
// indexPlayer,
},
data() {
return {
......@@ -23,7 +24,9 @@ export default {
},
methods: {
addPlayer(obj) {
this.$refs.indexPlayer.init(obj);
// window.playWebVideo(obj)
window.parent.document.getElementById('iframe').contentWindow.playWebVideo(obj)
// document.getElementById('iframe').contentWindow.playWebVideo(obj);
},
},
}
......
......@@ -118,8 +118,6 @@ export default {
isNoBack:true,
isFullScreen:false,
screenImgTotal:0,
screenImgList:[],
mouseMoveTime:'',
isMouseMove:false,
mouseMoveTimeFocus:false,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!