feat(wechat): 添加朋友圈功能支持
- 在微信状态管理中新增朋友圈相关状态和方法 - 实现朋友圈数据获取、展示和交互功能 - 添加朋友圈API接口和WebSocket消息处理 - 优化朋友圈UI展示和样式
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { ChatRecord, ContractData, weChatGroup } from "@/pages/pc/ckbox/data";
|
||||
import { FriendsCircleItem } from "@/pages/pc/ckbox/weChat/components/SidebarMenu/FriendsCicle/index.data";
|
||||
|
||||
// 微信聊天相关的类型定义
|
||||
export interface WeChatState {
|
||||
// 当前选中的联系人/群组
|
||||
@@ -13,6 +15,11 @@ export interface WeChatState {
|
||||
isLoadingData: boolean;
|
||||
currentGroupMembers: any[];
|
||||
|
||||
// 朋友圈数据
|
||||
MomentOfKf: FriendsCircleItem[]; // 客服自己的朋友圈
|
||||
MomentOfSquare: FriendsCircleItem[]; // 朋友圈广场
|
||||
MomentOfFriend: FriendsCircleItem[]; // 好友的朋友圈
|
||||
|
||||
// Actions
|
||||
setCurrentContact: (
|
||||
contract: ContractData | weChatGroup,
|
||||
@@ -30,4 +37,13 @@ export interface WeChatState {
|
||||
setVideoUrl: (messageId: number, videoUrl: string) => void;
|
||||
addMessage: (message: ChatRecord) => void;
|
||||
receivedMsg: (message: ChatRecord) => void;
|
||||
|
||||
// 朋友圈相关方法
|
||||
setMomentOfKf: (moments: FriendsCircleItem[]) => void;
|
||||
setMomentOfSquare: (moments: FriendsCircleItem[]) => void;
|
||||
setMomentOfFriend: (moments: FriendsCircleItem[]) => void;
|
||||
addMomentOfKf: (moments: FriendsCircleItem[]) => void;
|
||||
addMomentOfSquare: (moments: FriendsCircleItem[]) => void;
|
||||
addMomentOfFriend: (moments: FriendsCircleItem[]) => void;
|
||||
clearAllMoments: () => void;
|
||||
}
|
||||
|
||||
@@ -273,6 +273,45 @@ export const useWeChatStore = create<WeChatState>()(
|
||||
messagesLoading: false,
|
||||
});
|
||||
},
|
||||
|
||||
// 朋友圈相关方法
|
||||
setMomentOfKf: moments => {
|
||||
set({ MomentOfKf: moments });
|
||||
},
|
||||
|
||||
setMomentOfSquare: moments => {
|
||||
set({ MomentOfSquare: moments });
|
||||
},
|
||||
|
||||
setMomentOfFriend: moments => {
|
||||
set({ MomentOfFriend: moments });
|
||||
},
|
||||
|
||||
addMomentOfKf: moments => {
|
||||
set(state => ({
|
||||
MomentOfKf: [...state.MomentOfKf, ...moments],
|
||||
}));
|
||||
},
|
||||
|
||||
addMomentOfSquare: moments => {
|
||||
set(state => ({
|
||||
MomentOfSquare: [...state.MomentOfSquare, ...moments],
|
||||
}));
|
||||
},
|
||||
|
||||
addMomentOfFriend: moments => {
|
||||
set(state => ({
|
||||
MomentOfFriend: [...state.MomentOfFriend, ...moments],
|
||||
}));
|
||||
},
|
||||
|
||||
clearAllMoments: () => {
|
||||
set({
|
||||
MomentOfKf: [],
|
||||
MomentOfSquare: [],
|
||||
MomentOfFriend: [],
|
||||
});
|
||||
},
|
||||
}),
|
||||
{
|
||||
name: "wechat-storage",
|
||||
|
||||
@@ -3,8 +3,7 @@ import { deepCopy } from "@/utils/common";
|
||||
import { WebSocketMessage } from "./websocket";
|
||||
import { getkfUserList, asyncKfUserList } from "@/store/module/ckchat/ckchat";
|
||||
import { Messages } from "./msg.data";
|
||||
|
||||
import { useWeChatStore } from "@/store/module/weChat/weChat";
|
||||
import { useWeChatStore } from "../weChat/weChat";
|
||||
// 消息处理器类型定义
|
||||
type MessageHandler = (message: WebSocketMessage) => void;
|
||||
const setVideoUrl = useWeChatStore.getState().setVideoUrl;
|
||||
@@ -77,7 +76,54 @@ const messageHandlers: Record<string, MessageHandler> = {
|
||||
|
||||
CmdDownloadVideoResult: message => {
|
||||
// 在这里添加具体的处理逻辑
|
||||
setVideoUrl(message.friendMessageId, message.url);
|
||||
console.log("视频下载结果:", message);
|
||||
// setVideoUrl(message.friendMessageId, message.url);
|
||||
},
|
||||
|
||||
// 朋友圈数据响应处理
|
||||
CmdFetchMomentResult: message => {
|
||||
console.log("朋友圈数据响应", message);
|
||||
const { wechatFriendId, wechatAccountId, result, isTimeline, seq } =
|
||||
message;
|
||||
const {
|
||||
setMomentOfKf,
|
||||
setMomentOfSquare,
|
||||
setMomentOfFriend,
|
||||
addMomentOfKf,
|
||||
addMomentOfSquare,
|
||||
addMomentOfFriend,
|
||||
} = useWeChatStore.getState();
|
||||
|
||||
if (result && Array.isArray(result)) {
|
||||
// 判断是否为第一页数据(通过seq或数据长度)
|
||||
const isFirstPage = result.length > 0;
|
||||
|
||||
// 根据wechatFriendId和isTimeline参数判断朋友圈类型
|
||||
if (wechatFriendId === 0) {
|
||||
if (isTimeline) {
|
||||
// 朋友圈广场
|
||||
if (isFirstPage) {
|
||||
setMomentOfSquare(result);
|
||||
} else {
|
||||
addMomentOfSquare(result);
|
||||
}
|
||||
} else {
|
||||
// 客服自己的朋友圈
|
||||
if (isFirstPage) {
|
||||
setMomentOfKf(result);
|
||||
} else {
|
||||
addMomentOfKf(result);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 指定好友的朋友圈
|
||||
if (isFirstPage) {
|
||||
setMomentOfFriend(result);
|
||||
} else {
|
||||
addMomentOfFriend(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 可以继续添加更多处理器...
|
||||
|
||||
Reference in New Issue
Block a user