zhangzf 1 день назад
Родитель
Сommit
8823a4a2a5

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

@@ -10,7 +10,7 @@ import NewSortOrder from "@components/theme/filters/NewSortOrder";
 import { newSortByFields } from "@utils/constants";
 import { isArray } from "@/utils/type-guards";
 import { useRouter, usePathname } from "next/navigation";
-import { useMutation, useApolloClient } from "@apollo/client/react";
+import {  useApolloClient } from "@apollo/client/react";
 import { CategoryProductsResult } from "@components/catalog/type";
 import {CATEGORY_PRODUCTS} from "@/graphql";
 interface QueryState {
@@ -50,6 +50,9 @@ export default function ProductListing({
   // 新增:页面刷新初始化源头打印
   console.log("【页面刷新初始initialQuery】", initialQuery);
   console.log("【刷新初始filters(传给筛选器的源头)】", initialQuery.filters);
+  const CategoryId =categoryId;
+  console.log(CategoryId);
+  
   const [query, setQuery] = useState(initialQuery);
 
   const [products, setProducts] = useState(initialProducts);

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

@@ -4,13 +4,13 @@ import { notFound } from "next/navigation";
 // import FilterList from "@components/theme/filters/FilterList";
 // import Pagination from "@components/catalog/Pagination";
 import ProductListing from "./_components/ProductListing";
-import {
-  ProductsResponse,
+import type{
+  // ProductsResponse,
   GetCategoryAttrFiltersResult,
   CategoryProductsResult,
 } from "@components/catalog/type";
 import {
-  GET_FILTER_PRODUCTS,
+  // GET_FILTER_PRODUCTS,
   // GET_TREE_CATEGORIES,
   GET_CATEHORY_BY_ID,
   GET_CATEGORY_ATTR_FILTERS,
@@ -35,7 +35,7 @@ import {
   newBuildProductFilters,
 } from "@utils/helper";
 import { serverGraphqlFetch } from "@/utils/bagisto/index";
-import {
+import type{
   // CategoryNode,
   CategorySingleResponse,
 } from "@/types/theme/category-tree";

+ 30 - 8
src/app/(public)/customer/account/edit/page.tsx

@@ -52,7 +52,7 @@ const AccountEditPage = () => {
     }
 
     const profile = res.data.readCustomerProfile;
-
+    return profile;
       //接口数据映射到表单,reset回填
       reset({
         firstname: profile.firstName,
@@ -72,11 +72,33 @@ const AccountEditPage = () => {
         console.error("fetch products error", error);
       }
     };
-  useEffect(() => {
-   
-    fetchProducts();
-    
-  }, []);
+ useEffect(() => {
+  let mounted = true;
+
+  const loadProducts = async () => {
+    const profile = await fetchProducts();
+    // 组件已经卸载,直接放弃执行状态更新
+    if (!mounted) return;
+
+    reset({
+      firstname: profile.firstName,
+      lastname: profile.lastName,
+      email: profile.email,
+      phone: profile.phone,
+      date: profile.dateOfBirth || null,
+      current_password: "",
+      password: "",
+    });
+
+    setHasBirthDate(!!profile.dateOfBirth);
+  };
+
+  loadProducts();
+
+  return () => {
+    mounted = false;
+  };
+}, []);
   const [updateProfileMutate] = useMutation(UPDATE_CUSTOMER_PROFILE, {
   onCompleted: (res) => {
     console.log("更新结果", res);
@@ -143,7 +165,7 @@ const AccountEditPage = () => {
     register,
     handleSubmit,
     control,
-    formState: { errors },
+    formState: {  },
   } = addressForm;
   return (
     <div className="w-full h-full">
@@ -206,7 +228,7 @@ const AccountEditPage = () => {
           required: "date name is required",
         }}
       
-        render={({ field: { onChange, value } }) => (
+        render={({ field: { onChange } }) => (
             <DatePicker
               size="md"
               label="Date Of Birth"

+ 1 - 1
src/app/(public)/customer/account/mycoupon/_components/GiftCardList.tsx

@@ -79,7 +79,7 @@ const GiftCardList: React.FC = () => {
     >
       {/* 礼品卡列表 */}
       <div className="space-y-4">
-        {giftCards.map((item,index) => (
+        {giftCards.map((item) => (
           <>
             <div
               key={item.id}

+ 1 - 1
src/components/layout/navbar/MobileMenu.tsx

@@ -1,7 +1,7 @@
 "use client";
 
 import { AnimatePresence, motion } from "framer-motion";
-import Link from "next/link";
+// import Link from "next/link";
 
 // import { MobileSearchBar } from "./MobileSearch";
 import { useBodyScrollLock } from "@utils/hooks/useBodyScrollLock";

+ 1 - 1
src/components/layout/navbar/index.tsx

@@ -9,7 +9,7 @@ import { NavigationSkeleton } from "./NavigationSkeleton";
 import { ActionsSkeleton } from "./ActionsSkeleton";
 import { NavbarErrorBoundary } from "@/components/error/ErrorBoundary";
 
-import { GET_TREE_CATEGORIES,GET_TREEFRONT_MENUS } from "@/graphql";
+// import { GET_TREE_CATEGORIES,GET_TREEFRONT_MENUS } from "@/graphql";
 // import { cachedGraphQLRequest } from "@utils/hooks/useCache";
 import { serverGraphqlFetch } from "@utils/bagisto/index";
 // import { TreeCategoriesResponse } from "@/types/theme/category-tree";

+ 20 - 3
src/components/theme/filters/FilterPrice.tsx

@@ -10,7 +10,6 @@ type PriceFilterNode = {
   minPrice: string;
   maxPrice: string;
 };
-
 type PriceSelectedRange = {
   minPrice?: number;
   maxPrice?: number;
@@ -33,17 +32,20 @@ export default function PriceRangeSlider({
 }: Props) {
   const apiMin = Number(priceAttr.minPrice);
   const apiMax = Number(priceAttr.maxPrice);
+
   // 保存【基准初始值快照】用来拖拽结束对比
   const baselineRangeRef = useRef<PriceRange>({
     minPrice: apiMin,
     maxPrice: apiMax,
   });
+  // 记录上一次effect计算出来的值,避免无意义setState
+  const lastComputedRef = useRef<[number, number] | null>(null);
+
   const [sliderValue, setSliderValue] = useState<number[]>([apiMin, apiMax]);
 
   useEffect(() => {
     let startMin = apiMin;
     let startMax = apiMax;
-
     if (initialRange?.minPrice !== undefined) {
       startMin = Math.max(initialRange.minPrice, apiMin);
     }
@@ -52,10 +54,22 @@ export default function PriceRangeSlider({
     }
     // 强制约束:左滑块不能大于右滑块
     if (startMin > startMax) startMin = startMax;
+
     const newInitial: PriceRange = {
       minPrice: startMin,
       maxPrice: startMax,
     };
+
+    // 数值完全一样,跳过setState,防止无谓渲染
+    if (
+      lastComputedRef.current?.[0] === startMin &&
+      lastComputedRef.current?.[1] === startMax
+    ) {
+      baselineRangeRef.current = newInitial;
+      return;
+    }
+
+    lastComputedRef.current = [startMin, startMax];
     setSliderValue([startMin, startMax]);
     // 更新基准快照
     baselineRangeRef.current = newInitial;
@@ -80,16 +94,19 @@ export default function PriceRangeSlider({
     }
     onChangeComplete(newRange);
   };
+
   // 货币符号
   const { getCurrentCurrencyItem } = useConfig();
   const currentCurrency = getCurrentCurrencyItem();
   const currencySymbol = currentCurrency.symbol;
   const currencyCode = currentCurrency.code;
+
   return (
     <div className="py-5">
       <p className="text-base mb-4">
         Range: {currencySymbol}
-        {sliderValue[0].toFixed(2)}-${sliderValue[1].toFixed(2)}
+        {sliderValue[0].toFixed(2)} - {currencySymbol}
+        {sliderValue[1].toFixed(2)}
       </p>
       <Slider
         minValue={apiMin}