zhangzf 2 дней назад
Родитель
Сommit
89c023f0b0

+ 4 - 1
src/app/(public)/product/[urlkey]/[id]/page.tsx

@@ -26,6 +26,7 @@ import Recommend from "../../_components/youmaylike/Recommend"
 import ProductText from "../../_components/ProductText";
 import { formatFlexibleVariants } from "@/utils/variantTools";
 import { ProductInforWrapper } from "../../_components/ProductInforWrapper";
+import { auth } from "@/utils/auth/auth-helper";
 
 // export const dynamic = 'auto'
 // // 'auto' | 'force-dynamic' | 'error' | 'force-static'
@@ -79,7 +80,8 @@ export default async function ProductPage({
   searchParams: Promise<{ type: string }>;
 }) {
   const { urlkey } = await params;
-
+  const session = await auth();// 游客是null
+  const isGuest = session === null;
 
   const resProductData = await getProductBaseInfo(urlkey);
 
@@ -174,6 +176,7 @@ export default async function ProductPage({
             <ProductInforWrapper 
                 productBaseInfo={product}
                 optionsVariantsPromise={productOptionsRes}
+                isGuest={isGuest}
             />
 
           <ShopServicePanel />

+ 42 - 3
src/app/(public)/product/_components/NewUserBanner.tsx

@@ -1,8 +1,47 @@
 "use client";
-
-export default function NewUserBanner() {
+import {useLoginModal} from "@/providers/LoginModalProvider";
+import { useCustomToast } from "@/utils/hooks/useToast";
+import { confirmDialog } from "@/components/theme/ui/kernel/confirm/api";
+import { useRouter } from 'next/navigation';
+export default function NewUserBanner({isGuest}:{isGuest:boolean}) {
+     const {openLoginModal} = useLoginModal();
+     const { showToast } = useCustomToast();
+     const router = useRouter();
+     if (isGuest) return null;
+     const guestUserClick = () => {
+            openLoginModal({
+                onFinalResult: async (res) => {
+                    if(res.mergeCartSuccess) { // 购物车合并成功
+                        if(!res.cartAfterMerge?.isVip && res.cartAfterMerge?.vipPlusAmount === 0) {
+                           return
+                        }
+                    } else { // 购物车合并失败
+                        // 三种 情况: 登录成功; 注册成功;
+                        if(res.loginSuccess) {
+                            // 登录成功 需要刷新页面
+                            showToast('You have logged in successfully. But something wrong','danger');
+                            await confirmDialog({
+                                title: "Warning",
+                                content: "You have logged in successfully. But something wrong. You must refresh the page.",
+                                noCancel: true,
+                            });
+                            window.location.reload();
+                        }
+                        if(res.registerSuccess && !res.loginSuccess) {
+                            // 注册成功,去登录
+                            await confirmDialog({
+                                title: "Warning",
+                                content: "You have registered successfully. But something wrong. You have to login.",
+                                noCancel: true,
+                            });
+                            router.replace('/customer/login');
+                        }
+                    }
+                }
+            });
+        };
   return (
-    <div className="w-full flex items-center justify-between mt-1 bg-[#F9F9F9] px-3 py-2 ">
+    <div onClick={guestUserClick} className="w-full flex items-center justify-between mt-1 bg-[#F9F9F9] px-3 py-2 ">
       {/* 左侧:用户头像SVG + 文案 */}
       <div className="flex items-center gap-2">
         {/* 用户头像绿色SVG */}

+ 4 - 2
src/app/(public)/product/_components/ProductInforWrapper.tsx

@@ -19,7 +19,8 @@ interface PriceInfo {
 
 export function ProductInforWrapper({
     productBaseInfo,
-    optionsVariantsPromise
+    optionsVariantsPromise,
+    isGuest
 }: {
     productBaseInfo: ProductBaseInfo; 
     optionsVariantsPromise: Promise<{
@@ -27,6 +28,7 @@ export function ProductInforWrapper({
         productOptions: ProductOption[];
         flexibleVariants: ResolvedVariant[];
     }>
+    isGuest:boolean;
 }) {
 
     const productId = productBaseInfo._id;
@@ -57,7 +59,7 @@ export function ProductInforWrapper({
         
             <InstallmentTips totalPrice={priceInfo.totalNowPrice} />
 
-            <NewUserBanner />
+            <NewUserBanner isGuest={isGuest} />
             {/* 产品Code */}
             <PromotionDiscountCardProps productId="product-1001" />
         </div>

+ 5 - 5
src/app/(public)/product/_components/review/ReviewDetail.tsx

@@ -134,7 +134,7 @@ const handleTabClick = (tab: ReviewTabType) => {
     <>
       <div className="flex flex-col flex-wrap gap-x-5 sm:gap-x-10">
         <div className="flex items-center justify-between">
-          <h3 className="text-xl font-medium">Reviews</h3>
+          <h3 className="text-xl font-medium min-w-3xs">Reviews</h3>
           <Select
             selectionMode="single"
             classNames={{
@@ -218,7 +218,7 @@ const handleTabClick = (tab: ReviewTabType) => {
               return (
                 <div
                   key={index}
-                  className={clsx("flex flex-col gap-4 py-6 px-2", {
+                  className={clsx("flex flex-col gap-4 py-6 ", {
                     "border-b border-[#E5E5E5FF]":
                       visibleReviews.length > 1 &&
                       index < visibleReviews.length - 1,
@@ -323,7 +323,7 @@ const handleTabClick = (tab: ReviewTabType) => {
                   </div>
 
                   {/* 评论正文 */}
-                  <div className="mt-3 pl-[56px]">
+                  <div className="mt-3 ">
                     <p className="font-outfit text-base font-normal text-black/80 leading-relaxed">
                       {item.comment}
                     </p>
@@ -333,12 +333,12 @@ const handleTabClick = (tab: ReviewTabType) => {
                   {isArray(item.attachments) &&
                     item.attachments &&
                     item.attachments.length > 0 && (
-                      <div className="mt-4 pl-[56px] flex gap-3 flex-wrap">
+                      <div className="mt-4  flex gap-3 flex-wrap">
                         {item.attachments.map((img: any,imgIdx:number) => (
                           <div
                             key={img.reviewId}
                             onClick={() => openGalleryModal(index, imgIdx)}
-                            className="w-[160px] h-[160px] rounded-lg overflow-hidden shrink-0 border border-[#E5E5E5FF]"
+                            className="w-[93px] h-[116px] rounded-lg overflow-hidden shrink-0 border border-[#E5E5E5FF]"
                           >
                             <GridTileImage
                               fill

+ 1 - 1
src/app/(public)/product/_components/review/ReviewImageGalleryModal.tsx

@@ -64,7 +64,7 @@ export default function ReviewImageGalleryModal({
             return (
               <SwiperSlide
                 key={idx}
-                className="flex flex-col justify-between h-full py-4"
+                className="h-full py-4"
               >
                 {/* 大图 */}
                 <div className="flex-1 flex items-center justify-center px-2">