feat(消息列表): 添加搜索功能并优化客服筛选逻辑

添加对消息列表的搜索功能,支持根据昵称和备注进行模糊匹配
优化客服筛选逻辑,将筛选和搜索功能合并处理
在转接和转回操作后增加删除聊天会话和本地数据的逻辑
This commit is contained in:
超级老白兔
2025-09-10 17:27:59 +08:00
parent 51b1918f72
commit ad60e684fc
2 changed files with 46 additions and 8 deletions

View File

@@ -7,6 +7,8 @@ import {
WechatFriendRebackAllot,
} from "@/pages/pc/ckbox/weChat/api";
import { useCurrentContact } from "@/store/module/weChat/weChat";
import { deleteChatSession } from "@/store/module/ckchat/ckchat";
import { contractService, weChatGroupService } from "@/utils/db";
const { TextArea } = Input;
const { Option } = Select;
@@ -85,6 +87,18 @@ const ToContract: React.FC<ToContractProps> = ({
}
message.success("转接成功");
try {
// 删除聊天会话
deleteChatSession(currentContact.id.toString());
// 删除本地数据库记录
if ("chatroomId" in currentContact) {
await weChatGroupService.delete(currentContact.id);
} else {
await contractService.delete(currentContact.id.toString());
}
} catch (deleteError) {
console.error("删除本地数据失败:", deleteError);
}
closeModal();
} catch (error) {
console.error("转接失败:", error);
@@ -113,6 +127,18 @@ const ToContract: React.FC<ToContractProps> = ({
}
message.success("转回成功");
try {
// 删除聊天会话
deleteChatSession(currentContact.id.toString());
// 删除本地数据库记录
if ("chatroomId" in currentContact) {
await weChatGroupService.delete(currentContact.id);
} else {
await contractService.delete(currentContact.id);
}
} catch (deleteError) {
console.error("删除本地数据失败:", deleteError);
}
closeModal();
} catch (error) {
console.error("转回失败:", error);

View File

@@ -19,17 +19,29 @@ const MessageList: React.FC<MessageListProps> = () => {
const [chatSessions, setChatSessions] = useState<
(ContractData | weChatGroup)[]
>([]);
const searchKeyword = useCkChatStore(state => state.searchKeyword);
useEffect(() => {
if (kfSelected == 0) {
setChatSessions(getChatSessions);
} else {
const newChatSessions = getChatSessions.filter(
v => v.wechatAccountId === kfSelected && kfSelected != 0,
let filteredSessions = getChatSessions;
// 根据客服筛选
if (kfSelected !== 0) {
filteredSessions = filteredSessions.filter(
v => v.wechatAccountId === kfSelected,
);
setChatSessions(newChatSessions);
}
}, [getChatSessions, kfSelected]);
// 根据搜索关键词进行模糊匹配
if (searchKeyword.trim()) {
const keyword = searchKeyword.toLowerCase();
filteredSessions = filteredSessions.filter(v => {
const nickname = (v.nickname || "").toLowerCase();
const conRemark = (v.conRemark || "").toLowerCase();
return nickname.includes(keyword) || conRemark.includes(keyword);
});
}
setChatSessions(filteredSessions);
}, [getChatSessions, kfSelected, searchKeyword]);
return (
<div className={styles.messageList}>
<List