|
|
@@ -44,13 +44,14 @@ import SizeSelect from '@/components/SizeSelect'
|
|
|
import Search from '@/components/HeaderSearch'
|
|
|
import RuoYiGit from '@/components/RuoYi/Git'
|
|
|
import RuoYiDoc from '@/components/RuoYi/Doc'
|
|
|
-
|
|
|
+import WebsocketHeartbeatJs from '@/utils/WebsocketJs.js'
|
|
|
+import { systemConfiguration } from "@/api/pdu/pduServer";
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
logoName: "",
|
|
|
- dateTime:""
|
|
|
-
|
|
|
+ dateTime:"",
|
|
|
+ websocketHeartbeatJs: undefined, // websocket实例 -- 业务相关
|
|
|
}
|
|
|
},
|
|
|
components: {
|
|
|
@@ -64,6 +65,7 @@ export default {
|
|
|
RuoYiDoc
|
|
|
},
|
|
|
created() {
|
|
|
+ this.systemConfiguration();
|
|
|
this.logoName= this.$store.state.user.logoName;
|
|
|
this.dataRefreh()
|
|
|
},
|
|
|
@@ -93,6 +95,95 @@ export default {
|
|
|
|
|
|
},
|
|
|
methods: {
|
|
|
+ // 获取系统配置
|
|
|
+ systemConfiguration(){
|
|
|
+ systemConfiguration({}).then(response => {
|
|
|
+ if(response.data!=null && response.data.webSocket!=null && response.data.webSocket!=''){
|
|
|
+ var data=response.data;
|
|
|
+ var webSocket=data.webSocket;
|
|
|
+
|
|
|
+ this.initWebsocket(webSocket);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 判断字符串是否为json字符串
|
|
|
+ isJSON(str) {
|
|
|
+ if (typeof str == 'string') {
|
|
|
+ try {
|
|
|
+ var obj = JSON.parse(str)
|
|
|
+ if (typeof obj == 'object' && obj) {
|
|
|
+ return true
|
|
|
+ } else {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log('It is not a string!')
|
|
|
+ },
|
|
|
+// 初始化websocket
|
|
|
+ initWebsocket(url) {
|
|
|
+ let that = this
|
|
|
+ // let params = that.remoteAddrOperatornameBorse();
|
|
|
+ that.websocketHeartbeatJs = new WebsocketHeartbeatJs({
|
|
|
+ url: url + 'PDU-WebSocket',
|
|
|
+ pingTimeout: 30000,
|
|
|
+ pongTimeout: 20000,
|
|
|
+ reconnectTimeout: 2000,
|
|
|
+ pingMsg: 'heartbeat',
|
|
|
+ disableHeartbeat: true,
|
|
|
+ })
|
|
|
+
|
|
|
+ // Connection opened
|
|
|
+ that.websocketHeartbeatJs.onopen = function () {
|
|
|
+ that.websocketHeartbeatJs.send('first send message: hello server')
|
|
|
+ // console.log('websocket初始化成功!!并发送了消息first send message: hello server')
|
|
|
+ }
|
|
|
+
|
|
|
+ // 监听服务端的消息
|
|
|
+ that.websocketHeartbeatJs.onmessage = function (e) {
|
|
|
+ // 后台告知前端关闭websocket连接
|
|
|
+ if (e.type == 'close') that.websocketHeartbeatJs.close()
|
|
|
+
|
|
|
+ let result = e.data
|
|
|
+ let isJsonStr = that.isJSON(result) // 判断该字符串是否为json字符串
|
|
|
+ if (isJsonStr) {
|
|
|
+ result = JSON.parse(result)
|
|
|
+ } else {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ //总体状态监控推送
|
|
|
+ if (result.type === 'overallStatusMonitoring') {
|
|
|
+ //if (result.success) that.$bus.$emit('ATTENDANCE_ANALYSE', result)
|
|
|
+ if (result.success) that.$bus.$emit('OVERALL_STATUS_MONITORING', result)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ //通道状态监控
|
|
|
+ if (result.type === 'channelStatusMonitoring') {
|
|
|
+ that.$bus.$emit('CHANNEL_STATUS_MONITORING', result)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ //传感器状态监控
|
|
|
+ if (result.type === 'sensorStatusMonitoring') {
|
|
|
+ that.$bus.$emit('SENSOR_STATUS_MONITORING', result)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // websocket重连
|
|
|
+ that.websocketHeartbeatJs.onreconnect = function () {
|
|
|
+ // eslint-disable-next-line no-console
|
|
|
+ console.log('WebsocketForBusinessData reconnecting...')
|
|
|
+ // eslint-disable-next-line no-console
|
|
|
+ console.log('tips: if you network closing, please open network, reconnect will success')
|
|
|
+ }
|
|
|
+ },
|
|
|
dataRefreh(){
|
|
|
// 计时器为空,操作
|
|
|
setInterval(() => {
|
|
|
@@ -117,11 +208,14 @@ export default {
|
|
|
type: 'warning'
|
|
|
}).then(() => {
|
|
|
this.$store.dispatch('LogOut').then(() => {
|
|
|
+ this.websocketHeartbeatJs && this.websocketHeartbeatJs.close() //关闭websocket连接
|
|
|
location.href = '/index';
|
|
|
})
|
|
|
+
|
|
|
}).catch(() => {});
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
+
|
|
|
}
|
|
|
</script>
|
|
|
|