添加i2导出和websocket

jc1.0
fanluyan 12 months ago
parent bbbed2ca6c
commit cc310207e4

6811
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -18,6 +18,7 @@
"three": "^0.158.0",
"vue": "^2.6.14",
"vue-cookies": "^1.8.3",
"vue-native-websocket": "^2.0.15",
"vue-router": "^3.5.1",
"vuex": "^3.6.2"
},

@ -0,0 +1,138 @@
import { Notification } from "element-ui";
let hasShownNotification = false;
// WebSocket连接实例
let socket = null;
// 是否正在尝试重连
let lockReconnect = false;
// 心跳间隔20秒
const timeout = 20 * 1000;
// 心跳定时器
let timeoutObj = null;
// 服务器无响应超时定时器
let serverTimeoutObj = null;
// 重连定时器
let reconnectTimeout = null;
// 初始化WebSocket连接
const initWebSocket = () => {
if ("WebSocket" in window) {
const protocol = window.location.protocol === "https:" ? "wss://" : "ws://";
const wsPath = "/cac-api/websocket";
const wshost =
window.location.hostname === "localhost"
? "192.168.1.190:88"
: window.location.host;
const wsUrl = protocol + wshost + wsPath;
socket = new WebSocket(wsUrl);
socket.onerror = webSocketOnError;
socket.onmessage = webSocketOnMessage;
socket.onclose = closeWebsocket;
socket.onopen = openWebsocket;
} else {
// 浏览器不支持WebSocket
console.error("您的浏览器不支持WebSocket");
// 这里可以添加更友好的提示方式如使用Element UI的Notification
}
};
// 打开WebSocket连接时执行
const openWebsocket = () => {
console.log("WebSocket链接成功");
startHeartbeat();
};
// 启动心跳
const startHeartbeat = () => {
timeoutObj = setTimeout(() => {
if (socket.readyState === WebSocket.OPEN) {
socket.send("1"); // 发送心跳消息
console.log("发送心跳消息以保持WebSocket连接活跃");
// 如果需要,可以在这里添加检测服务器响应的逻辑
// 例如,设置一个服务器响应超时检测
// 递归调用以继续发送心跳
startHeartbeat();
} else {
// 如果WebSocket已经关闭则不再发送心跳
console.log("WebSocket连接已关闭停止发送心跳");
clearTimeout(timeoutObj); // 清除定时器
}
}, timeout);
};
// WebSocket错误处理
const webSocketOnError = (e) => {
console.error("WebSocket发生错误:", e);
// 这里通常不需要立即重连因为onclose会处理重连逻辑
};
// 处理接收到的消息
const webSocketOnMessage = (e) => {
// 自定义事件,将接收到的数据派发给其他监听器
window.dispatchEvent(
new CustomEvent("onmessageWS", { detail: { data: e.data } })
);
// 收到消息后重置心跳定时器
resetHeartbeat();
};
// WebSocket关闭处理
const closeWebsocket = (e) => {
console.log("WebSocket连接已关闭:", e);
if (!hasShownNotification) {
Notification({
title: "告警",
message: "WebSocket连接已关闭",
position: "bottom-right",
type: "warning",
duration: 2000,
});
hasShownNotification = true; // 更新状态,防止再次显示
}
// 清除所有定时器
clearTimeout(timeoutObj);
clearTimeout(serverTimeoutObj);
// 设置重连定时器
reconnectTimeout = setTimeout(() => {
initWebSocket();
}, 60 * 1000); // 60秒后重连
};
// 重置心跳定时器
const resetHeartbeat = () => {
clearTimeout(timeoutObj);
clearTimeout(serverTimeoutObj);
startHeartbeat();
};
// 发送消息到WebSocket服务器
const sendWebsocket = (data) => {
if (socket && socket.readyState === WebSocket.OPEN) {
socket.send(data);
} else {
console.error("WebSocket未连接无法发送消息");
}
};
// 关闭WebSocket连接通常不需要在前端主动调用除非有特定需求
const close = () => {
if (socket) {
socket.close();
}
};
// 导出相关函数,以便在其他地方使用
export default { initWebSocket, sendWebsocket, close };
// 注意关于离开页面不断开WebSocket连接的需求这通常取决于浏览器的行为。
// 在一些情况下浏览器会在页面卸载时自动关闭WebSocket连接。

@ -102,7 +102,8 @@ export default {
align-items: center;
cursor: pointer;
font-size: 14px;
margin-right: 32px;
margin-right: 16px;
width: 100px;
a {
color: #fff;
background-image: url(../assets/menu.png);
@ -112,6 +113,8 @@ export default {
background-size: 100% 100%;
background-repeat: no-repeat;
overflow: hidden;
width: 100px;
text-align: center;
}
.router-link-active {
color: #6de1ff;

@ -10,6 +10,10 @@ Vue.use(ElementUI, {
size: "small",
});
//websocket
import websocket from "../socket/index";
Vue.prototype.$websocket = websocket;
//引入Echarts;
import * as echarts from "echarts";
Vue.prototype.$echarts = echarts;

@ -131,7 +131,7 @@ export default {
},
prewFun() {
this.warnLoading = true;
prewXmlApi({ tablename: this.selectTableName })
prewXmlApi({ modevtypeId: this.formInfo.jcsbType })
.then((res) => {
console.log(res);
this.prewData = res.data;
@ -151,6 +151,7 @@ export default {
// 访 tablename
this.selectTableName = selectedOption.tablename;
this.mc = selectedOption.mc;
this.formInfo.jcsbType = selectedOption.id;
console.log(this.selectTableName); // 使 tablename
this.prewFun();
}

@ -72,7 +72,7 @@ import {
updateFieldConfigApi,
} from "@/utils/api/index";
export default {
props: ["title"],
props: ["title", "filedData"],
data() {
return {
filedDialogshow: false,
@ -204,13 +204,22 @@ export default {
.then((res) => {
console.log(res);
this.jcsbOptions = res.data;
console.log("我是已经添加过的", this.filedData);
let newData2 = this.jcsbOptions.filter((item2) => {
// 使somedata1mc
return !this.filedData.some((item1) => item1.mc === item2.mc);
});
console.log(newData2);
console.log(this.title);
if (this.title == "新增字段导出映射") {
this.jcsbOptions = newData2;
console.log(this.formInfo);
this.formInfo.jcsbType = this.jcsbOptions[0].id;
this.selectTableName = this.jcsbOptions[0].tablename;
this.mc = this.jcsbOptions[0].mc;
} else {
this.jcsbOptions = res.data;
let selectXl = this.jcsbOptions.find(
(item) => item.tablename === this.selectTableName
);

@ -53,7 +53,11 @@
</el-table>
</div>
</div>
<addfiledDialog ref="filedAddRef" :title="title"></addfiledDialog>
<addfiledDialog
ref="filedAddRef"
:title="title"
:filedData="filedData"
></addfiledDialog>
</div>
</template>
<script>

@ -31,12 +31,12 @@
</template>
</el-table-column>
<el-table-column label="被监测设备标识" prop="equipmentId">
<el-table-column label="equipmentId" prop="equipmentId">
<template slot-scope="scope">
<span>{{ scope.row.sensor.equipmentId }}</span>
</template>
</el-table-column>
<el-table-column label="监测装置标识" prop="sensorCode">
<el-table-column label="sensorCode" prop="sensorCode">
<template slot-scope="scope">
<span>{{ scope.row.sensor.sensorCode }}</span>
</template>

@ -36,6 +36,9 @@
</el-option>
</el-select>
</el-form-item>
<el-form-item label="类型编码:" prop="typeCode">
<el-input v-model="formInfo.typeCode"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="hide"> </el-button>
@ -58,6 +61,7 @@ export default {
formInfo: {
mc: "",
tablename: "",
typeCode: "",
},
rules: {
mc: [{ required: true, message: "请输入名称", trigger: "blur" }],
@ -143,6 +147,7 @@ export default {
console.log(this.formInfo);
this.formInfo.tablename = this.tableOptions[0].name;
this.formInfo.mc = "";
this.formInfo.typeCode = "";
}
})
.catch((err) => {

@ -19,7 +19,7 @@
<el-table-column prop="id" label="ID"> </el-table-column>
<el-table-column prop="mc" label="设备名称"> </el-table-column>
<el-table-column prop="tablename" label="表名"> </el-table-column>
<el-table-column prop="typeCode" label="类型编码"> </el-table-column>
<el-table-column label="操作" class-name="editClass">
<template slot-scope="scope">
<el-link

@ -37,9 +37,12 @@
</el-option>
</el-select>
</el-form-item>
<el-form-item label="传感器代码" prop="sensorCode">
<el-form-item label="sensorCode" prop="sensorCode">
<el-input v-model="formInfo.sensorCode"></el-input>
</el-form-item>
<el-form-item label="equipmentId" prop="equipmentId">
<el-input v-model="formInfo.equipmentId"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="hide"> </el-button>
@ -66,6 +69,7 @@ export default {
typeId: "",
devId: "",
sensorCode: "",
equipmentId: "",
},
rules: {
name: [{ required: true, message: "请输入名称", trigger: "blur" }],

@ -91,7 +91,9 @@
<el-table-column prop="typeName" label="类型" width="160">
</el-table-column>
<el-table-column prop="sensorCode" label="传感器代码" width="160">
<el-table-column prop="sensorCode" label="sensorCode" width="160">
</el-table-column>
<el-table-column prop="equipmentId" label="equipmentId" width="160">
</el-table-column>
<el-table-column label="操作" width="260" class-name="editClass">
<template slot-scope="scope">

@ -17,7 +17,7 @@
height="calc(100% - 0px)"
>
<el-table-column prop="id" label="ID"> </el-table-column>
<el-table-column prop="field" label="名称"> </el-table-column>
<el-table-column prop="field" label="字段"> </el-table-column>
<el-table-column prop="unit" label="单位"> </el-table-column>
<el-table-column label="操作" class-name="editClass">
<template slot-scope="scope">

@ -93,6 +93,7 @@
<script>
import { warningListApi } from "@/utils/api/index";
import warnDialog from "./components/warnDialog.vue";
import socketService from "../../../../socket/index";
export default {
name: "warnmessage",
components: {
@ -123,8 +124,26 @@ export default {
this.endtime = currentDate;
this.getwarnList();
},
mounted() {},
created() {},
async mounted() {
this.initWebSocket();
window.addEventListener("onmessageWS", this.getSocketData);
},
methods: {
async initWebSocket() {
this.$websocket.initWebSocket();
},
getSocketData(res) {
console.log(res);
this.$notify({
title: "告警",
message: res.detail.data,
position: "bottom-right",
type: "warning",
duration: 0,
});
},
lookMore() {
this.params.startTime = this.starttime;
this.params.endTime = this.endtime;
@ -152,6 +171,9 @@ export default {
});
},
},
destroyed() {
this.$websocket.close();
},
};
</script>
@ -325,4 +347,8 @@ export default {
}
}
}
.el-notification__content {
text-align: left;
word-break: break-all;
}
</style>

@ -235,7 +235,7 @@ export default {
//
getBindList() {
getBindApi({
eqmid: this.currentNodeKey,
sensorId: this.currentNodeKey,
})
.then((res) => {
console.log(res);
@ -309,7 +309,7 @@ export default {
this.icdid = this.ljOptions.find((item) => item.paramIndex === val).id;
this.warnMsg = "";
previewApi({
eqmid: this.currentNodeKey,
sensorId: this.currentNodeKey,
icdid: this.icdid,
})
.then((res) => {
@ -335,7 +335,7 @@ export default {
//
saveBind() {
bindApi({
eqmid: this.currentNodeKey,
sensorId: this.currentNodeKey,
icdid: this.icdid,
})
.then((res) => {
@ -385,7 +385,7 @@ export default {
//
unBind() {
unbindApi({
eqmid: this.currentNodeKey,
sensorId: this.currentNodeKey,
})
.then((res) => {
console.log(res);

@ -20,8 +20,8 @@ module.exports = defineConfig({
proxy: {
"/cac-api": {
//表示拦截以/api开头的请求路径
//target: "http://192.168.1.190:88", //200服务器
target: "http://61.169.135.146:40080/", //dell服务器
target: "http://192.168.1.190:88", //200服务器
// target: "http://61.169.135.146:40080/", //dell服务器
changOrigin: true, //是否开启跨域
pathRewrite: {

Loading…
Cancel
Save