Explorar el Código

restApiFetch 方法修改

fogwind hace 1 semana
padre
commit
94594e4e08
Se han modificado 1 ficheros con 14 adiciones y 10 borrados
  1. 14 10
      src/utils/bagisto/index.ts

+ 14 - 10
src/utils/bagisto/index.ts

@@ -49,6 +49,7 @@ interface PageByUrlKeyResponse {
 // rest api fetch
 export async function restApiFetch<T>({
   api,
+  method,
   cache = "force-cache",
   headers,
   tags,
@@ -58,6 +59,7 @@ export async function restApiFetch<T>({
   revalidate = 60,
 }: {
   api: string;
+  method: "POST" | "GET";
   cache?: RequestCache;
   headers?: HeadersInit | Record<string, string>;
   tags?: string[];
@@ -103,21 +105,20 @@ export async function restApiFetch<T>({
       }
     }
 
-    let param = {};
-    if(variables) {
-      param = {...variables};
-    }
-
-    const result = await fetch(apiUrl, {
-      method: "POST",
+    let param: RequestInit = {
+      method: method,
       headers: baseHeaders,
-      body: JSON.stringify(param),
       cache,
       next: {
         revalidate: cache === "no-store" ? 0 : revalidate || 60,
         ...(tags && { tags }),
       },
-    });
+    };
+    if(variables) {
+      param.body = JSON.stringify({...variables});
+    }
+
+    const result = await fetch(apiUrl, param);
 
     const body = await result.json();
 
@@ -356,7 +357,9 @@ export async function logoutUser() {
         message: "User token missing",
       };
     }
-
+    /**
+     * @todo CUSTOMER_LOGOUT 接口会报错,待修复(确定是php后端接口报错)
+     */
     const res = await bagistoFetch<{
       data: { createLogout: { logout: { success: boolean; message: string } } };
       variables: { input: { token: string } };
@@ -371,6 +374,7 @@ export async function logoutUser() {
     const message =
       res?.body?.data?.createLogout?.logout?.message ?? "Logout executed";
 
+    // 下面两行代码没啥用
     const cookieStore = await cookies();
     cookieStore.delete(BAGISTO_SESSION);