Files
ckb-SuperAdmin/nkebao/src/contexts/WechatAccountContext.tsx
2025-07-05 15:44:07 +08:00

54 lines
1.3 KiB
TypeScript

import React, { createContext, useContext, useState, ReactNode } from 'react';
export interface WechatAccountData {
id: string;
avatar: string;
nickname: string;
status: "normal" | "abnormal";
wechatId: string;
wechatAccount: string;
deviceName: string;
deviceId: string;
}
interface WechatAccountContextType {
currentAccount: WechatAccountData | null;
setCurrentAccount: (account: WechatAccountData) => void;
clearCurrentAccount: () => void;
}
const WechatAccountContext = createContext<WechatAccountContextType>({
currentAccount: null,
setCurrentAccount: () => {},
clearCurrentAccount: () => {},
});
export const useWechatAccount = () => useContext(WechatAccountContext);
interface WechatAccountProviderProps {
children: ReactNode;
}
export function WechatAccountProvider({ children }: WechatAccountProviderProps) {
const [currentAccount, setCurrentAccountState] = useState<WechatAccountData | null>(null);
const setCurrentAccount = (account: WechatAccountData) => {
setCurrentAccountState(account);
};
const clearCurrentAccount = () => {
setCurrentAccountState(null);
};
return (
<WechatAccountContext.Provider
value={{
currentAccount,
setCurrentAccount,
clearCurrentAccount,
}}
>
{children}
</WechatAccountContext.Provider>
);
}