重构状态管理:将 useWeChatStore 更名为 useDataCenterStore,并更新相关引用
This commit is contained in:
@@ -39,6 +39,7 @@ const TransmitModal: React.FC = () => {
|
|||||||
|
|
||||||
// 从 Zustand store 获取更新方法
|
// 从 Zustand store 获取更新方法
|
||||||
const openTransmitModal = useContactStore(state => state.openTransmitModal);
|
const openTransmitModal = useContactStore(state => state.openTransmitModal);
|
||||||
|
|
||||||
const setTransmitModal = useContactStore(state => state.setTransmitModal);
|
const setTransmitModal = useContactStore(state => state.setTransmitModal);
|
||||||
const updateSelectedChatRecords = useWeChatStore(
|
const updateSelectedChatRecords = useWeChatStore(
|
||||||
state => state.updateSelectedChatRecords,
|
state => state.updateSelectedChatRecords,
|
||||||
@@ -142,11 +143,11 @@ const TransmitModal: React.FC = () => {
|
|||||||
<Modal
|
<Modal
|
||||||
title="转发消息"
|
title="转发消息"
|
||||||
open={openTransmitModal}
|
open={openTransmitModal}
|
||||||
onCancel={() => updateTransmitModal(false)}
|
onCancel={() => setTransmitModal(false)}
|
||||||
width={"60%"}
|
width={"60%"}
|
||||||
className={styles.transmitModal}
|
className={styles.transmitModal}
|
||||||
footer={[
|
footer={[
|
||||||
<Button key="cancel" onClick={() => updateTransmitModal(false)}>
|
<Button key="cancel" onClick={() => setTransmitModal(false)}>
|
||||||
取消
|
取消
|
||||||
</Button>,
|
</Button>,
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import {
|
|||||||
* 微信聊天状态管理 Store
|
* 微信聊天状态管理 Store
|
||||||
* 使用 Zustand 管理微信聊天相关的状态和操作
|
* 使用 Zustand 管理微信聊天相关的状态和操作
|
||||||
*/
|
*/
|
||||||
export const useWeChatStore = create<WeChatState>()(
|
export const useDataCenterStore = create<WeChatState>()(
|
||||||
persist(
|
persist(
|
||||||
(set, get) => ({
|
(set, get) => ({
|
||||||
showChatRecordModel: false,
|
showChatRecordModel: false,
|
||||||
@@ -153,7 +153,7 @@ export const useWeChatStore = create<WeChatState>()(
|
|||||||
contract: ContractData | weChatGroup,
|
contract: ContractData | weChatGroup,
|
||||||
isExist?: boolean,
|
isExist?: boolean,
|
||||||
) => {
|
) => {
|
||||||
const state = useWeChatStore.getState();
|
const state = useDataCenterStore.getState();
|
||||||
// 切换联系人时清空当前消息,等待重新加载
|
// 切换联系人时清空当前消息,等待重新加载
|
||||||
set({ currentMessages: [], openTransmitModal: false });
|
set({ currentMessages: [], openTransmitModal: false });
|
||||||
|
|
||||||
@@ -193,7 +193,7 @@ export const useWeChatStore = create<WeChatState>()(
|
|||||||
// ==================== 消息加载方法 ====================
|
// ==================== 消息加载方法 ====================
|
||||||
/** 加载聊天消息 */
|
/** 加载聊天消息 */
|
||||||
loadChatMessages: async (Init: boolean, To?: number) => {
|
loadChatMessages: async (Init: boolean, To?: number) => {
|
||||||
const state = useWeChatStore.getState();
|
const state = useDataCenterStore.getState();
|
||||||
const contact = state.currentContract;
|
const contact = state.currentContract;
|
||||||
set({ messagesLoading: true });
|
set({ messagesLoading: true });
|
||||||
set({ isLoadingData: Init });
|
set({ isLoadingData: Init });
|
||||||
@@ -258,7 +258,7 @@ export const useWeChatStore = create<WeChatState>()(
|
|||||||
keyword: string;
|
keyword: string;
|
||||||
Count?: number;
|
Count?: number;
|
||||||
}) => {
|
}) => {
|
||||||
const state = useWeChatStore.getState();
|
const state = useDataCenterStore.getState();
|
||||||
const contact = state.currentContract;
|
const contact = state.currentContract;
|
||||||
set({ messagesLoading: true });
|
set({ messagesLoading: true });
|
||||||
|
|
||||||
@@ -302,7 +302,7 @@ export const useWeChatStore = create<WeChatState>()(
|
|||||||
// ==================== 消息接收处理 ====================
|
// ==================== 消息接收处理 ====================
|
||||||
/** 接收新消息处理 */
|
/** 接收新消息处理 */
|
||||||
receivedMsg: async message => {
|
receivedMsg: async message => {
|
||||||
const currentContract = useWeChatStore.getState().currentContract;
|
const currentContract = useDataCenterStore.getState().currentContract;
|
||||||
// 判断是群聊还是私聊
|
// 判断是群聊还是私聊
|
||||||
const getMessageId =
|
const getMessageId =
|
||||||
message?.wechatChatroomId || message.wechatFriendId;
|
message?.wechatChatroomId || message.wechatFriendId;
|
||||||
@@ -468,13 +468,16 @@ export const useWeChatStore = create<WeChatState>()(
|
|||||||
// ==================== 便捷选择器导出 ====================
|
// ==================== 便捷选择器导出 ====================
|
||||||
/** 获取当前联系人的 Hook */
|
/** 获取当前联系人的 Hook */
|
||||||
export const useCurrentContact = () =>
|
export const useCurrentContact = () =>
|
||||||
useWeChatStore(state => state.currentContract);
|
useDataCenterStore(state => state.currentContract);
|
||||||
/** 获取当前消息列表的 Hook */
|
/** 获取当前消息列表的 Hook */
|
||||||
export const useCurrentMessages = () =>
|
export const useCurrentMessages = () =>
|
||||||
useWeChatStore(state => state.currentMessages);
|
useDataCenterStore(state => state.currentMessages);
|
||||||
/** 获取消息加载状态的 Hook */
|
/** 获取消息加载状态的 Hook */
|
||||||
export const useMessagesLoading = () =>
|
export const useMessagesLoading = () =>
|
||||||
useWeChatStore(state => state.messagesLoading);
|
useDataCenterStore(state => state.messagesLoading);
|
||||||
/** 获取复选框显示状态的 Hook */
|
/** 获取复选框显示状态的 Hook */
|
||||||
export const useShowCheckbox = () =>
|
export const useShowCheckbox = () =>
|
||||||
useWeChatStore(state => state.showCheckbox);
|
useDataCenterStore(state => state.showCheckbox);
|
||||||
|
|
||||||
|
export const useUpdateTransmitModal = (open: boolean) =>
|
||||||
|
useDataCenterStore(state => state.updateTransmitModal(open));
|
||||||
|
|||||||
Reference in New Issue
Block a user