济菏高速业务端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
4.2 KiB

1 year ago
<!--
* @Author: Praise-Sun 18053314396@163.com
* @Date: 2022-09-25 08:41:42
* @LastEditors: Praise-Sun 18053314396@163.com
* @LastEditTime: 2023-01-30 09:10:22
* @FilePath: \tunnel-ui\src\views\websocket.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template></template>
1 year ago
<script>
1 year ago
import { mapState } from "vuex";
1 year ago
export default {
name: "Websocket",
data() {
return {};
},
computed: {
...mapState({
1 year ago
token: (state) => state.user.token,
websocket: (state) => state.user.websocket,
}),
1 year ago
},
watch: {
1 year ago
websocket({ password, path, port, interval }) {
// debugger
// console.log(path)
// console.log(port)
// console.log(location.hostname )
1 year ago
// 建立 websocket 连接
this.socket.initialize({
// url: 'ws://' + location.hostname + ':' + port + path,
12 months ago
url: 'wss://' + location.hostname + ':' + window.location.port + '/ws' || 80 + '/ws',
// url: 'ws://10.168.77.128:7789/ws',
// url: "ws://10.7.179.15" + ":" + port + path,
1 year ago
// url: "ws://10.168.64.171" + ":" + port + path,
// url: 'ws://10.168.78.127'+ ':' + port + path,
1 year ago
password: password,
tokenSN: this.token,
1 year ago
heartRate: interval,
1 year ago
});
12 months ago
1 year ago
this.socket.onopen = () => {};
1 year ago
this.socket.onmessage = (message) => {
12 months ago
1 year ago
// debugger
message = JSON.parse(message);
1 year ago
const method = message.method;
1 year ago
if (method !== "event") {
1 year ago
return;
}
const params = message.params;
const subEvent = params.subEvent;
const content = params.content;
let contentList;
12 months ago
if(_.isString(content)){
contentList = JSON.parse(content);
12 months ago
}else{
contentList = content;
12 months ago
}
1 year ago
switch (subEvent) {
case "payment_webSocket_send":
this.$store.commit("PAYMENT", content);
break;
case "carList":
this.$store.commit("CARLIST", content);
break;
case "realTimeLaneTrajectory":
this.$store.commit("REALTIMELANETRAJECTORY", content);
break;
case "sdEventList":
//弹窗
this.$store.commit("SDEVENTLIST", contentList.sdEventList);
break;
case "sdSvgEventList":
//弹窗
this.$store.commit("SDSVGEVENTLIST", contentList.sdSvgEventList);
1 year ago
break;
1 year ago
case "radarDataList":
this.$store.commit("RADARDATALIST", contentList.radarDataList);
break;
case "deviceStatus":
this.$store.commit("DEVICESTATUS", contentList.deviceStatus);
break;
case "deviceStatusChangeLog":
this.$store.commit(
"DEVICESTATUSCHANGELOG",
contentList.deviceStatusChangeLog
);
break;
case "eventFlow":
this.$store.commit("EVENTFLOW", contentList.eventFlow);
break;
case "eventUntreatedNum":
this.$nextTick(() => {
this.$store.commit("EVENTUNTREATEDNUM", contentList);
});
12 months ago
break;
case "0":
case "1":
this.$emit("newEvent", params);
1 year ago
break;
case "deviceState":
this.EventBus.$emit("deviceState", contentList );
break;
1 year ago
default:
}
1 year ago
};
},
1 year ago
},
1 year ago
created() {},
methods: {},
12 months ago
mounted(){
let _this = this;
12 months ago
if (process.env.NODE_ENV == "development"){
//测试websocket用的
12 months ago
return
let deviceState = "0";
12 months ago
document.onkeydown = function (e) {
deviceState == "0" ? deviceState = "1" : deviceState = "0";
12 months ago
if (e.code == 'Space') {
let params = {
"subEvent": "deviceState",
"content": [
{
"id": 896,
11 months ago
"iotDeviceId": "K67+240tynb",
"deviceType":"2",
deviceState
}
]
12 months ago
};
_this.EventBus.$emit("deviceState", params.content );
12 months ago
}
12 months ago
}
}
12 months ago
}
1 year ago
};
</script>