fix(app-layout): concat stomp broker url instead of just vite proxy

This commit is contained in:
yangsy
2025-11-04 22:26:02 +08:00
parent c08f6f0f59
commit bb1b70df47

View File

@@ -1,4 +1,6 @@
<script lang="ts">
const SUBSCRIBE_TOPIC = '/topic/deviceAlarm';
function renderIcon(icon: Component): () => VNode {
return () => h(NIcon, null, { default: () => h(icon) });
}
@@ -41,12 +43,12 @@ onBeforeMount(() => {
});
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({
brokerURL: '/ws',
// webSocketFactory: () => {
// const ws = new WebSocket('/ws');
// return ws;
// },
brokerURL,
reconnectDelay: 5000,
heartbeatIncoming: 10000,
heartbeatOutgoing: 10000,
@@ -55,7 +57,7 @@ onMounted(() => {
// },
onConnect: () => {
console.log('Stomp连接成功');
stompClient.value?.subscribe('/topic/deviceAlarm', (message) => {
stompClient.value?.subscribe(SUBSCRIBE_TOPIC, (message) => {
const alarm = destr<NdmDeviceAlarmLogResultVO>(message.body);
// console.log(alarm);
if (alarm.alarmCategory === '1') {
@@ -65,7 +67,7 @@ onMounted(() => {
},
onDisconnect: () => {
console.log('Stomp连接断开');
stompClient.value?.unsubscribe('/topic/deviceAlarm');
stompClient.value?.unsubscribe(SUBSCRIBE_TOPIC);
},
onStompError: (frame) => {
console.log('Stomp错误', frame);