Parcourir la source

fix: 请求error 释放Toast

Before il y a 7 mois
Parent
commit
919a0eb55e
3 fichiers modifiés avec 7 ajouts et 7 suppressions
  1. 1 0
      src/i18n/routing.ts
  2. 3 3
      src/utils/client/axios.ts
  3. 3 4
      src/utils/server/index.ts

+ 1 - 0
src/i18n/routing.ts

@@ -14,4 +14,5 @@ export const defaultLocale = locales.at(0) as string;
 export const routing = defineRouting({
     locales: locales,
     defaultLocale: defaultLocale,
+    localeCookie: { name: "language" },
 });

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

@@ -3,6 +3,7 @@ import { Toast } from "antd-mobile";
 import axios, { AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from "axios";
 import type { AxiosOptions } from "./type";
 
+import { defaultLocale } from "@/i18n/routing";
 import { getCookies, getToken } from "@/utils/Cookies";
 
 interface CustomRequestConfig {
@@ -44,8 +45,7 @@ export default class Request {
                     config = requestInterceptor(config);
                     // header请求头添加token
                     config.headers["Token"] = getToken() || "";
-                    config.headers["language"] =
-                        getCookies("language") || getCookies("NEXT_LOCALE");
+                    config.headers["language"] = getCookies("language") || defaultLocale;
                     if (config && config?.toast) {
                         Toast.show({
                             icon: "loading",
@@ -77,7 +77,7 @@ export default class Request {
                 if (responseInterceptorCatch) {
                     responseInterceptorCatch(error);
                 }
-                // Toast.clear();
+                Toast.clear();
             }
         );
     }

+ 3 - 4
src/utils/server/index.ts

@@ -1,4 +1,4 @@
-import { redirect } from "@/i18n/routing";
+import { defaultLocale, redirect } from "@/i18n/routing";
 import { Response } from "@/types";
 import { cookies } from "next/headers";
 import { ServerOptions } from "./type";
@@ -55,7 +55,7 @@ class Server {
         console.log(`🚀🚀🚀🚀🚀-> in index.ts on 55`, {
             Token: cookies().get("Token")?.value || "",
             "Content-Type": "application/json",
-            language: cookies().get("language")?.value || cookies().get("NEXT_LOCALE")?.value,
+            language: cookies().get("language")?.value || defaultLocale,
             url: url,
             ...headers,
         });
@@ -65,8 +65,7 @@ class Server {
                 headers: {
                     Token: cookies().get("Token")?.value || "",
                     "Content-Type": "application/json",
-                    language:
-                        cookies().get("language")?.value || cookies().get("NEXT_LOCALE")?.value,
+                    language: cookies().get("language")?.value || defaultLocale,
                     ...headers,
                 },
                 body: params,