转给他人逻辑处理,包括关闭和删除联系人、联系会话
This commit is contained in:
@@ -7,9 +7,11 @@ import {
|
|||||||
WechatFriendRebackAllot,
|
WechatFriendRebackAllot,
|
||||||
} from "@/pages/pc/ckbox/weChat/api";
|
} from "@/pages/pc/ckbox/weChat/api";
|
||||||
import { useCurrentContact } from "@/store/module/weChat/weChat";
|
import { useCurrentContact } from "@/store/module/weChat/weChat";
|
||||||
import { useCkChatStore } from "@/store/module/ckchat/ckchat";
|
import { ContactManager } from "@/utils/dbAction/contact";
|
||||||
import { ContactManager } from "@/utils/dbAction";
|
import { MessageManager } from "@/utils/dbAction/message";
|
||||||
|
import { triggerRefresh } from "@/store/module/weChat/message";
|
||||||
import { useUserStore } from "@/store/module/user";
|
import { useUserStore } from "@/store/module/user";
|
||||||
|
import { useWeChatStore } from "@/store/module/weChat/weChat";
|
||||||
const { TextArea } = Input;
|
const { TextArea } = Input;
|
||||||
const { Option } = Select;
|
const { Option } = Select;
|
||||||
|
|
||||||
@@ -33,6 +35,9 @@ const ToContract: React.FC<ToContractProps> = ({
|
|||||||
disabled = false,
|
disabled = false,
|
||||||
}) => {
|
}) => {
|
||||||
const currentContact = useCurrentContact();
|
const currentContact = useCurrentContact();
|
||||||
|
const clearCurrentContact = useWeChatStore(
|
||||||
|
state => state.clearCurrentContact,
|
||||||
|
);
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
const [selectedTarget, setSelectedTarget] = useState<number | null>(null);
|
const [selectedTarget, setSelectedTarget] = useState<number | null>(null);
|
||||||
const [comment, setComment] = useState<string>("");
|
const [comment, setComment] = useState<string>("");
|
||||||
@@ -40,7 +45,6 @@ const ToContract: React.FC<ToContractProps> = ({
|
|||||||
const [customerServiceList, setCustomerServiceList] = useState<DepartItem[]>(
|
const [customerServiceList, setCustomerServiceList] = useState<DepartItem[]>(
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
const deleteChatSession = useCkChatStore(state => state.deleteChatSession);
|
|
||||||
// 打开弹窗
|
// 打开弹窗
|
||||||
const openModal = () => {
|
const openModal = () => {
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
@@ -67,8 +71,6 @@ const ToContract: React.FC<ToContractProps> = ({
|
|||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
console.log(currentContact);
|
|
||||||
|
|
||||||
// 调用转接接口
|
// 调用转接接口
|
||||||
if (currentContact) {
|
if (currentContact) {
|
||||||
if ("chatroomId" in currentContact && currentContact.chatroomId) {
|
if ("chatroomId" in currentContact && currentContact.chatroomId) {
|
||||||
@@ -88,18 +90,37 @@ const ToContract: React.FC<ToContractProps> = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message.success("转接成功");
|
// 先关闭弹窗
|
||||||
|
closeModal();
|
||||||
|
|
||||||
|
// 删除本地数据库记录并关闭聊天窗口
|
||||||
try {
|
try {
|
||||||
// 删除聊天会话
|
|
||||||
deleteChatSession(currentContact.id);
|
|
||||||
// 删除本地数据库记录
|
|
||||||
const currentUserId = useUserStore.getState().user?.id || 0;
|
const currentUserId = useUserStore.getState().user?.id || 0;
|
||||||
const contactType = "chatroomId" in currentContact ? "group" : "friend";
|
const contactType = "chatroomId" in currentContact ? "group" : "friend";
|
||||||
|
|
||||||
|
// 1. 从会话列表数据库删除
|
||||||
|
await MessageManager.deleteSession(
|
||||||
|
currentUserId,
|
||||||
|
currentContact.id,
|
||||||
|
contactType,
|
||||||
|
);
|
||||||
|
console.log("✅ 已从会话列表删除");
|
||||||
|
|
||||||
|
// 2. 从联系人数据库删除
|
||||||
await ContactManager.deleteContact(currentContact.id);
|
await ContactManager.deleteContact(currentContact.id);
|
||||||
|
console.log("✅ 已从联系人数据库删除");
|
||||||
|
|
||||||
|
// 3. 触发会话列表刷新
|
||||||
|
triggerRefresh();
|
||||||
|
|
||||||
|
// 4. 清空当前选中的联系人(关闭聊天窗口)
|
||||||
|
clearCurrentContact();
|
||||||
|
|
||||||
|
message.success("转接成功,已清理本地数据");
|
||||||
} catch (deleteError) {
|
} catch (deleteError) {
|
||||||
console.error("删除本地数据失败:", deleteError);
|
console.error("删除本地数据失败:", deleteError);
|
||||||
|
message.error("删除本地数据失败");
|
||||||
}
|
}
|
||||||
closeModal();
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("转接失败:", error);
|
console.error("转接失败:", error);
|
||||||
message.error("转接失败,请重试");
|
message.error("转接失败,请重试");
|
||||||
@@ -126,18 +147,37 @@ const ToContract: React.FC<ToContractProps> = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message.success("转回成功");
|
// 先关闭弹窗
|
||||||
|
closeModal();
|
||||||
|
|
||||||
|
// 删除本地数据库记录并关闭聊天窗口
|
||||||
try {
|
try {
|
||||||
// 删除聊天会话
|
|
||||||
deleteChatSession(currentContact.id);
|
|
||||||
// 删除本地数据库记录
|
|
||||||
const currentUserId = useUserStore.getState().user?.id || 0;
|
const currentUserId = useUserStore.getState().user?.id || 0;
|
||||||
const contactType = "chatroomId" in currentContact ? "group" : "friend";
|
const contactType = "chatroomId" in currentContact ? "group" : "friend";
|
||||||
|
|
||||||
|
// 1. 从会话列表数据库删除
|
||||||
|
await MessageManager.deleteSession(
|
||||||
|
currentUserId,
|
||||||
|
currentContact.id,
|
||||||
|
contactType,
|
||||||
|
);
|
||||||
|
console.log("✅ 已从会话列表删除");
|
||||||
|
|
||||||
|
// 2. 从联系人数据库删除
|
||||||
await ContactManager.deleteContact(currentContact.id);
|
await ContactManager.deleteContact(currentContact.id);
|
||||||
|
console.log("✅ 已从联系人数据库删除");
|
||||||
|
|
||||||
|
// 3. 触发会话列表刷新
|
||||||
|
triggerRefresh();
|
||||||
|
|
||||||
|
// 4. 清空当前选中的联系人(关闭聊天窗口)
|
||||||
|
clearCurrentContact();
|
||||||
|
|
||||||
|
message.success("转回成功,已清理本地数据");
|
||||||
} catch (deleteError) {
|
} catch (deleteError) {
|
||||||
console.error("删除本地数据失败:", deleteError);
|
console.error("删除本地数据失败:", deleteError);
|
||||||
|
message.error("删除本地数据失败");
|
||||||
}
|
}
|
||||||
closeModal();
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("转回失败:", error);
|
console.error("转回失败:", error);
|
||||||
message.error("转回失败,请重试");
|
message.error("转回失败,请重试");
|
||||||
|
|||||||
@@ -49,8 +49,6 @@ const MessageEnter: React.FC<MessageEnterProps> = ({ contract }) => {
|
|||||||
const isLoadingAiChat = useWeChatStore(state => state.isLoadingAiChat);
|
const isLoadingAiChat = useWeChatStore(state => state.isLoadingAiChat);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (quoteMessageContent) {
|
if (quoteMessageContent) {
|
||||||
console.log("quoteMessageContent", quoteMessageContent);
|
|
||||||
|
|
||||||
setInputValue(quoteMessageContent);
|
setInputValue(quoteMessageContent);
|
||||||
}
|
}
|
||||||
}, [quoteMessageContent]);
|
}, [quoteMessageContent]);
|
||||||
|
|||||||
Reference in New Issue
Block a user