新增快捷回复功能:引入WebSocket支持,优化快捷语发送逻辑,增加发送确认预览,提升用户体验和代码可读性。
This commit is contained in:
@@ -38,6 +38,7 @@ import Layout from "@/components/Layout/LayoutFiexd";
|
||||
import QuickReplyModal from "./components/QuickReplyModal";
|
||||
import GroupModal from "./components/GroupModal";
|
||||
import { useWeChatStore } from "@/store/module/weChat/weChat";
|
||||
import { useWebSocketStore } from "@/store/module/websocket/websocket";
|
||||
|
||||
// 消息类型枚举
|
||||
export enum MessageType {
|
||||
@@ -80,6 +81,74 @@ const QuickWords: React.FC<QuickWordsProps> = ({ onInsert }) => {
|
||||
const updateQuoteMessageContent = useWeChatStore(
|
||||
state => state.updateQuoteMessageContent,
|
||||
);
|
||||
const currentContract = useWeChatStore(state => state.currentContract);
|
||||
const { sendCommand } = useWebSocketStore.getState();
|
||||
|
||||
const sendQuickReplyNow = (reply: QuickWordsReply) => {
|
||||
if (!currentContract) return;
|
||||
const params = {
|
||||
wechatAccountId: currentContract.wechatAccountId,
|
||||
wechatChatroomId: currentContract?.chatroomId ? currentContract.id : 0,
|
||||
wechatFriendId: currentContract?.chatroomId ? 0 : currentContract.id,
|
||||
msgSubType: 0,
|
||||
msgType: reply.msgType,
|
||||
content: reply.content,
|
||||
} as any;
|
||||
sendCommand("CmdSendMessage", params);
|
||||
};
|
||||
|
||||
const previewAndConfirmSend = (reply: QuickWordsReply) => {
|
||||
let previewNode: React.ReactNode = null;
|
||||
if (reply.msgType === MessageType.IMAGE) {
|
||||
previewNode = (
|
||||
<div style={{ textAlign: "center" }}>
|
||||
<img
|
||||
src={reply.content}
|
||||
alt="预览"
|
||||
style={{ maxWidth: 360, maxHeight: 320, borderRadius: 6 }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
} else if (reply.msgType === MessageType.VIDEO) {
|
||||
try {
|
||||
const json = JSON.parse(reply.content || "{}");
|
||||
const cover = json.previewImage || json.thumbPath || "";
|
||||
previewNode = (
|
||||
<div style={{ textAlign: "center" }}>
|
||||
{cover ? (
|
||||
<img
|
||||
src={String(cover)}
|
||||
alt="视频预览"
|
||||
style={{ maxWidth: 360, maxHeight: 320, borderRadius: 6 }}
|
||||
/>
|
||||
) : (
|
||||
<div>视频消息</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
} catch {
|
||||
previewNode = <div>视频消息</div>;
|
||||
}
|
||||
} else if (reply.msgType === MessageType.LINK) {
|
||||
previewNode = (
|
||||
<div>
|
||||
<div style={{ fontWeight: 600, marginBottom: 8 }}>{reply.title}</div>
|
||||
<div style={{ color: "#1677ff" }}>{reply.content}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Modal.confirm({
|
||||
title: "确认发送该快捷语?",
|
||||
content: previewNode,
|
||||
okText: "发送",
|
||||
cancelText: "取消",
|
||||
onOk: () => {
|
||||
sendQuickReplyNow(reply);
|
||||
message.success("已发送");
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// 获取快捷语数据
|
||||
const fetchQuickWords = useCallback(async () => {
|
||||
@@ -172,10 +241,10 @@ const QuickWords: React.FC<QuickWordsProps> = ({ onInsert }) => {
|
||||
if ([MessageType.TEXT].includes(reply.msgType)) {
|
||||
updateQuoteMessageContent(reply.content || "");
|
||||
} else if ([MessageType.LINK].includes(reply.msgType)) {
|
||||
updateQuoteMessageContent(reply.content || "");
|
||||
previewAndConfirmSend(reply);
|
||||
} else {
|
||||
// 非文本类型,插入标题作为占位,方便用户手动调整
|
||||
updateQuoteMessageContent(reply.title || "");
|
||||
// 图片/视频等类型:弹出预览确认后直接发送
|
||||
previewAndConfirmSend(reply);
|
||||
}
|
||||
} catch (_) {}
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user