|
@@ -6,17 +6,18 @@
|
|
|
|
|
|
<script>
|
|
|
import { mapState } from "vuex";
|
|
|
-import Chart from './chart.vue'
|
|
|
+import Chart from "./chart.vue";
|
|
|
export default {
|
|
|
- data () {
|
|
|
+ data() {
|
|
|
return {
|
|
|
currentData: new Array(30).fill("-"),
|
|
|
+ xData: new Array(30).fill("-"),
|
|
|
drawTiming: null,
|
|
|
cdata: {
|
|
|
currentData: [],
|
|
|
- xData:[]
|
|
|
- }
|
|
|
- }
|
|
|
+ xData: [],
|
|
|
+ },
|
|
|
+ };
|
|
|
},
|
|
|
computed: {
|
|
|
...mapState(["websocketIP"]),
|
|
@@ -25,26 +26,29 @@ export default {
|
|
|
Chart,
|
|
|
},
|
|
|
|
|
|
- beforeDestroy () {
|
|
|
+ beforeDestroy() {
|
|
|
clearInterval(this.drawTiming);
|
|
|
},
|
|
|
- methods: {
|
|
|
+ methods: {
|
|
|
addData(data) {
|
|
|
// console.log("data", data.map((item) => item["paiqiliuliang_after"]));
|
|
|
// 先扩展数组,然后删除多余元素
|
|
|
this.currentData = [
|
|
|
- ...this.currentData,
|
|
|
...data.map((item) => item["dianjidianliui_after"]),
|
|
|
- ].slice(1);
|
|
|
+ ...this.currentData,
|
|
|
+ ].slice(0, -1);
|
|
|
this.xData = [
|
|
|
- ...this.xData,
|
|
|
...data.map((item) => item["date"].split(" ")[1]),
|
|
|
- ].slice(1);
|
|
|
- // console.log("currentData",this.currentData);
|
|
|
- console.log('currentData',this.currentData);
|
|
|
+ ...this.xData,
|
|
|
+ ].slice(0, -1);
|
|
|
+ console.log(123);
|
|
|
+ console.log("currentData1", this.currentData);
|
|
|
+ console.log(
|
|
|
+ "currentData2",
|
|
|
+ data.map((item) => item["dianjidianliui_after"])
|
|
|
+ );
|
|
|
this.cdata.currentData = this.currentData;
|
|
|
this.cdata.xData = this.xData;
|
|
|
-
|
|
|
},
|
|
|
initWebSocket() {
|
|
|
// 连接错误
|
|
@@ -62,7 +66,7 @@ export default {
|
|
|
// 收到消息的回调
|
|
|
this.websocket.onmessage = (event) => {
|
|
|
// console.log("onmessage", event);
|
|
|
- if(JSON.parse(event.data).length) {
|
|
|
+ if (JSON.parse(event.data).length) {
|
|
|
this.addData(JSON.parse(event.data));
|
|
|
}
|
|
|
};
|
|
@@ -79,7 +83,8 @@ export default {
|
|
|
},
|
|
|
},
|
|
|
|
|
|
- mounted() {
|
|
|
+ mounted() {
|
|
|
+ console.log(888888888);
|
|
|
// 先画图
|
|
|
// this.myChart = this.$echarts.init(this.$refs.testLine);
|
|
|
// this.myChart.setOption(this.option);
|