up. 优化代码内容
This commit is contained in:
parent
9e41b66e5f
commit
5a1fd83430
@ -72,7 +72,7 @@ class GatewaySubscribe
|
||||
GatewayClientService::sendToClient($put->wsClientId, new OutMessage(
|
||||
WsTypeEnum::System,
|
||||
WsEventEnum::Notification,
|
||||
new ElNotification(title: '登录成功,欢迎您', message: "当前登录Ip: $ip"),
|
||||
new ElNotification(title: '登录成功,欢迎您', message: "当前登录Ip: $ip", position: 'bottom-right'),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@ import {
|
||||
} from '../types';
|
||||
import {computed, ref} from 'vue';
|
||||
import {wsEventManager} from './event-manager';
|
||||
import {systemEvent} from '@/plugins/websocket/core/event';
|
||||
|
||||
// 创建WebSocket实例
|
||||
export function createWsInstance(config: WsConfig): WsInstance {
|
||||
@ -46,14 +47,18 @@ export function createWsInstance(config: WsConfig): WsInstance {
|
||||
};
|
||||
|
||||
const handleMessage = (e: MessageEvent) => {
|
||||
addMessage(e.data, WsMessageType.INCOMING);
|
||||
const jsonData = JSON.parse(e.data);
|
||||
if (jsonData.event == WsEvent.LOCK_CLIENT_SCREEN) {
|
||||
// 锁屏
|
||||
wsEventManager.emit(WsEvent.LOCK_CLIENT_SCREEN, e);
|
||||
/*
|
||||
* 解析后数据格式应该统一为 @{type: "system", event: "事件名称", data: {}}
|
||||
*/
|
||||
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) => {
|
||||
isConnecting.value = false;
|
||||
@ -161,4 +166,3 @@ export let wsInstance: WsInstance | null = null;
|
||||
export function initWs(config: WsConfig): WsInstance {
|
||||
return (wsInstance = wsInstance || createWsInstance(config));
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user