up. 优化代码内容

This commit is contained in:
扶桑花间 2025-08-29 22:38:21 +08:00
parent 9e41b66e5f
commit 5a1fd83430
2 changed files with 18 additions and 14 deletions

View File

@ -72,7 +72,7 @@ class GatewaySubscribe
GatewayClientService::sendToClient($put->wsClientId, new OutMessage( GatewayClientService::sendToClient($put->wsClientId, new OutMessage(
WsTypeEnum::System, WsTypeEnum::System,
WsEventEnum::Notification, WsEventEnum::Notification,
new ElNotification(title: '登录成功,欢迎您', message: "当前登录Ip: $ip"), new ElNotification(title: '登录成功,欢迎您', message: "当前登录Ip: $ip", position: 'bottom-right'),
)); ));
} }

View File

@ -9,6 +9,7 @@ import {
} from '../types'; } from '../types';
import {computed, ref} from 'vue'; import {computed, ref} from 'vue';
import {wsEventManager} from './event-manager'; import {wsEventManager} from './event-manager';
import {systemEvent} from '@/plugins/websocket/core/event';
// 创建WebSocket实例 // 创建WebSocket实例
export function createWsInstance(config: WsConfig): WsInstance { export function createWsInstance(config: WsConfig): WsInstance {
@ -46,14 +47,18 @@ export function createWsInstance(config: WsConfig): WsInstance {
}; };
const handleMessage = (e: MessageEvent) => { const handleMessage = (e: MessageEvent) => {
addMessage(e.data, WsMessageType.INCOMING);
const jsonData = JSON.parse(e.data); const jsonData = JSON.parse(e.data);
if (jsonData.event == WsEvent.LOCK_CLIENT_SCREEN) { /*
// 锁屏 * @{type: "system", event: "事件名称", data: {}}
wsEventManager.emit(WsEvent.LOCK_CLIENT_SCREEN, e); */
if (jsonData.type == WsMessageType.SYSTEM) {
systemEvent.trigger(jsonData.event, jsonData.data);
} }
} // if (jsonData.event == WsEvent.LOCK_CLIENT_SCREEN) {
// // 锁屏
// wsEventManager.emit(WsEvent.LOCK_CLIENT_SCREEN, e);
// }
};
const handleError = (e: Event) => { const handleError = (e: Event) => {
isConnecting.value = false; isConnecting.value = false;
@ -161,4 +166,3 @@ export let wsInstance: WsInstance | null = null;
export function initWs(config: WsConfig): WsInstance { export function initWs(config: WsConfig): WsInstance {
return (wsInstance = wsInstance || createWsInstance(config)); return (wsInstance = wsInstance || createWsInstance(config));
} }