fix(app-layout): concat stomp broker url instead of just vite proxy
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
const SUBSCRIBE_TOPIC = '/topic/deviceAlarm';
|
||||||
|
|
||||||
function renderIcon(icon: Component): () => VNode {
|
function renderIcon(icon: Component): () => VNode {
|
||||||
return () => h(NIcon, null, { default: () => h(icon) });
|
return () => h(NIcon, null, { default: () => h(icon) });
|
||||||
}
|
}
|
||||||
@@ -41,12 +43,12 @@ onBeforeMount(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
|
const { host } = window.location;
|
||||||
|
const endpoint = '/ws';
|
||||||
|
const brokerURL = `${protocol}//${host}${endpoint}`;
|
||||||
stompClient.value = new StompClient({
|
stompClient.value = new StompClient({
|
||||||
brokerURL: '/ws',
|
brokerURL,
|
||||||
// webSocketFactory: () => {
|
|
||||||
// const ws = new WebSocket('/ws');
|
|
||||||
// return ws;
|
|
||||||
// },
|
|
||||||
reconnectDelay: 5000,
|
reconnectDelay: 5000,
|
||||||
heartbeatIncoming: 10000,
|
heartbeatIncoming: 10000,
|
||||||
heartbeatOutgoing: 10000,
|
heartbeatOutgoing: 10000,
|
||||||
@@ -55,7 +57,7 @@ onMounted(() => {
|
|||||||
// },
|
// },
|
||||||
onConnect: () => {
|
onConnect: () => {
|
||||||
console.log('Stomp连接成功');
|
console.log('Stomp连接成功');
|
||||||
stompClient.value?.subscribe('/topic/deviceAlarm', (message) => {
|
stompClient.value?.subscribe(SUBSCRIBE_TOPIC, (message) => {
|
||||||
const alarm = destr<NdmDeviceAlarmLogResultVO>(message.body);
|
const alarm = destr<NdmDeviceAlarmLogResultVO>(message.body);
|
||||||
// console.log(alarm);
|
// console.log(alarm);
|
||||||
if (alarm.alarmCategory === '1') {
|
if (alarm.alarmCategory === '1') {
|
||||||
@@ -65,7 +67,7 @@ onMounted(() => {
|
|||||||
},
|
},
|
||||||
onDisconnect: () => {
|
onDisconnect: () => {
|
||||||
console.log('Stomp连接断开');
|
console.log('Stomp连接断开');
|
||||||
stompClient.value?.unsubscribe('/topic/deviceAlarm');
|
stompClient.value?.unsubscribe(SUBSCRIBE_TOPIC);
|
||||||
},
|
},
|
||||||
onStompError: (frame) => {
|
onStompError: (frame) => {
|
||||||
console.log('Stomp错误', frame);
|
console.log('Stomp错误', frame);
|
||||||
|
|||||||
Reference in New Issue
Block a user