eventTab.vue
7.43 KB
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
<template>
<div>
<el-tabs v-model="activeName2" @tab-click="handleClick">
<el-tab-pane label="全卡口" name="first">
<Allalarm
@showDitail="showDitail"
:itemData="resultData"
ref="allalarm"
></Allalarm>
</el-tab-pane>
<el-tab-pane label="机动车" name="second">
<CarAlarm
@showDitail="showDitail"
:itemData="resultData"
ref="caralarm"
></CarAlarm>
</el-tab-pane>
<el-tab-pane label="违法" name="third">
<IllegalAlarm
@showDitail="showDitail"
:itemData="resultData"
ref="illegalalarm"
></IllegalAlarm>
</el-tab-pane>
<el-tab-pane label="事件" name="fourth">
<Eventalarm
@showDitail="showDitail"
:itemData="resultData"
ref="eventalarm"
></Eventalarm>
</el-tab-pane>
</el-tabs>
<div>
<EventDetail
ref="detail"
@closeDetailModal="closeDetailModal"
:curData="curdata"
></EventDetail>
</div>
</div>
</template>
<script>
var canvas = document.createElement("canvas");
// 分类报警
import Allalarm from "./eventData/allEvent.vue";
import CarAlarm from "./eventData/carEvent.vue";
import IllegalAlarm from "./eventData/illegalEvent.vue";
import Eventalarm from "./eventData/eventAlarm.vue";
import EventDetail from "./eventDetail.vue";
import { mapState } from "vuex";
import {config} from '../../../public/js/config.js'
export default {
data() {
return {
activeName2: "first",
resultData: [],
connect_id: "",
curdata: "",
curentId: "",
cws: "",
keepAlive: "",
curType: "",
quitws: false
};
},
components: {
Allalarm,
CarAlarm,
IllegalAlarm,
Eventalarm,
EventDetail
},
computed: {
// ...mapState(["eventData", "wsclient"])
},
methods: {
handleClick(tab, event) {},
dataInit(cid, type) {
debugger
this.$refs.allalarm.allAlarmData = [];
this.$refs.caralarm.carAlarmData = [];
this.$refs.illegalalarm.illAlarmData = [];
this.$refs.eventalarm.eventAlarmData = [];
this.resultData = "";
this.curType = type;
this.carItems = [];
let send_mesage =
'{"type":"request","connect_id": "' +
this.connect_id +
'","subtask_id":"' +
cid +
'"}';
console.log("当前任务id", cid);
this.cws.send(send_mesage);
this.curentId = cid;
},
showDitail(data) {
// this.$refs.ocxvido.show = false;
this.$refs.detail.detailInfo(data);
},
closeDetailModal() {
this.$store.commit("setocxstate", 1);
},
connectwebsocket(type) {
let that = this;
this.connect_id = new Date().getTime();
if(config.https) {
this.cws = new WebSocket(
`wss://${this.$api.wsIP}/websocket/v1/recv_data/connects/${this.connect_id}`
);
} else {
this.cws = new WebSocket(
`ws://${this.$api.wsIP}/websocket/v1/recv_data/connects/${this.connect_id}`
);
}
this.cws.onopen = () => {
console.log("ws事件推送服务连接成功");
if (type == 1) {
let send_mesage =
'{"type":"request","connect_id": "' +
this.connect_id +
'","subtask_id":"' +
this.curentId +
'"}';
this.cws.send(send_mesage);
}
};
this.cws.onmessage = evt => {
let data = JSON.parse(evt.data);
if (data.command) {
console.log("心跳连接正常!");
} else if (data.type == "response") {
console.log("请求任务推送成功");
} else if (data.event_cate) {
//根据抓拍图片坐标显示精确位置
if (data.subtask_id != this.curentId) {
return;
}
if (data.event_cate != "flow") {
console.log(data);
try {
data.picsEmpty = data.pics.length == 0 ? true : false;
if (data.pics[0].object_rect != undefined) {
data.bigpic =
data.pics[0].src_url ||
"data:image/jpeg;base64," + data.pics[0].pic_base64;
let img = new Image();
let picOffset = data.pics[0].object_rect;
canvas.width =
data.pics[0].width * (picOffset.right - picOffset.left) ||
189;
canvas.height =
data.pics[0].hight * (picOffset.bottom - picOffset.top) ||
246;
let ctx = canvas.getContext("2d");
//设置图片跨域访问
img.setAttribute("crossOrigin", "anonymous");
const that = this;
img.onload = function() {
//画图
let width = img.width * (picOffset.right - picOffset.left);
let height = img.height * (picOffset.bottom - picOffset.top);
if (width == 0) width = img.width;
if (height == 0) height = img.height;
ctx.drawImage(
img,
img.width * picOffset.left,
img.height * picOffset.top,
width,
height,
0,
0,
canvas.width,
canvas.height
);
// ctx.drawImage(img,0,0,width,height, 0, 0, canvas.width,canvas.height);
data.pic = canvas.toDataURL("image/jpeg");
};
img.src =
data.pics[0].src_url ||
"data:image/jpeg;base64," + data.pics[0].pic_base64;
} else {
data.pic =
data.pics[0].src_url ||
"data:image/jpeg;base64," + data.pics[0].pic_base64;
data.bigpic =
data.pics[0].src_url ||
"data:image/jpeg;base64," + data.pics[0].pic_base64;
}
that.$buildCode.init(data);
setTimeout(() => {
that.resultData = data;
}, 500);
} catch (err) {
console.log("err" + err);
}
}
}
};
try {
this.keepAlive = setInterval(() => {
let send_mesage =
'{"type":"request","id":"' +
new Date().getTime() +
'","mts":"' +
new Date().getTime() +
'","command": "get /websocket/v1/recv_data/connects/' +
this.connect_id +
'/keep_alive"}';
if (that.cws.readyState == 1) {
that.cws.send(send_mesage);
} else {
clearInterval(that.keepAlive);
that.connectwebsocket(1);
console.log("推送服务断开连接");
}
}, 20000);
} catch (err) {
console.log(err);
}
}
},
watch: {},
beforeMount() {
this.connectwebsocket();
//监听成功
this.cws.onopen = function() {
console.log("ws事件推送服务连接成功");
};
//监听断开
this.cws.onclose = () => {
if (this.quitws) return;
window.clearInterval(this.keepAlive);
this.connectwebsocket(1);
};
},
beforeDestroy() {
this.cws.close();
this.quitws = true;
try {
window.clearTimeout(this.keepAlive);
} catch (error) {
console.log(error);
}
}
};
</script>