移除未使用的客服列表相关代码,优化消息管理逻辑,新增消息状态管理功能,提升代码结构和可读性。
This commit is contained in:
39
Touchkebao/src/store/module/weChat/message.data.ts
Normal file
39
Touchkebao/src/store/module/weChat/message.data.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
export interface Message {
|
||||
id: number;
|
||||
wechatId: string;
|
||||
nickname: string;
|
||||
alias: string;
|
||||
avatar: string;
|
||||
region: string;
|
||||
signature: string;
|
||||
bindQQ: string;
|
||||
bindEmail: string;
|
||||
bindMobile: string;
|
||||
createTime: string;
|
||||
currentDeviceId: number;
|
||||
isDeleted: boolean;
|
||||
deleteTime: string;
|
||||
groupId: number;
|
||||
memo: string;
|
||||
wechatVersion: string;
|
||||
labels: string[];
|
||||
lastUpdateTime: string;
|
||||
isOnline?: boolean;
|
||||
momentsMax: number;
|
||||
momentsNum: number;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
//Store State
|
||||
export interface MessageState {
|
||||
//消息列表
|
||||
messageList: Message[];
|
||||
//当前选中的消息
|
||||
currentMessage: Message | null;
|
||||
//更新消息列表
|
||||
updateMessageList: (messageList: Message[]) => void;
|
||||
//更新消息状态
|
||||
updateMessageStatus: (messageId: number, status: string) => void;
|
||||
//更新当前选中的消息
|
||||
updateCurrentMessage: (message: Message) => void;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { create } from "zustand";
|
||||
import { persist } from "zustand/middleware";
|
||||
import { Message, MessageState } from "./message.data";
|
||||
export const useMessageStore = create<MessageState>()(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
messageList: [], //消息列表
|
||||
currentMessage: null, //当前选中的消息
|
||||
updateMessageList: (messageList: Message[]) => set({ messageList }), //更新消息列表
|
||||
updateCurrentMessage: (message: Message) =>
|
||||
set({ currentMessage: message }), //更新当前选中的消息
|
||||
updateMessageStatus: (messageId: number, status: string) =>
|
||||
set({
|
||||
messageList: get().messageList.map(message =>
|
||||
message.id === messageId ? { ...message, status } : message,
|
||||
),
|
||||
}), //更新消息状态
|
||||
}),
|
||||
{
|
||||
name: "message-storage",
|
||||
partialize: state => ({
|
||||
messageList: [],
|
||||
currentMessage: null,
|
||||
}),
|
||||
},
|
||||
),
|
||||
);
|
||||
/**
|
||||
* 更新当前选中的消息
|
||||
* @param message 消息
|
||||
* @returns void
|
||||
*/
|
||||
export const updateCurrentMessage = (message: Message) =>
|
||||
useMessageStore.getState().updateCurrentMessage(message);
|
||||
/**
|
||||
* 更新消息列表
|
||||
* @param messageList 消息列表
|
||||
* @returns void
|
||||
*/
|
||||
export const updateMessageList = (messageList: Message[]) =>
|
||||
useMessageStore.getState().updateMessageList(messageList);
|
||||
/**
|
||||
* 获取当前选中的消息
|
||||
* @returns Message | null
|
||||
*/
|
||||
export const getCurrentMessage = () =>
|
||||
useMessageStore.getState().currentMessage;
|
||||
|
||||
/**
|
||||
* 更新消息状态
|
||||
* @param messageId 消息ID
|
||||
* @param status 状态
|
||||
* @returns void
|
||||
*/
|
||||
export const updateMessageStatus = (messageId: number, status: string) =>
|
||||
useMessageStore.getState().updateMessageStatus(messageId, status);
|
||||
|
||||
Reference in New Issue
Block a user