瀏覽代碼

socket连接就发送请求

xiaochan 3 月之前
父節點
當前提交
62576f2201
共有 1 個文件被更改,包括 10 次插入0 次删除
  1. 10 0
      src/utils/useCySocket.ts

+ 10 - 0
src/utils/useCySocket.ts

@@ -4,6 +4,7 @@ import {
   UseWebSocketReturn,
 } from "@vueuse/core";
 import { useUserStore } from "@/pinia/user-store";
+import { xcMessage } from "@/utils/xiaochan-element-plus";
 
 export type UsCyeWebSocketOptions = UseWebSocketOptions & {
   socketMsg?: {
@@ -47,6 +48,15 @@ export function useCySocket(url: any, options?: UsCyeWebSocketOptions) {
     };
   }
 
+  const oldConnected = val.onConnected;
+
+  val.onConnected = ws => {
+    if (setInfo && socket.status.value === "OPEN") {
+      socket.send(getUserInfo());
+    }
+    oldConnected?.(ws);
+  };
+
   const oldOnMessage = val.onMessage;
 
   val.onMessage = (ws, event) => {