From d0953585a74b638470baffdf422472bee01e003b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B6=85=E7=BA=A7=E8=80=81=E7=99=BD=E5=85=94?= Date: Tue, 9 Sep 2025 16:40:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(Upload/MessageEnter):=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=97=A5=E5=BF=97=E5=B9=B6=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=B1=BB=E5=9E=8B=E5=88=A4=E6=96=AD=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除SimpleFileUpload组件中上传成功后的console.log 在MessageEnter组件中添加文件类型判断功能,根据文件扩展名确定消息类型并发送相应消息 --- .../Upload/SimpleFileUpload/index.tsx | 1 - .../components/MessageEnter/index.tsx | 53 ++++++++++++++++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/Cunkebao/src/components/Upload/SimpleFileUpload/index.tsx b/Cunkebao/src/components/Upload/SimpleFileUpload/index.tsx index eda775ba..8ed346c4 100644 --- a/Cunkebao/src/components/Upload/SimpleFileUpload/index.tsx +++ b/Cunkebao/src/components/Upload/SimpleFileUpload/index.tsx @@ -50,7 +50,6 @@ const SimpleFileUpload: React.FC = ({ try { const fileUrl = await uploadFile(file); - console.log("上传成功,文件URL:", fileUrl); onFileUploaded?.(fileUrl); message.success("文件上传成功"); } catch (error: any) { diff --git a/Cunkebao/src/pages/pc/ckbox/weChat/components/ChatWindow/components/MessageEnter/index.tsx b/Cunkebao/src/pages/pc/ckbox/weChat/components/ChatWindow/components/MessageEnter/index.tsx index 35cb2678..750f0a7a 100644 --- a/Cunkebao/src/pages/pc/ckbox/weChat/components/ChatWindow/components/MessageEnter/index.tsx +++ b/Cunkebao/src/pages/pc/ckbox/weChat/components/ChatWindow/components/MessageEnter/index.tsx @@ -97,9 +97,58 @@ const MessageEnter: React.FC = ({ contract }) => { setInputValue(prevValue => prevValue + `[${emoji.name}]`); }; + // 根据文件格式判断消息类型 + const getMsgTypeByFileFormat = (filePath: string): number => { + const extension = filePath.toLowerCase().split(".").pop() || ""; + + // 图片格式 + const imageFormats = [ + "jpg", + "jpeg", + "png", + "gif", + "bmp", + "webp", + "svg", + "ico", + ]; + if (imageFormats.includes(extension)) { + return 3; // 图片 + } + + // 视频格式 + const videoFormats = [ + "mp4", + "avi", + "mov", + "wmv", + "flv", + "mkv", + "webm", + "3gp", + "rmvb", + ]; + if (videoFormats.includes(extension)) { + return 43; // 视频 + } + + // 其他格式默认为文件 + return 49; // 文件 + }; + const handleFileUploaded = (filePath: string) => { - console.log("文件上传成功,路径:", filePath); - // 这里可以根据需要处理文件路径,比如发送文件消息 + // msgType(1:文本 3:图片 43:视频 47:动图表情包(gif、其他表情包) 49:小程序/其他:图文、文件) + const msgType = getMsgTypeByFileFormat(filePath); + + const params = { + wechatAccountId: contract.wechatAccountId, + wechatChatroomId: contract?.chatroomId ? contract.id : 0, + wechatFriendId: contract?.chatroomId ? 0 : contract.id, + msgSubType: 0, + msgType, + content: filePath, + }; + sendCommand("CmdSendMessage", params); }; return (