diff --git a/src/api/AlertMock.ts b/src/api/AlertMock.ts index 8dca82a..9e31f90 100644 --- a/src/api/AlertMock.ts +++ b/src/api/AlertMock.ts @@ -130,3 +130,11 @@ export async function recordAlarmReport( const response = await api.post(`/api/alertRecord/report/${lineId}`, data); return response.data; } + +/** + * 初始化 + * @param linId 线路的id + */ +export function resetApi(linId: number): Promise { + return api.get(`${alertUriBase}/reset/${linId}`); +} diff --git a/src/components/ConnectInfoDialog.vue b/src/components/ConnectInfoDialog.vue new file mode 100644 index 0000000..3733ff2 --- /dev/null +++ b/src/components/ConnectInfoDialog.vue @@ -0,0 +1,80 @@ + + + diff --git a/src/components/webSocketConnect.ts b/src/components/webSocketConnect.ts new file mode 100644 index 0000000..31157f9 --- /dev/null +++ b/src/components/webSocketConnect.ts @@ -0,0 +1,31 @@ +import { HandleMessage, StompMessagingClient } from 'jl-graphic'; +import { getJwtToken } from 'src/configs/TokenManage'; +import { getWebsocketUrl } from 'src/configs/UrlManage'; + +export function webSocketConnect(destination: string, handler: HandleMessage) { + const socket = new StompMessagingClient({ + wsUrl: `${getWebsocketUrl()}`, + token: getJwtToken() as string, + protocol: 'protobuf', + connectTimeout: 30 * 1000, + heartbeat: 60, + retryPeriod: 2 * 1000, + retryTimes: 100, + }); + socket.on('connected', () => { + socket?.subscribe(destination, handler); + }); + socket.on('disconnected', () => { + console.log('disconnected'); + }); + return socket; +} + +export function closeWebSocketConnect( + socket: StompMessagingClient | null, + destination: string +) { + socket?.unsubscribe0(destination); + socket?.close(); + socket = null; +} diff --git a/src/css/app.scss b/src/css/app.scss index ecac98f..2157cc3 100644 --- a/src/css/app.scss +++ b/src/css/app.scss @@ -1 +1,4 @@ // app global css in SCSS form +.my-notif-class { + margin-top: 50px; +} diff --git a/src/drawApp/lineApp.ts b/src/drawApp/lineApp.ts index 90aa484..94d8ab5 100644 --- a/src/drawApp/lineApp.ts +++ b/src/drawApp/lineApp.ts @@ -130,7 +130,7 @@ export function initLineApp(): IGraphicApp { sectionOperationPlugin.init(lineApp); lineApp.enableWsMassaging({ - engine: ClientEngine.MQTT, + engine: ClientEngine.Stomp, wsUrl: getWebsocketUrl(), token: getJwtToken() as string, }); @@ -143,7 +143,8 @@ export function initLineApp(): IGraphicApp { type: 'negative', timeout: 0, position: 'top-right', - message: '通信链接已断开!', + message: '与WebSocket服务连接断开!', + classes: 'my-notif-class', }); } else if (msgNotify && connected) { msgNotify(); diff --git a/src/drawApp/lineNetApp.ts b/src/drawApp/lineNetApp.ts index fb6f1ae..1f00a57 100644 --- a/src/drawApp/lineNetApp.ts +++ b/src/drawApp/lineNetApp.ts @@ -91,7 +91,8 @@ export function initLineNetApp(): IGraphicApp { type: 'negative', timeout: 0, position: 'top-right', - message: '通信链接已断开!', + message: '与WebSocket服务连接断开!', + classes: 'my-notif-class', }); } else if (msgNotify && connected) { msgNotify(); diff --git a/src/layouts/MainLayout.vue b/src/layouts/MainLayout.vue index 3ef22a0..f35de31 100644 --- a/src/layouts/MainLayout.vue +++ b/src/layouts/MainLayout.vue @@ -30,6 +30,13 @@ class="q-mr-sm" @click="openSetAlarmTextDialog" /> +
+ diff --git a/src/pages/AlarmInfoList.vue b/src/pages/AlarmInfoList.vue index 2f6670e..c134790 100644 --- a/src/pages/AlarmInfoList.vue +++ b/src/pages/AlarmInfoList.vue @@ -226,8 +226,6 @@ import { ShowAlertStateData, alertStatusOptions, } from 'src/components/alarm/alarmInfoEnum'; -import { getWebsocketUrl } from 'src/configs/UrlManage'; -import { getJwtToken } from 'src/configs/TokenManage'; import { alert } from 'src/protos/alertInfo'; import { useLineNetStore } from 'src/stores/line-net-store'; import { StompMessagingClient } from 'jl-graphic'; @@ -235,6 +233,10 @@ import alarmStatistics from 'src/components/alarm/alarmStatistics.vue'; import { errorNotify } from 'src/utils/CommonNotify'; import { pageQuery } from 'src/api/LineInfoApi'; import { ApiError } from 'src/boot/axios'; +import { + webSocketConnect, + closeWebSocketConnect, +} from 'src/components/webSocketConnect'; const $q = useQuasar(); const lineNetStore = useLineNetStore(); @@ -370,7 +372,7 @@ onMounted(() => { setTimeout(() => { tableRef.value.requestServerInteraction(); lineNetStore.alarmInfoListTable = tableRef.value; - socketConnect(); + socket = webSocketConnect(destination, handler); }); }); @@ -551,34 +553,13 @@ function openAlarmDialog(row: any) { let socket: StompMessagingClient | null = null; const destination = '/queue/xian/ncc/alert'; -function socketConnect() { - socket = new StompMessagingClient({ - wsUrl: `${getWebsocketUrl()}`, - token: getJwtToken() as string, - protocol: 'protobuf', - connectTimeout: 30 * 1000, - heartbeat: 60, - retryPeriod: 2 * 1000, - retryTimes: 100, - }); - socket.on('connected', () => { - socket?.subscribe(destination, handler); - }); -} - function handler(message: Uint8Array) { const storage = alert.NccAlertInfoMessage.deserialize(message); lineNetStore.setAlarmInfo(storage.messages as []); } -function closeSocket() { - socket?.unsubscribe0(destination); - socket?.close(); - socket = null; -} - onUnmounted(() => { - closeSocket(); + closeWebSocketConnect(socket, destination); }); //报警统计 diff --git a/src/stores/line-net-store.ts b/src/stores/line-net-store.ts index 2836538..821ea40 100644 --- a/src/stores/line-net-store.ts +++ b/src/stores/line-net-store.ts @@ -7,6 +7,7 @@ import { } from 'src/drawApp/lineNetApp'; import { markRaw } from 'vue'; import { QTable } from 'quasar'; +import { state } from 'src/protos/system_warn_message'; export interface AlarmInfo { id: string; level: string; @@ -28,6 +29,8 @@ export const useLineNetStore = defineStore('lineNet', { alarmInfoListTable: undefined as QTable | undefined, playAble: false, //是否允许播放音乐 closeAllAlarmInfoDialog: false, + connectButtonColor: 'green', + connectInfo: null as state.WarnLineMessage | null, }), getters: { untreatedNum: (state) => { @@ -81,6 +84,25 @@ export const useLineNetStore = defineStore('lineNet', { this.untreatedMap.set(item.id, item); }); }, + setConnectInfo(data: state.WarnLineMessage) { + this.connectInfo = data; + const allConnectAmount = data.msgs.reduce((pre, cur) => { + let addValue = 0; + if (cur.occRealConned && cur.occUnrealConned) { + addValue = 2; + } else if (cur.occRealConned || cur.occUnrealConned) { + addValue = 1; + } + return pre + addValue; + }, 0); + if (allConnectAmount == data.msgs.length * 2) { + this.connectButtonColor = 'green'; + } else if (allConnectAmount == 0) { + this.connectButtonColor = 'red'; + } else { + this.connectButtonColor = 'yellow'; + } + }, treatedAlarm(data: AlarmInfo) { if (this.untreatedMap.has(data.id)) { this.untreatedMap.delete(data.id);