123456789101112131415161718192021222324252627282930313233 |
- import { getLogoutApi } from "@/api/user";
- import { useRouter } from "@/i18n/routing";
- import { useSearchStore } from "@/stores/useSearchStore";
- import { useUserInfoStore } from "@/stores/useUserInfoStore";
- import { useWalletStore } from "@/stores/useWalletStore";
- import dayjs from "dayjs";
- import Cookies from "js-cookie";
- export const useLogout = () => {
- const restGlobal = useUserInfoStore((state) => state.reset);
- const resetSearch = useSearchStore((state) => state.reset);
- const restWalletStore = useWalletStore((state) => state.reset);
- const router = useRouter();
- const logout = async () => {
- let res = await getLogoutApi();
- const isClearPromotion = dayjs().isSame(sessionStorage.getItem("isClosePromotion"), "days");
- if (res.code == 200) {
- restGlobal();
- resetSearch();
- restWalletStore();
- localStorage.clear();
- Cookies.remove("Token");
- router.replace("/login");
- }
- if (!isClearPromotion) {
- sessionStorage.clear();
- }
- return Promise.resolve(res);
- };
- return {
- logout,
- };
- };
|