|
@@ -2,10 +2,8 @@
|
|
|
<div class="analysis">
|
|
|
<a-row>
|
|
|
<a-col :sm="24" :md="12" :xl="12">
|
|
|
- <h2 style="text-align: center;">{{this.$route.params.title}}</h2>
|
|
|
- <img
|
|
|
- src="@/assets/img/20211209164229.png"
|
|
|
- />
|
|
|
+ <h2 style="text-align: center">{{ this.$route.params.title }}</h2>
|
|
|
+ <img src="@/assets/img/20211209164229.png" />
|
|
|
</a-col>
|
|
|
|
|
|
<a-col :sm="24" :md="12" :xl="12">
|
|
@@ -68,37 +66,53 @@
|
|
|
</a-col>
|
|
|
</a-row>
|
|
|
|
|
|
- <a-card :loading="loading" style="margin-top: 24px" :bordered="false">
|
|
|
+ <a-card style="margin-top: 24px" :bordered="false">
|
|
|
<div class="salesCard">
|
|
|
<a-row>
|
|
|
<a-col :xl="12" :lg="24" :md="24" :sm="24" :xs="24">
|
|
|
<a-card
|
|
|
- :bodyStyle="{display: 'flex', justifyContent: 'center',alignItems: 'center'}"
|
|
|
+ :bodyStyle="{
|
|
|
+ display: 'flex',
|
|
|
+ justifyContent: 'center',
|
|
|
+ alignItems: 'center',
|
|
|
+ }"
|
|
|
>
|
|
|
- <chart-1 ref="chart1" />
|
|
|
+ <chart-1 ref="chart1" :id="23" />
|
|
|
</a-card>
|
|
|
</a-col>
|
|
|
- <a-col :xl="12" :lg="24" :md="24" :sm="24" :xs="24">
|
|
|
+ <a-col :xl="12" :lg="24" :md="24" :sm="24" :xbelts="24">
|
|
|
<a-card
|
|
|
- :bodyStyle="{display: 'flex', justifyContent: 'center',alignItems: 'center'}"
|
|
|
+ :bodyStyle="{
|
|
|
+ display: 'flex',
|
|
|
+ justifyContent: 'center',
|
|
|
+ alignItems: 'center',
|
|
|
+ }"
|
|
|
>
|
|
|
- <chart-2 ref="chart2" />
|
|
|
+ <chart-2 ref="chart2" :id="24" />
|
|
|
</a-card>
|
|
|
</a-col>
|
|
|
</a-row>
|
|
|
<a-row>
|
|
|
<a-col :xl="12" :lg="24" :md="24" :sm="24" :xs="24">
|
|
|
<a-card
|
|
|
- :bodyStyle="{display: 'flex', justifyContent: 'center',alignItems: 'center'}"
|
|
|
+ :bodyStyle="{
|
|
|
+ display: 'flex',
|
|
|
+ justifyContent: 'center',
|
|
|
+ alignItems: 'center',
|
|
|
+ }"
|
|
|
>
|
|
|
- <chart-3 ref="chart3" />
|
|
|
+ <chart-3 ref="chart3" :id="25" />
|
|
|
</a-card>
|
|
|
</a-col>
|
|
|
<a-col :xl="12" :lg="24" :md="24" :sm="24" :xs="24">
|
|
|
<a-card
|
|
|
- :bodyStyle="{display: 'flex', justifyContent: 'center',alignItems: 'center'}"
|
|
|
+ :bodyStyle="{
|
|
|
+ display: 'flex',
|
|
|
+ justifyContent: 'center',
|
|
|
+ alignItems: 'center',
|
|
|
+ }"
|
|
|
>
|
|
|
- <chart-4 ref="chart4" />
|
|
|
+ <chart-4 ref="chart4" :id="26" />
|
|
|
</a-card>
|
|
|
</a-col>
|
|
|
</a-row>
|
|
@@ -112,15 +126,12 @@ import Chart1 from "./Chart1.vue";
|
|
|
import Chart2 from "./Chart2.vue";
|
|
|
import Chart3 from "./Chart3.vue";
|
|
|
import Chart4 from "./Chart4.vue";
|
|
|
+import { mapState } from "vuex";
|
|
|
|
|
|
export default {
|
|
|
name: "Analysis",
|
|
|
data() {
|
|
|
return {
|
|
|
- path: "ws://124.71.174.198:8080/ws/belt/",
|
|
|
- beltId: 1,
|
|
|
- isFirst: 1,
|
|
|
- ws: {},
|
|
|
circle1: 1,
|
|
|
circle2: 1,
|
|
|
circle3: 1,
|
|
@@ -136,98 +147,34 @@ export default {
|
|
|
};
|
|
|
},
|
|
|
methods: {
|
|
|
- change_color: function () {
|
|
|
- this.circle1 = Math.round(Math.random() * 2) % 2;
|
|
|
- this.circle2 = Math.round(Math.random() * 2) % 2;
|
|
|
- this.circle3 = Math.round(Math.random() * 2) % 2;
|
|
|
- this.circle4 = Math.round(Math.random() * 2) % 2;
|
|
|
- this.circle5 = Math.round(Math.random() * 2) % 2;
|
|
|
- this.circle6 = Math.round(Math.random() * 2) % 2;
|
|
|
- this.circle7 = Math.round(Math.random() * 2) % 2;
|
|
|
- this.circle8 = Math.round(Math.random() * 2) % 2;
|
|
|
- this.circle9 = Math.round(Math.random() * 2) % 2;
|
|
|
- this.circle10 = Math.round(Math.random() * 2) % 2;
|
|
|
- },
|
|
|
- //websocket连接后端数据改变颜色
|
|
|
- //1:为绿色,0:为红色
|
|
|
- changecolor_websocket: function () {
|
|
|
- this.ws = new WebSocket(this.path);
|
|
|
- //监听是否连接成功
|
|
|
- this.ws.onopen = () => {
|
|
|
- console.log("ws连接状态:" + this.ws.readyState);
|
|
|
+ initWebSocket() {
|
|
|
+ // 连接错误
|
|
|
+ this.websocket.onerror = () => {
|
|
|
+ console.log(
|
|
|
+ "WebSocket连接发生错误 状态码:" + this.websocket.readyState
|
|
|
+ );
|
|
|
};
|
|
|
- //接听服务器发回的信息并处理展示
|
|
|
- this.ws.onmessage = (res) => {
|
|
|
- console.log("接收到来自服务器的消息:");
|
|
|
- console.log(res.data);
|
|
|
- this.circle1 = res.data[0];
|
|
|
- this.circle2 = res.data[1];
|
|
|
- this.circle3 = res.data[2];
|
|
|
- this.circle4 = res.data[3];
|
|
|
- this.circle5 = res.data[4];
|
|
|
- this.circle6 = res.data[5];
|
|
|
- this.circle7 = res.data[6];
|
|
|
- this.circle8 = res.data[7];
|
|
|
- this.circle9 = res.data[8];
|
|
|
- this.circle10 = res.data[9];
|
|
|
+ // 连接成功
|
|
|
+ this.websocket.onopen = () => {
|
|
|
+ console.log(
|
|
|
+ "WebSocket连接成功 状态码:" + this.websocket.readyState
|
|
|
+ );
|
|
|
};
|
|
|
- //监听连接关闭事件
|
|
|
- this.ws.onclose = () => {
|
|
|
- //监听整个过程中websocket的状态
|
|
|
- console.log("ws连接状态:" + this.ws.readyState);
|
|
|
+ // 收到消息的回调
|
|
|
+ this.websocket.onmessage = (event) => {
|
|
|
+ console.log("onmessage", event);
|
|
|
};
|
|
|
- //监听并处理error事件
|
|
|
- this.ws.onerror = function (error) {
|
|
|
- console.log(error);
|
|
|
+ // 连接关闭的回调
|
|
|
+ this.websocket.onclose = () => {
|
|
|
+ console.log(
|
|
|
+ "WebSocket连接关闭 状态码:" + this.websocket.readyState
|
|
|
+ );
|
|
|
};
|
|
|
+ // 通过$once来监听定时器,在beforeDestroy钩子可以被清除。
|
|
|
+ this.$once("hook:beforeDestroy", () => {
|
|
|
+ this.websocket.close();
|
|
|
+ });
|
|
|
},
|
|
|
- init() {
|
|
|
- if (typeof WebSocket === "undefined") {
|
|
|
- alert("您的浏览器不支持socket");
|
|
|
- } else {
|
|
|
- this.socket = new WebSocket(this.path);
|
|
|
- this.socket.onopen = this.open;
|
|
|
- this.socket.onerror = this.error;
|
|
|
- this.socket.onmessage = this.getMessage;
|
|
|
- }
|
|
|
- },
|
|
|
- open() {
|
|
|
- console.log("socket连接成功");
|
|
|
- },
|
|
|
- error() {
|
|
|
- console.log("连接错误");
|
|
|
- },
|
|
|
- getMessage(msg) {
|
|
|
- let item = JSON.parse(msg.data);
|
|
|
- if(this.isFirst === 1){
|
|
|
- this.isFirst = 0;
|
|
|
- return;
|
|
|
- }
|
|
|
- if (item.error_code === 0 && this.isFirst === 0) {
|
|
|
- console.log(item.data);
|
|
|
- const {
|
|
|
- datetime,
|
|
|
- dianjicurrent,
|
|
|
- pressure,
|
|
|
- speed,
|
|
|
- bpqcurrent,
|
|
|
- } = item.data;
|
|
|
- let postdatetime = datetime.split('.')[0]
|
|
|
- this.$refs.chart1.addData(postdatetime, dianjicurrent);
|
|
|
- this.$refs.chart2.addData(postdatetime, pressure);
|
|
|
- this.$refs.chart3.addData(postdatetime, speed);
|
|
|
- this.$refs.chart4.addData(postdatetime, bpqcurrent);
|
|
|
- }
|
|
|
- },
|
|
|
- send() {},
|
|
|
- close() {
|
|
|
- console.log("socket已经关闭");
|
|
|
- },
|
|
|
- },
|
|
|
- created() {
|
|
|
- setTimeout(() => (this.loading = !this.loading), 1000);
|
|
|
- setInterval(this.change_color, 5000);
|
|
|
- this.$refs.chart1.test();
|
|
|
},
|
|
|
components: {
|
|
|
Chart1,
|
|
@@ -235,14 +182,14 @@ export default {
|
|
|
Chart3,
|
|
|
Chart4,
|
|
|
},
|
|
|
- destroyed() {
|
|
|
- this.socket.onclose = this.close;
|
|
|
+ computed: {
|
|
|
+ ...mapState(["websocketIP"]),
|
|
|
},
|
|
|
mounted() {
|
|
|
- const beltId = this.$route.params.id;
|
|
|
- this.path = this.path + beltId;
|
|
|
- this.init();
|
|
|
- }
|
|
|
+ console.log("id", this.$route.params.id);
|
|
|
+ // this.websocket = new WebSocket();
|
|
|
+ // this.initWebSocket();
|
|
|
+ },
|
|
|
};
|
|
|
</script>
|
|
|
|