Browse Source

Merge branch 'master' of https://git.nanodreamtech.com/wkw/wallet_app

wkw 1 week ago
parent
commit
5a5190b66e

+ 21 - 0
src/common/constant/msgType.js

@@ -0,0 +1,21 @@
+export const MSG_TYPE = {
+  TEXT: 1, // 文本
+  FILE: 2, // 文件
+  IMAGE: 3, // 图片
+  AUDIO: 4, // 音频
+  VIDEO: 5, // 视频
+  AUDIO_ONLINE: 6, // 音频
+  VIDEO_ONLINE: 7, // 视频
+};
+export const MSG_TYPE_MAP = [
+  MSG_TYPE.TEXT,
+  MSG_TYPE.FILE,
+  MSG_TYPE.IMAGE,
+  MSG_TYPE.AUDIO,
+  MSG_TYPE.VIDEO,
+  MSG_TYPE.AUDIO_ONLINE,
+  MSG_TYPE.VIDEO_ONLINE,
+]
+
+export const MESSAGE_TYPE_USER = 1; // 单聊
+export const MESSAGE_TYPE_GROUP = 2; // 群聊

+ 3 - 2
src/stores/modules/webSocketStore.js

@@ -4,6 +4,7 @@ import { $root as protobuf } from "@/common/proto/proto";
 import * as Constant from "@/common/constant/Constant";
 import { useWalletStore } from "@/stores/modules/walletStore";
 import { getMessageApi  } from "@/api/path/im.api"
+import { MSG_TYPE, MSG_TYPE_MAP } from "@/common/constant/msgType";
 
 export const useWebSocketStore = defineStore("webSocketStore", {
   // 状态定义
@@ -133,7 +134,7 @@ export const useWebSocketStore = defineStore("webSocketStore", {
           });
 
           console.log("收到消息:", message);
-          if([1,2].includes(message.messageType)){
+          if(MSG_TYPE_MAP.includes(message.messageType)){
             // 更新状态
             this.messages.push({
               ...message,
@@ -231,7 +232,7 @@ export const useWebSocketStore = defineStore("webSocketStore", {
         fromUsername: walletStore.username,
         from: walletStore.account,
       };
-      if([1,2].includes(data.messageType)){
+      if(MSG_TYPE_MAP.includes(data.messageType)){
         this.messages.push({
           ...data,
           toUsername: data.friendUsername

+ 4 - 3
src/views/im/chat/index.vue

@@ -79,6 +79,7 @@ import { useWebSocketStore } from "@/stores/modules/webSocketStore.js";
 import { useWalletStore } from "@/stores/modules/walletStore.js";
 import { Keyboard } from "@capacitor/keyboard";
 import { Capacitor } from "@capacitor/core";
+import { MSG_TYPE, MESSAGE_TYPE_USER } from "@/common/constant/msgType";
 
 // 路由 & store
 const router = useRouter();
@@ -140,9 +141,9 @@ const sendMessage = () => {
   if (!text.value.trim()) return;
   const message = {
     content: text.value,
-    contentType: 1,
-    messageType: 1,
-    to: route.query.uuid,
+    contentType: MSG_TYPE.TEXT,  // 1: 文本消息 
+    messageType: MESSAGE_TYPE_USER, // 1: 单聊天
+    to:route.query.uuid, 
   };
   wsStore.sendMessage(message);
   text.value = "";