refactor(weChat): 优化朋友圈数据类型和更新逻辑

- 导出 likeListItem 和 CommentItem 接口供其他模块使用
- 重构 CommentItem 接口字段,增加注释说明
- 简化 updateLikeMoment 方法实现
- 新增 updateComment 方法用于更新评论列表
This commit is contained in:
超级老白兔
2025-09-17 17:02:27 +08:00
parent 527a76c480
commit 15a17b5e1d
2 changed files with 21 additions and 16 deletions

View File

@@ -1,17 +1,19 @@
import { ChatRecord, ContractData, weChatGroup } from "@/pages/pc/ckbox/data";
import { FriendsCircleItem } from "@/pages/pc/ckbox/weChat/components/SidebarMenu/FriendsCicle/index.data";
interface likeListItem {
export interface likeListItem {
createTime: number;
nickName: string;
wechatId: string;
}
interface CommentItem {
commentId2: string;
// 评论数据类型
export interface CommentItem {
commentArg: number;
commentId1: number;
commentId2: number;
commentTime: number;
createTime: number;
content: string;
nickName: string;
wechatId: string;
sendWord: string;
}
// 微信聊天相关的类型定义
export interface WeChatState {

View File

@@ -5,7 +5,7 @@ import {
getChatroomMessages,
getGroupMembers,
} from "@/pages/pc/ckbox/api";
import { WeChatState } from "./weChat.data";
import { WeChatState, likeListItem, CommentItem } from "./weChat.data";
import { clearUnreadCount, updateConfig } from "@/pages/pc/ckbox/api";
import { ContractData, weChatGroup } from "@/pages/pc/ckbox/data";
import { weChatGroupService, contractService } from "@/utils/db";
@@ -292,17 +292,20 @@ export const useWeChatStore = create<WeChatState>()(
updateMomentCommon: moments => {
set({ MomentCommon: moments });
},
updateLikeMoment: (snsId, likeList) => {
updateLikeMoment: (snsId: string, likeList: likeListItem[]) => {
set(state => ({
MomentCommon: state.MomentCommon.map(item => {
if (item.snsId === snsId) {
return {
...item,
likeList: likeList,
};
}
return item;
}),
MomentCommon: state.MomentCommon.map(moment =>
moment.snsId === snsId ? { ...moment, likeList } : moment,
),
}));
},
updateComment: (snsId: string, commentList: CommentItem[]) => {
set(state => ({
MomentCommon: state.MomentCommon.map(moment =>
moment.snsId === snsId ? { ...moment, commentList } : moment,
),
}));
},
}),