suerprisePlus
2024-08-21 7d57b0fef0f220dfe7c868ce1113a7ce6eb6c468
src/views/visualization/index.vue
@@ -3,10 +3,10 @@
        <div class="title"></div>
        <mapView></mapView>
        <div class="leftMenu">
            <left-menu></left-menu>
            <left-menu :leftChartData="leftChartData"></left-menu>
        </div>
        <div class="rightMenu">
            <right-menu></right-menu>
            <right-menu :rightChartData="rightChartData"></right-menu>
        </div>
        <div class="bottomMenu">
            <bottomMenu @childData="childData"></bottomMenu>
@@ -42,6 +42,7 @@
import analysis from '@/views/visual/analysis/index.vue'
import lineLoss from './lineLoss.vue';
import statistics from '@/views/visual/statistics/index.vue'
import { type } from 'jquery';
export default {
    components: {
        mapView, leftMenu,
@@ -50,12 +51,50 @@
    data() {
        return {
            isShow: null,
            showInfo: false
            showInfo: false,
            wsSocket: null,
            rightChartData: {},
            leftChartData:{},
        }
    },
    beforeDestroy() {
        if (this.wsSocket) {
            this.wsSocket.onclose = () => {
                console.log('WebSocket连接关闭');
                this.wsSocket = null
            };
        }
    },
    mounted() {
        if (!this.wsSocket) {
            this.createSocket();
        }
    },
    methods: {
        createSocket() {
            this.wsSocket = new WebSocket(config.pySocket);
            this.wsSocket.onopen = (event) => {
                console.log('WebSocket连接成功');
            };
            this.wsSocket.onmessage = (event) => {
                // console.log('Received message:', event.data);
                if (event.data != "连接成功") {
                    const obj = JSON.parse(event.data)
                    this.leftChartData = {
                        type: 'left1',
                        val: obj
                    }
                }
                // 处理接收到的消息
            };
        },
        childData(res) {
            if (!res) return
            this.showInfo = true;