Преглед изворни кода

根据pnpm build 修改代码

zhangzf пре 1 дан
родитељ
комит
b91e21e5b7

+ 10 - 9
src/app/(public)/category/[slug]/[id]/_components/ProductListing.tsx

@@ -11,7 +11,7 @@ import { newSortByFields } from "@utils/constants";
 import { isArray } from "@/utils/type-guards";
 import { useRouter, usePathname } from "next/navigation";
 import {  useApolloClient } from "@apollo/client/react";
-import { CategoryProductsResult } from "@components/catalog/type";
+import type{ CategoryProductsResult,PageInfo,CategoryProductNode,CategoryAttrFilterItem } from "@components/catalog/type";
 import {CATEGORY_PRODUCTS} from "@/graphql";
 interface QueryState {
   // search: string;
@@ -27,11 +27,11 @@ interface ProductListingProps {
   slug:string;
   categoryId: string;
 
-  filterAttributes: any[];
+  filterAttributes:Array<{ node: CategoryAttrFilterItem }>;
 
-  initialProducts: any[];
+  initialProducts: CategoryProductNode[];
 
-  initialPageInfo: any;
+  initialPageInfo: PageInfo;
 
   initialTotal: number;
 
@@ -114,9 +114,9 @@ export default function ProductListing({
         res.data?.categoryProducts?.products.map((e: any) => e.node) || [];
 
       setProducts(newProducts);
-
-      setPageInfo(res.data?.categoryProducts?.pageInfo);
-
+      if(res.data?.categoryProducts?.pageInfo){
+      setPageInfo(res.data.categoryProducts.pageInfo);
+      }
       setTotal(res.data?.categoryProducts?.totalCount || 0);
     } catch (error) {
       console.error("fetch products error", error);
@@ -212,8 +212,9 @@ export default function ProductListing({
        res.data?.categoryProducts?.products.map((e: any) => e.node) || [];
 
     setProducts((prev) => [...prev, ...moreProducts]);
-
-    setPageInfo(res.data?.categoryProducts?.pageInfo);
+     if(res.data?.categoryProducts?.pageInfo){
+      setPageInfo(res.data?.categoryProducts?.pageInfo);
+      }
   };
   return (
     <>

+ 2 - 2
src/app/(public)/category/[slug]/[id]/page.tsx

@@ -247,7 +247,7 @@ export default async function CategoryPage({
   );
 
   const products = categoryProductDatas?.categoryProducts?.products?.map((e) => e.node) || [];
-  const pageInfo = categoryProductDatas?.categoryProducts?.pageInfo;
+  const pageInfo = categoryProductDatas?.categoryProducts?.pageInfo||{endCursor:'',hasNextPage:false};
   const totalCount = categoryProductDatas?.categoryProducts?.totalCount || 0;
   const translation = categoryItem.translation;
   console.log("initialQuery------------", {
@@ -321,7 +321,7 @@ export default async function CategoryPage({
           categoryId={numericId}
           slug={_categorySlug} 
           filterAttributes={
-            filterAttributesRes.data?.categoryAttributeFilters.edges
+          filterAttributesRes.data?  filterAttributesRes.data.categoryAttributeFilters.edges:[]
           }
           initialProducts={products}
           initialPageInfo={pageInfo}

+ 4 - 0
src/components/catalog/type.ts

@@ -220,6 +220,10 @@ export type CategoryProductsResult = {
     }>;
   };
 };
+export type PageInfo = {
+  endCursor: string;
+  hasNextPage: boolean;
+};
 export interface SearchProductsVariables {
     query: string;
     suggest?: boolean;

+ 18 - 2
src/components/customer/accountSwiper.tsx

@@ -2,9 +2,25 @@
 // import { Swiper, SwiperSlide } from 'swiper/react';
 import { OpenAddToCartModalButton } from "@/components/common/AddToCartModal/OpenAddToCartModalButton";
 import Image from 'next/image';
+interface ProductItem {
+  id: number;
+  sku: string;
+  name: string;
+  slug: string | null;
+  type: string;
+  price: number;
+  min_price: number;
+  special_price: number | null;
+  image_url: string | null;
+  is_new: boolean;
+  is_featured: boolean;
+  short_description: string;
+  rating: number;
+  review_count: number;
+}
 // import 'swiper/css';
 // 模拟商品数据(和图片内容匹配)
-const productList:any = [
+const productList:ProductItem[] = [
                     {
                         "id": 3792,
                         "sku": "BW--Closure",
@@ -189,7 +205,7 @@ const AccountSwiper = () => {
                   {/* Next.Image 商品图容器 */}
                   <div className="relative w-full aspect-[3/4] overflow-hidden rounded-md">
                     <Image
-                      src={item.image_url}
+                      src={item.image_url?item.image_url:''}
                       alt={item.name}
                       fill
                       sizes="(max-width:768px) 50vw, 33vw"

+ 2 - 2
src/graphql/customer/mutations/UpdataCustomerInformation.ts

@@ -1,5 +1,5 @@
-import { gql, TypedDocumentNode } from "@apollo/client";
-import { UpdateCustomerProfileData, UpdateCustomerProfileVars } from "@/types/customer/information/information";
+import { gql, type TypedDocumentNode } from "@apollo/client";
+import type{ UpdateCustomerProfileData, UpdateCustomerProfileVars } from "@/types/customer/information/information";
 export const UPDATE_CUSTOMER_PROFILE: TypedDocumentNode<UpdateCustomerProfileData, UpdateCustomerProfileVars> = gql`
 mutation updateCustomerProfile($input: createCustomerProfileUpdateInput!) {
   createCustomerProfileUpdate(input: $input) {