|
|
@ -1,16 +1,43 @@
|
|
|
|
<template>
|
|
|
|
<template>
|
|
|
|
<div id="app">
|
|
|
|
<div id="app">
|
|
|
|
<router-view />
|
|
|
|
<router-view />
|
|
|
|
|
|
|
|
<!-- 只有当 warnMsgs 数组长度大于 0 时才渲染告警弹窗 -->
|
|
|
|
|
|
|
|
<div v-if="warnMsgs.length > 0" class="warnDialog-container">
|
|
|
|
|
|
|
|
<div class="warnDialog" v-for="(warn, index) in warnMsgs" :key="index">
|
|
|
|
|
|
|
|
<div class="warnTitle">
|
|
|
|
|
|
|
|
<div class="left">
|
|
|
|
|
|
|
|
<i class="el-icon-warning"></i>
|
|
|
|
|
|
|
|
告警
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="right">
|
|
|
|
|
|
|
|
<!-- 传递索引以关闭当前告警 -->
|
|
|
|
|
|
|
|
<i class="el-icon-close" @click="handleCloseWarn(index)"></i>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="warnContent">
|
|
|
|
|
|
|
|
<p>{{ warn.content }}</p>
|
|
|
|
|
|
|
|
<el-button
|
|
|
|
|
|
|
|
v-if="warn.warningId"
|
|
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
|
|
@click="clearWarnClick(warn, index)"
|
|
|
|
|
|
|
|
>处理</el-button
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
<script>
|
|
|
|
import socketService from "../socket/index";
|
|
|
|
import socketService from "../socket/index";
|
|
|
|
|
|
|
|
import { updateStateApi } from "@/utils/api/index";
|
|
|
|
export default {
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
windowWidth: 0,
|
|
|
|
windowWidth: 0,
|
|
|
|
htmlFontSize: 16, // 默认的html字体大小
|
|
|
|
htmlFontSize: 16, // 默认的html字体大小
|
|
|
|
|
|
|
|
warnMsgs: [], // 存储告警消息的数组
|
|
|
|
|
|
|
|
//warnMsg: '{"type":1,"content":"qwqdqdqd","warningId":2}',
|
|
|
|
};
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
@ -29,16 +56,22 @@ export default {
|
|
|
|
this.$websocket.initWebSocket();
|
|
|
|
this.$websocket.initWebSocket();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
getSocketData(res) {
|
|
|
|
getSocketData(res) {
|
|
|
|
console.log(res);
|
|
|
|
const newWarnMsg = JSON.parse(res.detail.data);
|
|
|
|
// let a = JsON.parse(res.detail);
|
|
|
|
// 检查告警消息是否已存在,避免重复添加
|
|
|
|
// console.log(a.type);
|
|
|
|
if (newWarnMsg.type == 1) {
|
|
|
|
this.$notify({
|
|
|
|
if (!this.warnMsgs.includes(newWarnMsg)) {
|
|
|
|
title: "告警",
|
|
|
|
this.warnMsgs.push(newWarnMsg); // 添加新的告警消息到数组中
|
|
|
|
message: res.detail.data,
|
|
|
|
}
|
|
|
|
position: "bottom-right",
|
|
|
|
}
|
|
|
|
type: "warning",
|
|
|
|
console.log("我是告警信息", newWarnMsg);
|
|
|
|
duration: 0,
|
|
|
|
//this.warnMsg = res.detail.data;
|
|
|
|
});
|
|
|
|
// this.$notify({
|
|
|
|
|
|
|
|
// title: "告警",
|
|
|
|
|
|
|
|
// message: res.detail.data,
|
|
|
|
|
|
|
|
// position: "bottom-right",
|
|
|
|
|
|
|
|
// type: "warning",
|
|
|
|
|
|
|
|
// duration: 0,
|
|
|
|
|
|
|
|
// });
|
|
|
|
},
|
|
|
|
},
|
|
|
|
setRemUnit() {
|
|
|
|
setRemUnit() {
|
|
|
|
// 设置所有的rem单位
|
|
|
|
// 设置所有的rem单位
|
|
|
@ -56,6 +89,34 @@ export default {
|
|
|
|
// 根据窗口宽度动态设置html的字体大小
|
|
|
|
// 根据窗口宽度动态设置html的字体大小
|
|
|
|
document.documentElement.style.fontSize = `${remUnit()}px`;
|
|
|
|
document.documentElement.style.fontSize = `${remUnit()}px`;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
//关闭告警
|
|
|
|
|
|
|
|
handleCloseWarn(index) {
|
|
|
|
|
|
|
|
console.log("Closing warning:", index);
|
|
|
|
|
|
|
|
this.warnMsgs.splice(index, 1); // 根据索引移除对应的告警消息
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
//处理告警并关闭
|
|
|
|
|
|
|
|
clearWarnClick(item, index) {
|
|
|
|
|
|
|
|
this.handleCloseWarn(index);
|
|
|
|
|
|
|
|
updateStateApi({
|
|
|
|
|
|
|
|
id: item.warningId,
|
|
|
|
|
|
|
|
state: 0,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.then((res) => {
|
|
|
|
|
|
|
|
if (res.success) {
|
|
|
|
|
|
|
|
console.log(res);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.$message({
|
|
|
|
|
|
|
|
duration: 1500,
|
|
|
|
|
|
|
|
showClose: true,
|
|
|
|
|
|
|
|
message: res.errorMsg,
|
|
|
|
|
|
|
|
type: "error",
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
|
|
console.log(err); //代码错误、请求失败捕获
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
destroyed() {
|
|
|
|
destroyed() {
|
|
|
|
this.$websocket.close();
|
|
|
|
this.$websocket.close();
|
|
|
@ -104,4 +165,65 @@ body {
|
|
|
|
background-color: #f0f0f0;
|
|
|
|
background-color: #f0f0f0;
|
|
|
|
border-radius: 32px;
|
|
|
|
border-radius: 32px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.warnDialog-container {
|
|
|
|
|
|
|
|
.warnDialog {
|
|
|
|
|
|
|
|
right: 16px;
|
|
|
|
|
|
|
|
bottom: 16px;
|
|
|
|
|
|
|
|
width: 330px;
|
|
|
|
|
|
|
|
padding: 16px;
|
|
|
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
|
|
|
border: 1px solid #ebeef5;
|
|
|
|
|
|
|
|
position: fixed;
|
|
|
|
|
|
|
|
background-color: #fff;
|
|
|
|
|
|
|
|
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
|
|
|
|
|
|
|
transition: opacity 0.3s, transform 0.3s, left 0.3s, right 0.3s, top 0.4s,
|
|
|
|
|
|
|
|
bottom 0.3s;
|
|
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
.warnTitle {
|
|
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
|
|
.left {
|
|
|
|
|
|
|
|
color: #000;
|
|
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
height: 24px;
|
|
|
|
|
|
|
|
line-height: 24px;
|
|
|
|
|
|
|
|
i {
|
|
|
|
|
|
|
|
font-size: 24px;
|
|
|
|
|
|
|
|
color: #e6a23c;
|
|
|
|
|
|
|
|
margin-right: 8px;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
.right {
|
|
|
|
|
|
|
|
i {
|
|
|
|
|
|
|
|
font-size: 24px;
|
|
|
|
|
|
|
|
color: #606266;
|
|
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
|
|
|
color: #337ab7;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
.warnContent {
|
|
|
|
|
|
|
|
text-align: left;
|
|
|
|
|
|
|
|
word-break: break-all;
|
|
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
|
|
line-height: 21px;
|
|
|
|
|
|
|
|
margin: 6px 0 0 0;
|
|
|
|
|
|
|
|
color: #606266;
|
|
|
|
|
|
|
|
padding: 0px 12px;
|
|
|
|
|
|
|
|
p {
|
|
|
|
|
|
|
|
height: 100px;
|
|
|
|
|
|
|
|
margin-bottom: 12px;
|
|
|
|
|
|
|
|
padding: 0px 20px;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-button {
|
|
|
|
|
|
|
|
margin-left: auto;
|
|
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</style>
|
|
|
|