Skip to content

Let's use AI to Earn!

feat: 请求器拦截添加语言

gaoSira8baef28c9bc
diff --git a/src/app/[lng]/accounts/components/AddAccountModal/AccountLogin/plats/XhsLogin.tsx b/src/app/[lng]/accounts/components/AddAccountModal/AccountLogin/plats/XhsLogin.tsx
index 6de5364a..02b4626d 100644
--- a/src/app/[lng]/accounts/components/AddAccountModal/AccountLogin/plats/XhsLogin.tsx
+++ b/src/app/[lng]/accounts/components/AddAccountModal/AccountLogin/plats/XhsLogin.tsx
@@ -26,7 +26,9 @@ const XhsLogin = memo(
const [loginLoading, setLoginLoading] = useState(false);
const sendCodeResRef = useRef<any>(null);
// 停止轮询的方法
- const stopPolling = useRef<() => void>(() => {});
+ const stopPolling = useRef<() => void>(() => {
+ console.log("2222222222")
+ });
const [getUserInfoLoding, setGetUserInfoLoding] = useState(false);
useEffect(() => {
@@ -62,9 +64,11 @@ const XhsLogin = memo(
let isStopPolling = false;
stopPolling.current = () => {
+ console.log("----------")
isStopPolling = true;
};
while (true) {
+ console.log(isStopPolling);
if (isStopPolling) break;
const res = await requestPlatApi({
url: "xhs/check_login",
@@ -87,7 +91,7 @@ const XhsLogin = memo(
loginSuccess(res.data.response_body.cookie);
break;
}
- await sleep(1500);
+ await sleep(2000);
}
};
diff --git a/src/app/layout/Providers.tsx b/src/app/layout/Providers.tsx
index cda2a165..12260e48 100644
--- a/src/app/layout/Providers.tsx
+++ b/src/app/layout/Providers.tsx
@@ -3,7 +3,7 @@
import { GoogleOAuthProvider } from "@react-oauth/google";
import { ConfigProvider, App } from "antd";
import { AntdRegistry } from "@ant-design/nextjs-registry";
-import { Suspense } from "react";
+import {Suspense, useEffect} from "react";
import type { Locale } from "antd/es/locale";
import zh_CN from "antd/es/locale/zh_CN";
import en_US from "antd/es/locale/en_US";
@@ -36,6 +36,10 @@ export function Providers({
useAccountStore.getState().accountInit();
}
+ useEffect(() => {
+ useUserStore.getState().setLang(lng);
+ }, [lng]);
+
return (
<GoogleOAuthProvider clientId="471394506793-t2g4mg90vr8qgpq5stbua0b22pofqrne.apps.googleusercontent.com">
<ConfigProvider
diff --git a/src/store/user.ts b/src/store/user.ts
index 627462d0..aa074e46 100644
--- a/src/store/user.ts
+++ b/src/store/user.ts
@@ -18,6 +18,7 @@ export interface IUserStore {
token?: string;
userInfo?: Partial<UserInfo>;
isAddAccountPorxy: boolean;
+ lang: string;
}
const state: IUserStore = {
@@ -25,6 +26,7 @@ const state: IUserStore = {
userInfo: {},
// 添加账户是否默认开启代理
isAddAccountPorxy: false,
+ lang: "",
};
export const useUserStore = createPersistStore(
@@ -33,6 +35,12 @@ export const useUserStore = createPersistStore(
},
(set, _get) => {
const methods = {
+ // 设置语言
+ setLang(lang: string) {
+ set({
+ lang,
+ });
+ },
setIsAddAccountPorxy(isAddAccountPorxy: boolean) {
set({ isAddAccountPorxy });
},
diff --git a/src/utils/general.ts b/src/utils/general.ts
index 4a2f1f9c..b8dab9a3 100644
--- a/src/utils/general.ts
+++ b/src/utils/general.ts
@@ -1,5 +1,7 @@
import { Metadata } from "next";
import { useTranslation } from "@/app/i18n";
+import { useParams } from "next/navigation";
+import { fallbackLng } from "@/app/i18n/settings";
export async function getPageTitle(name: string, lng: string) {
const { t } = await useTranslation(lng);
diff --git a/src/utils/request.ts b/src/utils/request.ts
index da0146b9..0e120467 100644
--- a/src/utils/request.ts
+++ b/src/utils/request.ts
@@ -2,7 +2,6 @@ import FetchService from "@/utils/FetchService/FetchService";
import { RequestParams } from "@/utils/FetchService/types";
import { useUserStore } from "@/store/user";
import { message } from "antd";
-import { useGetClientLng } from "@/hooks/useSystem";
type ResponseType<T> = {
code: string | number;
@@ -35,7 +34,7 @@ export async function request<T>(params: RequestParams) {
// 语言拦截
if (typeof window !== "undefined") {
- const lng = useGetClientLng();
+ const lng = useUserStore.getState().lang;
console.log(lng);
// ...
}