suerprisePlus
2024-11-27 ab8f3297f7c8243d486c9da0900e4f813b2ea2df
src/components/RuoYi/Msgger/index.vue
@@ -2,7 +2,8 @@
    <div class="msgBox" @click.stop="setShowMenuClick(true)">
        <i style="font-size: 20px;" class="el-icon-chat-line-round"></i>
        <el-badge v-show="$store.state.mapLayers.msgList.length > 0" :value="$store.state.mapLayers.msgList.length" class="item">
        <el-badge v-show="$store.state.mapLayers.msgList.length > 0" :value="$store.state.mapLayers.msgList.length"
            class="item">
        </el-badge>
        <el-dialog title="故障信息" :visible.sync="dialogVisible" width="30%" :show-close="false">
            <el-table :data="$store.state.mapLayers.msgList" style="width: 100%">
@@ -13,7 +14,7 @@
                <el-table-column label="操作" width="100">
                    <template slot-scope="scope">
                        <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
                        <el-button @click="handleClick2(scope.row)" type="text" size="small">分发</el-button></el-button>
                        <el-button @click="handleClick2(scope.row)" type="text" size="small">分发</el-button>
                    </template>
                </el-table-column>
            </el-table>
@@ -31,7 +32,7 @@
</template>
<script>
import olMap from '@/components/mapOl/index.vue';
export default {
@@ -64,6 +65,7 @@
                type: 'point',
                isShow: false,
            }
            this.parentData = JSON.stringify([obj])
            this.innerVisible = true
        },
@@ -81,12 +83,33 @@
            this.wsSocket.onopen = (event) => {
                console.log('WebSocket连接成功');
            };
            this.wsSocket.onclose = () => {
                console.log('WebSocket连接关闭');
                this.wsSocket = null
            };
            this.wsSocket.onmessage = (event) => {
                if (event.data != "连接成功") {
                    const obj = JSON.parse(event.data);
                    if (obj.mes) {
                        this.setShowMsg(obj)
                    if (obj.type == "error") {
                        if (this.$store.state.mapLayers.msgList.length == 0) {
                            this.$store.state.mapLayers.msgList.push(obj)
                        } else {
                            var rs = this.$store.state.mapLayers.msgList;
                            var st = rs.filter(item => {
                                if (item.msg == obj.msg && item.point == obj.point && item.line == obj.line) {
                                    return item
                                }
                            })
                            if (st.length <= 0) {
                                this.$store.state.mapLayers.msgList.push(obj)
                            }
                        }
                    }
                }
                // 处理接收到的消息
@@ -105,9 +128,16 @@
        },
    },
    mounted() {
        // if (!this.wsSocket) {
        //     this.createSocket();
        // }
        if (!this.wsSocket) {
            this.createSocket();
        }
    },
    beforeDestroy() {
        if (this.wsSocket) {
            this.wsSocket.close();
        }
    },
}