refactor: 移除Cunkebao项目中未使用的微信聊天相关组件和代码

重构Touchkebao项目中的微信API调用逻辑,优化消息记录处理
This commit is contained in:
超级老白兔
2025-09-15 18:03:14 +08:00
parent d802b9da1f
commit c88431b564
50 changed files with 79 additions and 11341 deletions

View File

@@ -13,18 +13,18 @@ import {
} from "./data";
// 好友列表
export function getWechatFriendList() {
return request("/v1/kefu/wechatFriend/list", {}, "GET");
export function getWechatFriendList(params) {
return request("/v1/kefu/wechatFriend/list", params, "GET");
}
// 群列表
export function getWechatChatroomList() {
return request("/v1/kefu/wechatChatroom/list", {}, "GET");
export function getWechatChatroomList(params) {
return request("/v1/kefu/wechatChatroom/list", params, "GET");
}
//群、好友聊天记录列表
export function getChatroomList() {
return request("/v1/kefu/wechatChatroom/list", {}, "GET");
export function getMessageList() {
return request("/v1/kefu/message/list", {}, "GET");
}
//获取客服列表

View File

@@ -36,6 +36,26 @@ const MessageRecord: React.FC<MessageRecordProps> = ({ contract }) => {
);
};
// 提取content字符串中冒号后面的JSON部分
const extractJsonFromContent = (content: string): object | null => {
try {
// 查找第一个冒号的位置
const colonIndex = content.indexOf(":");
if (colonIndex === -1) {
return null;
}
// 提取冒号后面的部分并去除前后空格
const jsonStr = content.substring(colonIndex + 1).trim();
// 尝试解析JSON
return JSON.parse(jsonStr);
} catch (error) {
console.error("解析JSON失败:", error);
return null;
}
};
// 解析表情包文字格式[表情名称]并替换为img标签
const parseEmojiText = (text: string): React.ReactNode[] => {
const emojiRegex = /\[([^\]]+)\]/g;
@@ -193,6 +213,14 @@ const MessageRecord: React.FC<MessageRecordProps> = ({ contract }) => {
</div>
);
case 34: // 语音消息
if (typeof content !== "string" || !content.trim()) {
return renderErrorMessage("[语音消息 - 无效内容]");
}
// content直接是音频URL字符串
return <AudioMessage audioUrl={content} msgId={String(msg.id)} />;
case 43: // 视频消息
return (
<VideoMessage content={content || ""} msg={msg} contract={contract} />
@@ -225,17 +253,16 @@ const MessageRecord: React.FC<MessageRecordProps> = ({ contract }) => {
}
return renderErrorMessage("[表情包]");
case 34: // 语音消息
if (typeof content !== "string" || !content.trim()) {
return renderErrorMessage("[语音消息 - 无效内容]");
}
// content直接是音频URL字符串
return <AudioMessage audioUrl={content} msgId={String(msg.id)} />;
case 49: // 小程序/文章/其他:图文、文件
return <SmallProgramMessage content={content || ""} />;
case 1090519089: {
// 文本消息
const extractedJson = extractJsonFromContent(content);
const newContent = extractedJson
? JSON.stringify(extractedJson)
: content;
return <SmallProgramMessage content={newContent || ""} />;
}
default: {
// 兼容旧版本和未知消息类型的处理逻辑
if (typeof content !== "string" || !content.trim()) {

View File

@@ -13,10 +13,7 @@ import {
getControlTerminalList,
getContactList,
getGroupList,
getAgentList,
getChatroomList,
getWechatFriendList,
getWechatChatroomList,
getMessageList,
} from "./api";
import { useUserStore } from "@/store/module/user";
@@ -33,7 +30,7 @@ const { login2 } = useUserStore.getState();
export const chatInitAPIdata = async () => {
try {
//获取联系人列表
const contractList = await getWechatFriendList();
const contractList = await getAllContactList();
//获取联系人列表
asyncContractList(contractList);
@@ -43,7 +40,15 @@ export const chatInitAPIdata = async () => {
await asyncWeChatGroup(groupList);
const kfUserList: KfUserListData[] = await getAgentList();
// 提取不重复的wechatAccountId组
const uniqueWechatAccountIds: number[] = getUniqueWechatAccountIds(
contractList,
groupList,
);
//获取控制终端列表
const kfUserList: KfUserListData[] =
await getControlTerminalListByWechatAccountIds(uniqueWechatAccountIds);
//获取用户列表
await asyncKfUserList(kfUserList);
@@ -53,36 +58,35 @@ export const chatInitAPIdata = async () => {
await asyncCountLables(countLables);
//获取消息会话列表并按lastUpdateTime排序
// const filterUserSessions = contractList?.filter(
// v => v?.config && v.config?.chat,
// );
// const filterGroupSessions = groupList?.filter(
// v => v?.config && v.config?.chat,
// );
const filterUserSessions = contractList?.filter(
v => v?.config && v.config?.chat,
);
const filterGroupSessions = groupList?.filter(
v => v?.config && v.config?.chat,
);
//排序功能
// const sortedSessions = [...filterUserSessions, ...filterGroupSessions].sort(
// (a, b) => {
// // 如果lastUpdateTime不存在则将其排在最后
// if (!a.lastUpdateTime) return 1;
// if (!b.lastUpdateTime) return -1;
const sortedSessions = [...filterUserSessions, ...filterGroupSessions].sort(
(a, b) => {
// 如果lastUpdateTime不存在则将其排在最后
if (!a.lastUpdateTime) return 1;
if (!b.lastUpdateTime) return -1;
// // 首先按时间降序排列(最新的在前面)
// const timeCompare =
// new Date(b.lastUpdateTime).getTime() -
// new Date(a.lastUpdateTime).getTime();
// 首先按时间降序排列(最新的在前面)
const timeCompare =
new Date(b.lastUpdateTime).getTime() -
new Date(a.lastUpdateTime).getTime();
// // 如果时间相同,则按未读消息数量降序排列
// if (timeCompare === 0) {
// // 如果unreadCount不存在则将其排在后面
// const aUnread = a.unreadCount || 0;
// const bUnread = b.unreadCount || 0;
// return bUnread - aUnread; // 未读消息多的排在前面
// }
// 如果时间相同,则按未读消息数量降序排列
if (timeCompare === 0) {
// 如果unreadCount不存在则将其排在后面
const aUnread = a.unreadCount || 0;
const bUnread = b.unreadCount || 0;
return bUnread - aUnread; // 未读消息多的排在前面
}
// return timeCompare;
// },
// );
const sortedSessions = await getChatroomList();
return timeCompare;
},
);
//会话数据同步
asyncChatSessions(sortedSessions);
@@ -103,7 +107,7 @@ export const initSocket = () => {
// 如果已经连接或正在连接,则不重复连接
if (["connected", "connecting"].includes(status)) {
// console.log("WebSocket已连接或正在连接跳过重复连接", { status });
console.log("WebSocket已连接或正在连接跳过重复连接", { status });
return;
}