HomeNewArrival.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import { OpenAddToCartModalButton } from "@/components/common/AddToCartModal/OpenAddToCartModalButton";
  2. import Link from "next/link";
  3. import Image from "next/image";
  4. import type {HomeProduct,HomeSection} from "@/types/home/type"
  5. interface newArrivalSectionProps{
  6. newArrivalSection:HomeSection |undefined;
  7. }
  8. const HomeNewArrival = ({ newArrivalSection }: newArrivalSectionProps) => {
  9. const newArrival: HomeProduct[] = newArrivalSection?.products ?? [];
  10. if (!newArrival || newArrival.length === 0) return null;
  11. // 4. 真实数据按每6个拆分一组,替换原来的模拟拆分逻辑
  12. const chunkSize = 6;
  13. const productBlocks: HomeProduct[][] = [];
  14. for (let i = 0; i < newArrival.length; i += chunkSize) {
  15. productBlocks.push(newArrival.slice(i, i + chunkSize));
  16. }
  17. return (
  18. <div className="w-full mx-auto px-12 py-12">
  19. {/* 标题 */}
  20. <h2 className="text-4xl text-center font-bold leading-ly-46 mb-6">{newArrivalSection?.title}</h2>
  21. <div className="grid grid-cols-4 gap-8">
  22. {newArrival.map((product) => (
  23. <div key={product.id} className="flex min-w-0 flex-col gap-2">
  24. <Link href={`/${product.urlKey}.html`} className="relative aspect-[3/4] w-full overflow-hidden rounded-sm block">
  25. <Image
  26. src={product.image_url}
  27. alt={product.name}
  28. fill
  29. sizes="25vw"
  30. className="object-cover"
  31. />
  32. </Link>
  33. <Link
  34. href={`/${product.urlKey}.html`}
  35. className="truncate text-sm leading-ly-22 font-normal text-gray-800"
  36. >
  37. {product.name}
  38. </Link>
  39. <div className="flex items-center gap-1">
  40. <div className="flex">
  41. {[1, 2, 3, 4, 5].map((star) => (
  42. <svg
  43. key={star}
  44. className="h-4 w-4 text-green-500"
  45. fill="currentColor"
  46. viewBox="0 0 20 20"
  47. >
  48. <path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" />
  49. </svg>
  50. ))}
  51. </div>
  52. <span className="text-xs text-gray-600">
  53. {product.review_count}
  54. </span>
  55. </div>
  56. <div className="flex items-center justify-between">
  57. <div className="flex items-center gap-1">
  58. <span className="font-semibold">${product.min_price}</span>
  59. <span className="text-xs text-gray-500 line-through">
  60. ${product.price}
  61. </span>
  62. </div>
  63. <OpenAddToCartModalButton
  64. productId={product.id}
  65. icon={
  66. <svg
  67. xmlns="http://www.w3.org/2000/svg"
  68. width="32"
  69. height="32"
  70. viewBox="0 0 32 32"
  71. fill="none"
  72. >
  73. <rect
  74. x="0"
  75. y="0"
  76. width="32"
  77. height="32"
  78. rx="8"
  79. fill="#036141"
  80. ></rect>
  81. <path
  82. stroke="rgba(255, 255, 255, 1)"
  83. stroke-width="1.3333333333333333"
  84. stroke-linejoin="round"
  85. stroke-linecap="round"
  86. d="M6.40039 7.79993L8.03372 7.79993L8.73372 10.5999M8.73372 10.5999L11.0671 19.9333L23.2004 19.9333L25.5337 10.5999L8.73372 10.5999Z"
  87. ></path>
  88. <ellipse
  89. cx="11.066040515899658"
  90. cy="23.199928283691406"
  91. rx="1.4000248908996582"
  92. ry="1.4000015258789062"
  93. stroke="rgba(255, 255, 255, 1)"
  94. stroke-width="1.3333333333333333"
  95. stroke-linejoin="round"
  96. stroke-linecap="round"
  97. ></ellipse>
  98. <ellipse
  99. cx="23.1998291015625"
  100. cy="23.199928283691406"
  101. rx="1.4000244140625"
  102. ry="1.4000015258789062"
  103. stroke="rgba(255, 255, 255, 1)"
  104. stroke-width="1.3333333333333333"
  105. stroke-linejoin="round"
  106. stroke-linecap="round"
  107. ></ellipse>
  108. <path
  109. stroke="rgba(255, 255, 255, 1)"
  110. stroke-width="1.3333333333333333"
  111. stroke-linejoin="round"
  112. stroke-linecap="round"
  113. d="M15.2656 15.2665L18.999 15.2665"
  114. ></path>
  115. <path
  116. stroke="rgba(255, 255, 255, 1)"
  117. stroke-width="1.3333333333333333"
  118. stroke-linejoin="round"
  119. stroke-linecap="round"
  120. d="M17.1348 17.1332L17.1348 13.3999"
  121. ></path>
  122. </svg>
  123. }
  124. />
  125. </div>
  126. </div>
  127. ))}
  128. </div>
  129. <div className="w-[186px] h-[32px] m-auto text-center text-sm leading-ly-32 mt-12 opacity-100 rounded-[29px] bg-white border border-solid">
  130. View More
  131. </div>
  132. </div>
  133. );
  134. };
  135. export default HomeNewArrival;