feat:微信详情进度保存一下
This commit is contained in:
54
nkebao/src/contexts/WechatAccountContext.tsx
Normal file
54
nkebao/src/contexts/WechatAccountContext.tsx
Normal file
@@ -0,0 +1,54 @@
|
||||
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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user