|
|
@@ -11,6 +11,7 @@ import { ReviewButton } from "@components/common/button/ReviewButton";
|
|
|
import AddProductReviewForm from "../_components/review/AddProductReviewForm";
|
|
|
import type {
|
|
|
ProductReviewList,
|
|
|
+ ProductReviewNode,
|
|
|
GalleryItem,
|
|
|
} from "@/types/products/review";
|
|
|
interface ReviewQuestionTabProps {
|
|
|
@@ -73,7 +74,7 @@ export default function SwitchButton({
|
|
|
try {
|
|
|
const clientUuid = getUuId();
|
|
|
const res = await clientFetch(
|
|
|
- `/api/shop/products/${productId}/reviews?page=1&per_page=5&has_images=0&sort=all&client_id=${clientUuid}`,
|
|
|
+ `/api/shop/products/${productId}/reviews?page=1&per_page=5&has_images=1&sort=photos&client_id=${clientUuid}`,
|
|
|
{ signal }, // 绑定中断信号
|
|
|
);
|
|
|
console.log("res------------------------------ccc:", res);
|
|
|
@@ -125,12 +126,12 @@ export default function SwitchButton({
|
|
|
setActiveModalTab("all");
|
|
|
setReviewModalOpen(true);
|
|
|
}, []);
|
|
|
- const hairImages = [
|
|
|
- "https://cdn.alipearlhair.com/media/reviewimages/cache/6/image/150x/040ec09b1e35df139433887a97daa66f/reviewimages/7O_A6W92AW3D_87N5PR8CO.png",
|
|
|
- "https://cdn.alipearlhair.com/media/reviewimages/cache/6/image/150x/040ec09b1e35df139433887a97daa66f/reviewimages/7O_A6W92AW3D_87N5PR8CO.png",
|
|
|
- "https://cdn.alipearlhair.com/media/reviewimages/cache/6/image/150x/040ec09b1e35df139433887a97daa66f/reviewimages/7O_A6W92AW3D_87N5PR8CO.png",
|
|
|
- "https://cdn.alipearlhair.com/media/reviewimages/cache/6/image/150x/040ec09b1e35df139433887a97daa66f/reviewimages/7O_A6W92AW3D_87N5PR8CO.png",
|
|
|
- ];
|
|
|
+ // const hairImages = [
|
|
|
+ // "https://cdn.alipearlhair.com/media/reviewimages/cache/6/image/150x/040ec09b1e35df139433887a97daa66f/reviewimages/7O_A6W92AW3D_87N5PR8CO.png",
|
|
|
+ // "https://cdn.alipearlhair.com/media/reviewimages/cache/6/image/150x/040ec09b1e35df139433887a97daa66f/reviewimages/7O_A6W92AW3D_87N5PR8CO.png",
|
|
|
+ // "https://cdn.alipearlhair.com/media/reviewimages/cache/6/image/150x/040ec09b1e35df139433887a97daa66f/reviewimages/7O_A6W92AW3D_87N5PR8CO.png",
|
|
|
+ // "https://cdn.alipearlhair.com/media/reviewimages/cache/6/image/150x/040ec09b1e35df139433887a97daa66f/reviewimages/7O_A6W92AW3D_87N5PR8CO.png",
|
|
|
+ // ];
|
|
|
const closeModal = useCallback(() => {
|
|
|
console.log("【根】调用关闭弹窗");
|
|
|
setReviewModalOpen(false);
|
|
|
@@ -151,14 +152,14 @@ export default function SwitchButton({
|
|
|
initialSlide: number;
|
|
|
}>({ galleryList: [], initialSlide: 0 });
|
|
|
// ✅ buildGalleryList 移到父组件
|
|
|
- const buildGalleryList = useCallback((reviewList: ProductReviewList): GalleryItem[] => {
|
|
|
+ const buildGalleryList = useCallback((datareviewList: ProductReviewNode[]): GalleryItem[] => {
|
|
|
const allGallery: GalleryItem[] = [];
|
|
|
- reviewList.forEach((edge, reviewIdx) => {
|
|
|
- edge.node.attachments.forEach((imgUrl) => {
|
|
|
+ datareviewList.forEach((edge, reviewIdx) => {
|
|
|
+ edge.attachments.forEach((imgUrl) => {
|
|
|
allGallery.push({
|
|
|
reviewIndex: reviewIdx,
|
|
|
imageUrl: imgUrl,
|
|
|
- review: edge.node,
|
|
|
+ review: edge,
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
@@ -168,12 +169,12 @@ export default function SwitchButton({
|
|
|
const openGalleryModal = useCallback((
|
|
|
clickReviewIndex: number,
|
|
|
clickImgIndex: number,
|
|
|
- reviewList: ProductReviewList // 重点:传入当前点击所属的评论数组
|
|
|
+ reviewList: ProductReviewNode[] // 重点:传入当前点击所属的评论数组
|
|
|
) => {
|
|
|
const galleryAll = buildGalleryList(reviewList);
|
|
|
const targetEdge = reviewList[clickReviewIndex];
|
|
|
- const targetReview = targetEdge.node;
|
|
|
- const targetImg = targetReview.attachments[clickImgIndex];
|
|
|
+ // const targetReview = targetEdge;
|
|
|
+ const targetImg = targetEdge.attachments[clickImgIndex];
|
|
|
|
|
|
const targetSlide = galleryAll.findIndex(
|
|
|
(g) => g.reviewIndex === clickReviewIndex && g.imageUrl === targetImg
|
|
|
@@ -274,10 +275,18 @@ const openGalleryModal = useCallback((
|
|
|
<ReviewButton setShowForm={setShowForm} />
|
|
|
</div>
|
|
|
<div className="w-full relative ">
|
|
|
- <HairPhotoGallery
|
|
|
- imageList={hairImages}
|
|
|
- onOpenModal={openPhotoTabModal}
|
|
|
- />
|
|
|
+ {reviewList.map((edge) => (
|
|
|
+ <div key={edge.id}>
|
|
|
+ {/*评论文字、评分等*/}
|
|
|
+ {edge.attachments.length > 0 && (
|
|
|
+ <HairPhotoGallery
|
|
|
+ review={edge}
|
|
|
+ fullReviewList={reviewList}
|
|
|
+ onOpenModal={openGalleryModal}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
{/* <ReviewAdd productId={productId} /> */}
|
|
|
</div>
|
|
|
{open && (
|