feat:完善功能

This commit is contained in:
zjc
2025-01-16 12:37:23 +08:00
parent ef5cb642ca
commit 2a11f91d36
43 changed files with 2644 additions and 3108 deletions

View File

@@ -6,6 +6,7 @@ const homeStore = useHomeStore()
export function useWebSocket(url) {
let socket = ref(null) // socket对象
let isConnected = ref(false) // 是否连接成功
let dataRes = ref(null) // 存储推送数据
const connectWebSocket = () => {
socket.value = new WebSocket(url, 'echo-protocol', {
@@ -25,7 +26,7 @@ export function useWebSocket(url) {
// 处理接收到的消息
if (JSON.parse(message.data)) {
let data = JSON.parse(message.data)
console.log(data, '接收到的消息')
dataRes.value = data
switch (data.type) {
case 'userPortrait':
homeStore.setUserPortraitData(data.data)
@@ -87,5 +88,5 @@ export function useWebSocket(url) {
}
})
return { socket, isConnected, connectWebSocket, sendMessage }
return { socket, dataRes, isConnected, connectWebSocket, sendMessage }
}