Ver código fonte

fix: 修改sharId存储

Before 10 meses atrás
pai
commit
1109d51390

+ 1 - 1
src/app/[locale]/(TabBar)/(entire)/promo/page.tsx

@@ -3,7 +3,7 @@ import Empty from "@/components/Empty";
 import { server } from "@/utils/server";
 
 import Box from "@/components/Box";
-const getPromotionApi = () => {
+const getPromotionApi = async () => {
     return server
         .request<BannerRep[]>({
             url: "/v1/api/front/activity_promotion",

+ 0 - 1
src/app/[locale]/(TabBar)/(ordinary)/gameList/[[...gameListFlag]]/page.tsx

@@ -11,7 +11,6 @@ interface Props {
 
 const GameListFlag: FC<Props> = (props) => {
     const { searchParams } = props;
-    console.log(`🚀🚀🚀🚀🚀-> in page.tsx on 10`);
 
     const [target, setTarget] = useSetState<{ games: GameListRep[]; page: Partial<Pagination> }>({
         games: [],

+ 13 - 3
src/app/[locale]/(TabBar)/(ordinary)/profile/component/ModalCom/index.tsx

@@ -2,7 +2,10 @@
 import { getLogoutApi } from "@/api/user";
 import { useRouter } from "@/i18n";
 import { useGlobalStore } from "@/stores";
+import { useSearchStore } from "@/stores/useSearchStore";
+import { useWalletStore } from "@/stores/useWalletStore";
 import { CenterPopup } from "antd-mobile";
+import Cookies from "js-cookie";
 import { useTranslations } from "next-intl";
 import { FC, PropsWithChildren, useState } from "react";
 import "./style.scss";
@@ -17,14 +20,21 @@ export interface ItemComProps {
 
 const ModalCom: FC<PropsWithChildren<ItemComProps>> = () => {
     const t = useTranslations("ProfilePage");
-    const { token, setToken, setUserInfo } = useGlobalStore();
+    const restGlobal = useGlobalStore((state) => state.reset);
+    const resetSearch = useSearchStore((state) => state.reset);
+    const restWalletStore = useWalletStore((state) => state.reset);
+
     // const { isOpen, onOpen, onClose, onOpenChange } = useDisclosure();
     const [visible, setVisible] = useState(false);
     const logoutRequest = async () => {
         let res = await getLogoutApi();
         if (res.code == 200) {
-            setUserInfo("");
-            setToken("");
+            restGlobal();
+            resetSearch();
+            restWalletStore();
+            localStorage.clear();
+            sessionStorage.clear();
+            Cookies.remove("Token");
             router.replace("/login");
         }
     };

+ 1 - 0
src/app/[locale]/(TabBar)/[[...share]]/@noticeWidget/page.tsx

@@ -16,6 +16,7 @@ const getNotices = async () => {
 };
 const NoticeWidget = async () => {
     const notices = await getNotices();
+
     if (!notices.length) return null;
     return <HomeNoticeBar notices={notices} />;
 };

+ 1 - 1
src/app/[locale]/(TabBar)/[[...share]]/_home/HomeNoticeBar.tsx

@@ -22,7 +22,7 @@ const HomeNoticeBar: FC<Props> = (props) => {
                 {notices.map((notice, index) => (
                     <Swiper.Item key={index}>
                         <Box none action={notice.action_type} actionData={notice.action_params}>
-                            {notice.content}
+                            <p dangerouslySetInnerHTML={{ __html: notice.content! }}></p>
                         </Box>
                     </Swiper.Item>
                 ))}

+ 2 - 9
src/app/[locale]/(TabBar)/[[...share]]/_home/HomeSwiper.tsx

@@ -1,9 +1,8 @@
 "use client";
-import { FC, useEffect } from "react";
+import { FC } from "react";
 
 import { BannerRep } from "@/api/home";
 import Box from "@/components/Box";
-import { usePathname } from "@/i18n";
 import { Autoplay, Pagination } from "swiper/modules";
 import { Swiper, SwiperSlide } from "swiper/react";
 interface Props {
@@ -11,13 +10,7 @@ interface Props {
 }
 const HomeSwiper: FC<Props> = (props) => {
     const { banners = [] } = props;
-    // 获取分享id
-    const pathname = usePathname();
-    useEffect(() => {
-        const [, shareId] = pathname.split("/");
-        if (!shareId) return;
-        sessionStorage.setItem("shareId", shareId);
-    }, []);
+
     return (
         <div style={{ height: "1.86rem" }} className={"home-banner"}>
             <Swiper

+ 9 - 2
src/app/[locale]/(TabBar)/[[...share]]/layout.tsx

@@ -4,8 +4,9 @@ import Footer from "@/components/Footer";
 import Header from "@/components/Header";
 import Sidebar from "@/components/Layout/Sidebar";
 import styles from "@/components/Layout/style.module.scss";
+import { usePathname } from "@/i18n";
 import { SpinLoading } from "antd-mobile";
-import { FC, PropsWithChildren, ReactNode, useRef } from "react";
+import { FC, PropsWithChildren, ReactNode, useEffect, useRef } from "react";
 import { Swiper, SwiperClass, SwiperSlide } from "swiper/react";
 type Props = {
     swiperWidget: ReactNode;
@@ -49,7 +50,13 @@ const Layout: FC<PropsWithChildren<Props>> = (props) => {
             swiperRef.current?.slidePrev();
         }
     };
-
+    // 获取分享id
+    const pathname = usePathname();
+    useEffect(() => {
+        const [, shareId] = pathname.split("/");
+        if (!shareId) return;
+        sessionStorage.setItem("shareId", shareId);
+    }, []);
     return (
         <>
             <Swiper

+ 9 - 0
src/app/[locale]/layout.tsx

@@ -6,6 +6,8 @@ import { Inter as FontSans } from "next/font/google";
 import { ReactNode } from "react";
 import "../globals.scss";
 
+import Cookies from "js-cookie";
+import { cookies } from "next/headers";
 import { Providers } from "./providers";
 
 // 加载字体
@@ -41,6 +43,13 @@ export default async function LocaleLayout({
     params: { locale: string };
 }) {
     const messages = await getMessages();
+    const luange = cookies().get("language");
+    console.log(`🚀🚀🚀🚀🚀-> in layout.tsx on 46`, luange, locale);
+
+    if (!luange) {
+        // cookies().set("language", locale);
+        Cookies.set("language", locale);
+    }
     return (
         <html lang={locale} suppressHydrationWarning>
             <body className={clsx("font-sans", fontSans.variable)}>

+ 3 - 1
src/components/Header/HeaderRight.tsx

@@ -3,12 +3,14 @@ import { Link } from "@/i18n";
 import { useGlobalStore } from "@/stores";
 import { useWalletStore } from "@/stores/useWalletStore";
 import { useRequest } from "ahooks";
+import Cookies from "js-cookie";
 import { useTranslations } from "next-intl";
 import styles from "./style.module.scss";
 
 const HeaderRight = () => {
     const t = useTranslations("Header");
-    const { token, userInfo } = useGlobalStore();
+    const { userInfo } = useGlobalStore();
+    const token = Cookies.get("Token");
     const score = useWalletStore((state) => state.score);
     const setScore = useWalletStore((state) => state.setScore);
     const getUserMoneyHandler = () => {

+ 1 - 1
src/middleware.ts

@@ -15,7 +15,7 @@ function localMiddleware() {
     return async (request: NextRequest, _next: NextFetchEvent) => {
         const handleI18nRouting = createMiddleware({
             locales: locales,
-            defaultLocale: locales[0],
+            defaultLocale: locales.at(-1)!,
         });
         return handleI18nRouting(request);
     };

+ 42 - 34
src/stores/index.ts

@@ -1,41 +1,49 @@
-import { create } from 'zustand'
-import { devtools, persist, createJSONStorage } from 'zustand/middleware';
+import { create } from "zustand";
+import { createJSONStorage, devtools, persist } from "zustand/middleware";
 
 interface State {
-  lang: string;
-  token: string;
-  userInfo: any
+    lang: string;
+    token: string;
+    userInfo: any;
 }
 
 interface Action {
-  setLang: (lang: State['lang']) => void;
-  setToken: (lang: State['token']) => void;
-  setUserInfo: (lang: State['userInfo']) => void;
+    setLang: (lang: State["lang"]) => void;
+    setToken: (lang: State["token"]) => void;
+    setUserInfo: (lang: State["userInfo"]) => void;
+    reset: () => void;
 }
-
+const initialState: State = {
+    lang: "zh",
+    token: "",
+    userInfo: "",
+};
 export const useGlobalStore = create<State & Action>()(
-  devtools(persist(
-    (set) => {
-      return {
-        lang: 'zh',
-        token: '',
-        userInfo: '',
-        setLang: (lang: State['lang']) => set({
-          lang,
-        }),
-        setToken: (token: State['token']) => set({
-          token,
-        }),
-        setUserInfo: (userInfo: State['userInfo']) => set({
-          userInfo,
-        }),
-      };
-    },
-    {
-      name: 'globalStore',
-      storage: createJSONStorage(() => localStorage),
-    }
-  ),
-    { name: 'globalStore' }
-  )
-)
+    devtools(
+        persist(
+            (set) => {
+                return {
+                    ...initialState,
+                    setLang: (lang: State["lang"]) =>
+                        set({
+                            lang,
+                        }),
+                    setToken: (token: State["token"]) =>
+                        set({
+                            token,
+                        }),
+                    setUserInfo: (userInfo: State["userInfo"]) =>
+                        set({
+                            userInfo,
+                        }),
+                    reset: () => set(initialState),
+                };
+            },
+            {
+                name: "globalStore",
+                storage: createJSONStorage(() => localStorage),
+            }
+        ),
+        { name: "globalStore" }
+    )
+);

+ 1 - 0
src/stores/useGlobalNoticeStore.ts

@@ -25,5 +25,6 @@ export const useGlobalNoticeStore = create<State & Action>()((set, get) => {
             }),
 
         hasValue: (key) => get().sourceMap.has(key),
+        reset: () => set(initialState),
     };
 });

+ 8 - 1
src/stores/useSearchStore.ts

@@ -9,14 +9,18 @@ interface Action {
     setHistory: (key: string) => void;
     removeKey: (key: string) => void;
     removeAllKey: () => void;
+    reset: () => void;
 }
 
+const initialState: State = {
+    history: [],
+};
 export const useSearchStore = create<State & Action>()(
     devtools(
         persist(
             (set) => {
                 return {
-                    history: ["for"],
+                    ...initialState,
                     setHistory: (value: string) =>
                         set((state) => {
                             const newHistory = state.history;
@@ -42,6 +46,9 @@ export const useSearchStore = create<State & Action>()(
                             history: [],
                         });
                     },
+                    reset: () => {
+                        set(initialState);
+                    },
                 };
             },
             {

+ 7 - 3
src/stores/useWalletStore.ts

@@ -9,17 +9,21 @@ interface State {
 interface Action {
     setWallet: (state: Wallet) => void;
     setScore: (state: Wallet["Score"]) => void;
+    reset: () => void;
 }
-
+const initialState: State = {
+    wallet: {},
+    score: 0,
+};
 export const useWalletStore = create<State & Action>()((set) => {
     return {
-        wallet: {},
-        score: 0,
+        ...initialState,
         setWallet: (wallet) => {
             set((state) => ({ ...state, wallet }));
         },
         setScore: (score) => {
             set((state) => ({ ...state, score }));
         },
+        reset: () => set(initialState),
     };
 });

+ 1 - 1
src/utils/client/axios.ts

@@ -45,7 +45,7 @@ export default class Request {
                     config = requestInterceptor(config);
                     // header请求头添加token
                     config.headers["Token"] = Cookies.get("Token") || "";
-                    config.headers["language"] = Cookies.get("language") || locales[0];
+                    config.headers["language"] = Cookies.get("language") || locales.at(-1);
                     if (config && config?.toast) {
                         Toast.show({
                             icon: "loading",

+ 1 - 1
src/utils/server/index.ts

@@ -54,7 +54,7 @@ class Server {
                 headers: {
                     Token: cookies().get("Token")?.value || "",
                     "Content-Type": "application/json",
-                    language: cookies().get("language")?.value || locales[0],
+                    language: cookies().get("language")?.value || locales.at(-1),
                     ...headers,
                 },
                 body: params,