lxl-dev #3

Merged
zhanghao merged 122 commits from lxl-dev into dev 2026-08-24 13:55:18 +08:00
3 changed files with 33 additions and 4 deletions
Showing only changes of commit fabfa05db5 - Show all commits

View File

@ -17,6 +17,7 @@ class WebSocketManager {
this.processingMessages = false; this.processingMessages = false;
this.maxQueueSize = 100; this.maxQueueSize = 100;
this.status = false; this.status = false;
this.channelSubscriptions = new Set();
} }
connect() { connect() {
@ -33,6 +34,7 @@ class WebSocketManager {
this.status = true; this.status = true;
this.startHeartbeat(); this.startHeartbeat();
this.processMessageQueue(); this.processMessageQueue();
this.restoreChannelSubscriptions();
this.dispatch('open'); this.dispatch('open');
}; };
@ -159,13 +161,31 @@ class WebSocketManager {
} }
send(payload) { send(payload) {
if (payload?.type === 'channel_subscription' && payload.channel) {
if (payload.action === 'subscribe') {
this.channelSubscriptions.add(payload.channel);
} else if (payload.action === 'unsubscribe') {
this.channelSubscriptions.delete(payload.channel);
}
}
if (this.ws && this.ws.readyState === 1) { if (this.ws && this.ws.readyState === 1) {
this.ws.send(JSON.stringify(payload)); this.ws.send(JSON.stringify(payload));
} else { } else if (payload?.type !== 'channel_subscription') {
console.warn('WebSocket 未连接,消息发送失败'); console.warn('WebSocket 未连接,消息发送失败');
} }
} }
restoreChannelSubscriptions() {
if (!this.ws || this.ws.readyState !== 1) return;
this.channelSubscriptions.forEach((channel) => {
this.ws.send(JSON.stringify({
type: 'channel_subscription',
action: 'subscribe',
channel,
}));
});
}
close() { close() {
this.isManualClose = true; this.isManualClose = true;
this.status = false; this.status = false;

View File

@ -501,7 +501,6 @@ const subscribeDebounced = debounce(async (sub) => {
// 清理旧回调 // 清理旧回调
if (socketChannelCallbacks.value[channel]) { if (socketChannelCallbacks.value[channel]) {
socket.off(channel, socketChannelCallbacks.value[channel]); socket.off(channel, socketChannelCallbacks.value[channel]);
console.log('清理旧回调:', channel);
} }
const callback = (data) => { const callback = (data) => {
@ -555,15 +554,21 @@ const handleOpenLog = async (row) => {
logDialogData.value = res.rows logDialogData.value = res.rows
} }
} }
const refreshAfterSocketReconnect = () => {
getList()
getHistoryList()
}
onMounted(() => { onMounted(() => {
getTaskData(); getTaskData();
getList(); getList();
getHistoryList(); getHistoryList();
subscribeDebounced(true) subscribeDebounced(true)
socket?.on('open', refreshAfterSocketReconnect)
}) })
onUnmounted(() => { onUnmounted(() => {
subscribeDebounced(false) subscribeDebounced(false)
socket?.off('open', refreshAfterSocketReconnect)
}) })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -543,11 +543,9 @@ const subscribeDebounced = debounce(async (sub) => {
// 清理旧回调 // 清理旧回调
if (socketChannelCallbacks.value[channel]) { if (socketChannelCallbacks.value[channel]) {
socket.off(channel, socketChannelCallbacks.value[channel]); socket.off(channel, socketChannelCallbacks.value[channel]);
console.log('清理旧回调:', channel);
} }
const callback = (data) => { const callback = (data) => {
console.log('data', data)
if (data !== '500') { if (data !== '500') {
if (data.status !== 0) { if (data.status !== 0) {
const steps = pointList_runningTask.value[data.taskId] || [] const steps = pointList_runningTask.value[data.taskId] || []
@ -598,6 +596,10 @@ const handleOpenLog = async (row) => {
logDialogData.value = res.rows logDialogData.value = res.rows
} }
} }
const refreshAfterSocketReconnect = () => {
getList()
getHistoryList()
}
onMounted(() => { onMounted(() => {
getTaskData(); getTaskData();
getPhoneData(); getPhoneData();
@ -605,10 +607,12 @@ onMounted(() => {
getList(); getList();
getHistoryList(); getHistoryList();
subscribeDebounced(true) subscribeDebounced(true)
socket?.on('open', refreshAfterSocketReconnect)
}) })
onUnmounted(() => { onUnmounted(() => {
subscribeDebounced(false) subscribeDebounced(false)
socket?.off('open', refreshAfterSocketReconnect)
}) })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>