fix(Upload/MessageEnter): 移除调试日志并完善文件类型判断逻辑
移除SimpleFileUpload组件中上传成功后的console.log 在MessageEnter组件中添加文件类型判断功能,根据文件扩展名确定消息类型并发送相应消息
This commit is contained in:
@@ -50,7 +50,6 @@ const SimpleFileUpload: React.FC<SimpleFileUploadProps> = ({
|
||||
|
||||
try {
|
||||
const fileUrl = await uploadFile(file);
|
||||
console.log("上传成功,文件URL:", fileUrl);
|
||||
onFileUploaded?.(fileUrl);
|
||||
message.success("文件上传成功");
|
||||
} catch (error: any) {
|
||||
|
||||
@@ -97,9 +97,58 @@ const MessageEnter: React.FC<MessageEnterProps> = ({ 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 (
|
||||
|
||||
Reference in New Issue
Block a user