功能迭代
This commit is contained in:
1 parent
da4e9a57a8
commit
9df10ca806
16 files changed
+277
-29
No files matched your search
@@ -1,8 +1,10 @@
|
||||
package com.shoplix.site.controller;
|
||||
|
||||
import com.shoplix.site.facade.SiteContentFacade;
|
||||
import com.shoplix.site.modules.content.req.ContentCategoryListSiteReq;
|
||||
import com.shoplix.site.modules.content.req.ContentDetailSiteReq;
|
||||
import com.shoplix.site.modules.content.req.ContentListSiteReq;
|
||||
import com.shoplix.site.modules.content.res.ContentCategoryListSiteRes;
|
||||
import com.shoplix.site.modules.content.res.ContentDetailSiteRes;
|
||||
import com.shoplix.site.modules.content.res.ContentListSiteRes;
|
||||
import jakarta.validation.Valid;
|
||||
@@ -15,6 +17,7 @@ public class SiteContentController {
|
||||
private final SiteContentFacade facade;
|
||||
/** 注入内容 Facade。 */ public SiteContentController(SiteContentFacade facade) { this.facade = facade; }
|
||||
/** 查询已发布内容列表。 */ @PostMapping("/list") public ContentListSiteRes list(@Valid @RequestBody ContentListSiteReq req) { return facade.list(req); }
|
||||
/** 查询已发布内容分类。 */ @PostMapping("/categories/list") public ContentCategoryListSiteRes categories(@Valid @RequestBody ContentCategoryListSiteReq req) { return facade.categories(req); }
|
||||
/** 查询已发布内容详情。 */ @PostMapping("/detail") public ContentDetailSiteRes detail(@Valid @RequestBody ContentDetailSiteReq req) { return facade.detail(req); }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.shoplix.site.facade;
|
||||
|
||||
import com.shoplix.site.modules.content.req.ContentCategoryListSiteReq;
|
||||
import com.shoplix.site.modules.content.req.ContentDetailSiteReq;
|
||||
import com.shoplix.site.modules.content.req.ContentListSiteReq;
|
||||
import com.shoplix.site.modules.content.res.ContentCategoryListSiteRes;
|
||||
import com.shoplix.site.modules.content.res.ContentDetailSiteRes;
|
||||
import com.shoplix.site.modules.content.res.ContentListSiteRes;
|
||||
import com.shoplix.site.service.SiteContentService;
|
||||
@@ -13,7 +15,11 @@ public class SiteContentFacade {
|
||||
private final SiteContentService service;
|
||||
/** 注入内容业务。 */ public SiteContentFacade(SiteContentService service) { this.service = service; }
|
||||
/** 查询内容列表。 */ public ContentListSiteRes list(ContentListSiteReq req) {
|
||||
return service.list(req.contentType().name(), req.categoryCode(), req.pageNo(), req.pageSize());
|
||||
return service.list(req.contentType().name(), req.categoryCode(), req.keyword(), req.featured(),
|
||||
req.pageNo(), req.pageSize());
|
||||
}
|
||||
/** 查询内容分类。 */ public ContentCategoryListSiteRes categories(ContentCategoryListSiteReq req) {
|
||||
return service.categories(req.contentType().name());
|
||||
}
|
||||
/** 查询内容详情。 */ public ContentDetailSiteRes detail(ContentDetailSiteReq req) { return service.detail(req.contentType().name(), req.slug()); }
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class SiteProductFacade {
|
||||
private final SiteProductService service;
|
||||
/** 注入产品业务。 */ public SiteProductFacade(SiteProductService service) { this.service = service; }
|
||||
/** 查询产品列表。 */ public ProductListSiteRes list(ProductListSiteReq req) {
|
||||
return service.list(req.categoryCode(), req.pageNo(), req.pageSize());
|
||||
return service.list(req.categoryCode(), req.keyword(), req.featured(), req.pageNo(), req.pageSize());
|
||||
}
|
||||
/** 查询产品分类列表。 */ public ProductCategoryListSiteRes categories() { return service.categories(); }
|
||||
/** 查询产品详情。 */ public ProductDetailSiteRes detail(SlugDetailSiteReq req) { return service.detail(req.slug()); }
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.shoplix.site.modules.content.req;
|
||||
|
||||
import com.shoplix.modules.content.enums.ContentTypeEnum;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
/** 前台内容分类列表请求。 */
|
||||
public record ContentCategoryListSiteReq(
|
||||
/** 内容类型。 */ @NotNull ContentTypeEnum contentType) {
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import jakarta.validation.constraints.Size;
|
||||
public record ContentListSiteReq(
|
||||
/** 内容类型。 */ @NotNull ContentTypeEnum contentType,
|
||||
/** 分类业务编号,为空时查询全部分类。 */ @Size(max = 16) String categoryCode,
|
||||
/** 标题或摘要关键词。 */ @Size(max = 100) String keyword,
|
||||
/** 是否仅查询推荐内容。 */ Boolean featured,
|
||||
/** 页码,从 1 开始;为空时使用第 1 页。 */ @Min(1) Integer pageNo,
|
||||
/** 每页数量;为空时使用 12 条。 */ @Min(1) @Max(100) Integer pageSize) {
|
||||
}
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.shoplix.site.modules.content.res;
|
||||
|
||||
/** 前台内容分类列表项。 */
|
||||
public record ContentCategoryItemSiteRes(
|
||||
/** 分类业务编号。 */ String categoryCode,
|
||||
/** 父分类业务编号。 */ String parentCategoryCode,
|
||||
/** 分类英文名称。 */ String categoryName,
|
||||
/** 分类英文路径。 */ String slug,
|
||||
/** 分类英文描述。 */ String description,
|
||||
/** 排序值。 */ Integer sortNo) {
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.shoplix.site.modules.content.res;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** 前台内容分类列表响应。 */
|
||||
public record ContentCategoryListSiteRes(
|
||||
/** 已发布内容分类。 */ List<ContentCategoryItemSiteRes> items) {
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import jakarta.validation.constraints.Size;
|
||||
/** 前台站产品列表请求。 */
|
||||
public record ProductListSiteReq(
|
||||
/** 产品分类业务编号,为空时查询全部分类。 */ @Size(max = 16) String categoryCode,
|
||||
/** 产品名称、型号或摘要关键词。 */ @Size(max = 100) String keyword,
|
||||
/** 是否仅查询推荐产品。 */ Boolean featured,
|
||||
/** 页码,从 1 开始;为空时使用第 1 页。 */ @Min(1) Integer pageNo,
|
||||
/** 每页数量;为空时使用 12 条。 */ @Min(1) @Max(100) Integer pageSize) {
|
||||
}
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.shoplix.site.modules.product.res;
|
||||
|
||||
/** 前台产品详情分类面包屑。 */
|
||||
public record ProductCategoryBreadcrumbSiteRes(
|
||||
/** 分类业务编号。 */ String categoryCode,
|
||||
/** 分类英文名称。 */ String categoryName,
|
||||
/** 分类英文路径。 */ String slug) {
|
||||
}
|
||||
@@ -11,6 +11,7 @@ public record ProductDetailSiteRes(
|
||||
/** 主分类业务编号。 */ String primaryCategoryCode,
|
||||
/** 主分类英文名称。 */ String primaryCategoryName,
|
||||
/** 主分类英文路径。 */ String primaryCategorySlug,
|
||||
/** 从顶级分类到主分类的面包屑。 */ List<ProductCategoryBreadcrumbSiteRes> categoryBreadcrumbs,
|
||||
/** 产品摘要。 */ String summary,
|
||||
/** 产品详情内容。 */ String content,
|
||||
/** 封面媒体业务编号。 */ String coverMediaCode,
|
||||
|
||||
@@ -3,25 +3,37 @@ package com.shoplix.site.service;
|
||||
import com.shoplix.common.context.SiteContextHolder;
|
||||
import com.shoplix.common.exception.BusinessException;
|
||||
import com.shoplix.modules.content.repository.entity.ContentEntity;
|
||||
import com.shoplix.modules.content.repository.service.ContentCategoryRepositoryService;
|
||||
import com.shoplix.modules.content.repository.service.ContentRepositoryService;
|
||||
import com.shoplix.modules.media.repository.service.MediaAssetRepositoryService;
|
||||
import com.shoplix.site.modules.content.res.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/** 前台站已发布新闻、案例和帮助业务。 */
|
||||
@Service
|
||||
public class SiteContentService {
|
||||
private final ContentRepositoryService repository;
|
||||
/** 内容分类仓储服务。 */
|
||||
private final ContentCategoryRepositoryService categoryRepository;
|
||||
private final MediaAssetRepositoryService mediaRepository;
|
||||
/** 注入内容数据源。 */ public SiteContentService(ContentRepositoryService repository,
|
||||
ContentCategoryRepositoryService categoryRepository,
|
||||
MediaAssetRepositoryService mediaRepository) {
|
||||
this.repository = repository; this.mediaRepository = mediaRepository;
|
||||
this.repository = repository; this.categoryRepository = categoryRepository; this.mediaRepository = mediaRepository;
|
||||
}
|
||||
/** 查询当前站点指定类型已发布内容。 */
|
||||
public ContentListSiteRes list(String type, String categoryCode, Integer requestedPageNo, Integer requestedPageSize) {
|
||||
List<ContentEntity> contents = repository.listPublished(SiteContextHolder.getRequired().siteCode(), type, categoryCode);
|
||||
public ContentListSiteRes list(String type, String categoryCode, String keyword, Boolean featured,
|
||||
Integer requestedPageNo, Integer requestedPageSize) {
|
||||
String normalizedKeyword = keyword == null ? "" : keyword.trim().toLowerCase(Locale.ROOT);
|
||||
List<ContentEntity> contents = repository.listPublished(
|
||||
SiteContextHolder.getRequired().siteCode(), type, categoryCode).stream()
|
||||
.filter(item -> !Boolean.TRUE.equals(featured) || Integer.valueOf(1).equals(item.getFeaturedFlag()))
|
||||
.filter(item -> normalizedKeyword.isEmpty() || contains(item.getTitle(), normalizedKeyword)
|
||||
|| contains(item.getSummary(), normalizedKeyword))
|
||||
.toList();
|
||||
int pageNo = requestedPageNo == null ? 1 : requestedPageNo;
|
||||
int pageSize = requestedPageSize == null ? 12 : requestedPageSize;
|
||||
int totalPages = contents.isEmpty() ? 0 : (contents.size() + pageSize - 1) / pageSize;
|
||||
@@ -32,6 +44,19 @@ public class SiteContentService {
|
||||
item.getSummary(), item.getCoverMediaCode(), resolveMediaUrl(item), item.getPublishTime())).toList();
|
||||
return new ContentListSiteRes(items, contents.size(), pageNo, pageSize, totalPages);
|
||||
}
|
||||
/** 判断候选文本是否包含已标准化关键词。 */
|
||||
private boolean contains(String value, String normalizedKeyword) {
|
||||
return value != null && value.toLowerCase(Locale.ROOT).contains(normalizedKeyword);
|
||||
}
|
||||
/** 查询当前站点指定类型的已发布内容分类。 */
|
||||
public ContentCategoryListSiteRes categories(String type) {
|
||||
List<ContentCategoryItemSiteRes> items = categoryRepository.list(
|
||||
SiteContextHolder.getRequired().siteCode(), type, true).stream()
|
||||
.map(item -> new ContentCategoryItemSiteRes(item.getCategoryCode(), item.getParentCategoryCode(),
|
||||
item.getCategoryName(), item.getSlug(), item.getDescription(), item.getSortNo()))
|
||||
.toList();
|
||||
return new ContentCategoryListSiteRes(items);
|
||||
}
|
||||
/** 查询当前站点指定类型内容详情。 */
|
||||
public ContentDetailSiteRes detail(String type, String slug) {
|
||||
ContentEntity item = repository.findPublishedBySlug(SiteContextHolder.getRequired().siteCode(), type, slug)
|
||||
|
||||
@@ -17,6 +17,9 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
/** 前台站已发布产品业务。 */
|
||||
@@ -46,11 +49,18 @@ public class SiteProductService {
|
||||
this.templateRepository = templateRepository;
|
||||
}
|
||||
/** 查询当前站点已发布产品。 */
|
||||
public ProductListSiteRes list(String categoryCode, Integer requestedPageNo, Integer requestedPageSize) {
|
||||
public ProductListSiteRes list(String categoryCode, String keyword, Boolean featured,
|
||||
Integer requestedPageNo, Integer requestedPageSize) {
|
||||
String siteCode = SiteContextHolder.getRequired().siteCode();
|
||||
List<ProductEntity> products = categoryCode == null || categoryCode.isBlank()
|
||||
List<ProductEntity> source = categoryCode == null || categoryCode.isBlank()
|
||||
? repository.listPublished(siteCode, null)
|
||||
: repository.listPublishedByCategories(siteCode, resolveCategoryCodes(siteCode, categoryCode));
|
||||
String normalizedKeyword = keyword == null ? "" : keyword.trim().toLowerCase(Locale.ROOT);
|
||||
List<ProductEntity> products = source.stream()
|
||||
.filter(item -> !Boolean.TRUE.equals(featured) || Integer.valueOf(1).equals(item.getFeaturedFlag()))
|
||||
.filter(item -> normalizedKeyword.isEmpty() || contains(item.getProductName(), normalizedKeyword)
|
||||
|| contains(item.getModel(), normalizedKeyword) || contains(item.getSummary(), normalizedKeyword))
|
||||
.toList();
|
||||
int pageNo = requestedPageNo == null ? 1 : requestedPageNo;
|
||||
int pageSize = requestedPageSize == null ? 12 : requestedPageSize;
|
||||
int totalPages = products.isEmpty() ? 0 : (products.size() + pageSize - 1) / pageSize;
|
||||
@@ -63,6 +73,11 @@ public class SiteProductService {
|
||||
return new ProductListSiteRes(items, products.size(), pageNo, pageSize, totalPages);
|
||||
}
|
||||
|
||||
/** 判断候选文本是否包含已标准化关键词。 */
|
||||
private boolean contains(String value, String normalizedKeyword) {
|
||||
return value != null && value.toLowerCase(Locale.ROOT).contains(normalizedKeyword);
|
||||
}
|
||||
|
||||
/** 查询当前站点已发布产品分类。 */
|
||||
public ProductCategoryListSiteRes categories() {
|
||||
String siteCode = SiteContextHolder.getRequired().siteCode();
|
||||
@@ -121,11 +136,29 @@ public class SiteProductService {
|
||||
: categoryRepository.findByCode(siteCode, item.getPrimaryCategoryCode()).orElse(null);
|
||||
return new ProductDetailSiteRes(item.getProductCode(), item.getProductName(), item.getSlug(), item.getModel(),
|
||||
item.getPrimaryCategoryCode(), primaryCategory == null ? null : primaryCategory.getCategoryName(),
|
||||
primaryCategory == null ? null : primaryCategory.getSlug(), item.getSummary(), resolveProductContent(item),
|
||||
primaryCategory == null ? null : primaryCategory.getSlug(), categoryBreadcrumbs(siteCode, primaryCategory),
|
||||
item.getSummary(), resolveProductContent(item),
|
||||
item.getCoverMediaCode(), mediaUrl, images,
|
||||
item.getInquiryEnabled() == 1, attributes, specifications);
|
||||
}
|
||||
|
||||
/** 构建从顶级分类到产品主分类的完整面包屑。 */
|
||||
private List<ProductCategoryBreadcrumbSiteRes> categoryBreadcrumbs(
|
||||
String siteCode, com.shoplix.modules.product.repository.entity.ProductCategoryEntity primaryCategory) {
|
||||
if (primaryCategory == null) return List.of();
|
||||
List<ProductCategoryBreadcrumbSiteRes> breadcrumbs = new ArrayList<>();
|
||||
var current = primaryCategory;
|
||||
while (current != null) {
|
||||
breadcrumbs.add(new ProductCategoryBreadcrumbSiteRes(
|
||||
current.getCategoryCode(), current.getCategoryName(), current.getSlug()));
|
||||
String parentCode = current.getParentCategoryCode();
|
||||
current = parentCode == null || parentCode.isBlank()
|
||||
? null : categoryRepository.findByCode(siteCode, parentCode).orElse(null);
|
||||
}
|
||||
Collections.reverse(breadcrumbs);
|
||||
return List.copyOf(breadcrumbs);
|
||||
}
|
||||
|
||||
/** 按产品配置将已发布公共模板动态拼接到独立详情前后。 */
|
||||
private String resolveProductContent(ProductEntity product) {
|
||||
String productContent = product.getProductContent() == null ? "" : product.getProductContent();
|
||||
|
||||
@@ -24,12 +24,13 @@ class SiteContentFacadeTest {
|
||||
@Test
|
||||
void passesCategoryCodeToContentService() {
|
||||
ContentListSiteRes expected = new ContentListSiteRes(List.of(), 0, 1, 12, 0);
|
||||
when(service.list("NEWS", "CCT0000000000001", 1, 12)).thenReturn(expected);
|
||||
when(service.list("NEWS", "CCT0000000000001", null, null, 1, 12)).thenReturn(expected);
|
||||
SiteContentFacade facade = new SiteContentFacade(service);
|
||||
|
||||
ContentListSiteRes actual = facade.list(new ContentListSiteReq(ContentTypeEnum.NEWS, "CCT0000000000001", 1, 12));
|
||||
ContentListSiteRes actual = facade.list(new ContentListSiteReq(
|
||||
ContentTypeEnum.NEWS, "CCT0000000000001", null, null, 1, 12));
|
||||
|
||||
assertSame(expected, actual);
|
||||
verify(service).list("NEWS", "CCT0000000000001", 1, 12);
|
||||
verify(service).list("NEWS", "CCT0000000000001", null, null, 1, 12);
|
||||
}
|
||||
}
|
||||
@@ -72,13 +72,37 @@ class SiteProductServiceTest {
|
||||
when(productRepository.listPublished(SITE_CODE, null)).thenReturn(List.of(product));
|
||||
when(mediaRepository.find(SITE_CODE, "MED001")).thenReturn(Optional.of(media));
|
||||
|
||||
var response = service.list(null, 1, 12);
|
||||
var response = service.list(null, null, null, 1, 12);
|
||||
|
||||
assertThat(response.items()).singleElement()
|
||||
.extracting(item -> item.coverMediaUrl())
|
||||
.isEqualTo("https://oss.steliro.com/shoplix-test/media/trimmer-head.png");
|
||||
}
|
||||
|
||||
/** 推荐产品查询应同时应用推荐标识和关键词条件。 */
|
||||
@Test
|
||||
void shouldFilterFeaturedProductsByKeyword() {
|
||||
ProductEntity matched = new ProductEntity();
|
||||
matched.setProductCode("PRD001");
|
||||
matched.setProductName("Nylon Brush Wheel Kit");
|
||||
matched.setSlug("nylon-brush-wheel-kit");
|
||||
matched.setFeaturedFlag(1);
|
||||
matched.setInquiryEnabled(1);
|
||||
ProductEntity notFeatured = new ProductEntity();
|
||||
notFeatured.setProductCode("PRD002");
|
||||
notFeatured.setProductName("Nylon Brush Wheel");
|
||||
notFeatured.setSlug("nylon-brush-wheel");
|
||||
notFeatured.setFeaturedFlag(0);
|
||||
notFeatured.setInquiryEnabled(1);
|
||||
when(productRepository.listPublished(SITE_CODE, null)).thenReturn(List.of(matched, notFeatured));
|
||||
|
||||
var response = service.list(null, "wheel kit", true, 1, 12);
|
||||
|
||||
assertThat(response.items()).singleElement()
|
||||
.extracting(item -> item.productCode())
|
||||
.isEqualTo("PRD001");
|
||||
}
|
||||
|
||||
/** 选择父分类时应查询该分类及全部已发布后代分类的产品。 */
|
||||
@Test
|
||||
void shouldIncludeAllDescendantCategoriesWhenListingProducts() {
|
||||
@@ -91,7 +115,7 @@ class SiteProductServiceTest {
|
||||
argThat(codes -> codes.containsAll(List.of("CAT001", "CAT002", "CAT003")))))
|
||||
.thenReturn(List.of());
|
||||
|
||||
service.list("CAT001", 1, 12);
|
||||
service.list("CAT001", null, null, 1, 12);
|
||||
|
||||
org.mockito.Mockito.verify(productRepository).listPublishedByCategories(
|
||||
org.mockito.ArgumentMatchers.eq(SITE_CODE),
|
||||
|
||||
+91
-16
@@ -191,6 +191,7 @@ const nav = [
|
||||
type NavigationItem = { title: string; url: string; openType: "CURRENT" | "NEW"; children: NavigationItem[] };
|
||||
type ProductCategory = { categoryCode: string; parentCategoryCode?: string; categoryName: string; slug: string; sortNo: number };
|
||||
type ProductCategoryNode = ProductCategory & { children: ProductCategoryNode[] };
|
||||
type ContentCategory = { categoryCode: string; parentCategoryCode?: string; categoryName: string; slug: string; description?: string; sortNo: number };
|
||||
|
||||
/** 读取已发布导航,没有配置时返回既有默认菜单。 */
|
||||
function useNavigation(position: "HEADER" | "FOOTER"): NavigationItem[] {
|
||||
@@ -227,6 +228,20 @@ function useProductCategoryTree(): ProductCategoryNode[] {
|
||||
return build("");
|
||||
}
|
||||
|
||||
/** 读取新闻、案例或帮助的已发布分类。 */
|
||||
function useContentCategories(contentType?: ContentType): ContentCategory[] {
|
||||
const [categories, setCategories] = useState<ContentCategory[]>([]);
|
||||
useEffect(() => {
|
||||
if (!contentType) { setCategories([]); return; }
|
||||
let active = true;
|
||||
post("/contents/categories/list", { contentType })
|
||||
.then((data) => { if (active) setCategories(data.items || []); })
|
||||
.catch(() => { if (active) setCategories([]); });
|
||||
return () => { active = false; };
|
||||
}, [contentType]);
|
||||
return categories;
|
||||
}
|
||||
|
||||
/** 读取当前站点已启用的社媒渠道配置。 */
|
||||
function useSocialChannels(): SocialChannel[] {
|
||||
const [channels, setChannels] = useState<SocialChannel[]>([]);
|
||||
@@ -254,6 +269,12 @@ function productCategoryNavigation(categories: ProductCategoryNode[]): Navigatio
|
||||
function NavigationLinks({ items }: { items: NavigationItem[] }) {
|
||||
return <>{items.map((item) => <div className="site-nav-item" key={`${item.title}-${item.url}`}><a href={item.url} target={item.openType === "NEW" ? "_blank" : undefined} rel={item.openType === "NEW" ? "noreferrer" : undefined}>{item.title}</a>{item.children?.length > 0 && <div className="site-subnav"><NavigationLinks items={item.children}/></div>}</div>)}</>;
|
||||
}
|
||||
/** 已合并产品的历史英文路径,前台统一跳转到新的产品族页面。 */
|
||||
const PRODUCT_SLUG_REDIRECTS: Record<string, string> = {
|
||||
"hy-047-nylon-brush-wheel-with-8-piece-adapter-kit": "nylon-brush-wheel-kit",
|
||||
"hy-048-nylon-brush-wheel-with-4-piece-fixing-kit": "nylon-brush-wheel-kit",
|
||||
"hy-049-nylon-brush-wheel-with-stihl-style-4-piece-kit": "nylon-brush-wheel-kit",
|
||||
};
|
||||
function route() {
|
||||
const p = location.pathname.split("/").filter(Boolean);
|
||||
const parameters = new URLSearchParams(location.search);
|
||||
@@ -268,6 +289,11 @@ function route() {
|
||||
}
|
||||
function App() {
|
||||
const r = route();
|
||||
useEffect(() => {
|
||||
if (r.kind !== "products" || !r.slug) return;
|
||||
const redirectedSlug = PRODUCT_SLUG_REDIRECTS[r.slug];
|
||||
if (redirectedSlug) location.replace(`/products/${redirectedSlug}`);
|
||||
}, [r.kind, r.slug]);
|
||||
useEffect(() => {
|
||||
initializeAnalytics();
|
||||
const context = { pageCode: routePageCode(), pageName: document.title, scene: r.kind };
|
||||
@@ -376,9 +402,9 @@ function LiveHeader({ section, style }: { section: DecorationSection; style: Rea
|
||||
}
|
||||
function LiveCollection({section}:{section:DecorationSection}) {
|
||||
const [items,setItems]=useState<Item[]>([]);
|
||||
useEffect(()=>{const path=section.type==="PRODUCTS"?"/products/list":"/contents/list";const body=section.type==="PRODUCTS"?{pageNo:1,pageSize:section.limit||3}:{contentType:section.sourceType||"CASE",pageNo:1,pageSize:section.limit||3};post(path,body).then(data=>setItems(data.items||[])).catch(()=>setItems([]))},[section.type,section.sourceType,section.limit]);
|
||||
useEffect(()=>{const path=section.type==="PRODUCTS"?"/products/list":"/contents/list";const body=section.type==="PRODUCTS"?{featured:true,pageNo:1,pageSize:section.limit||3}:{contentType:section.sourceType||"CASE",featured:true,pageNo:1,pageSize:section.limit||3};post(path,body).then(data=>setItems(data.items||[])).catch(()=>setItems([]))},[section.type,section.sourceType,section.limit]);
|
||||
const base=section.type==="PRODUCTS"?"products":(section.sourceType||"CASE").toLowerCase();
|
||||
return <section className="live-collection" style={{background:section.background,color:section.textColor}}><p>FEATURED</p><h2>{section.title}</h2><div>{items.map(item=><a href={`/${base}/${item.slug}`} key={item.productCode||item.contentCode}><div>{item.coverMediaUrl&&<img src={assetUrl(item.coverMediaUrl)} alt={item.productName||item.title}/>}</div><span>{section.type==="PRODUCTS"?"PRODUCT":section.sourceType}</span><h3>{item.productName||item.title}</h3><p>{item.summary}</p></a>)}</div></section>;
|
||||
return <section className="live-collection" style={{background:section.background,color:section.textColor}}><p>FEATURED</p><h2>{section.title}</h2><div>{items.map(item=><a href={`/${base}/${item.slug}`} key={item.productCode||item.contentCode}><div>{item.coverMediaUrl&&<img src={assetUrl(item.coverMediaUrl)} alt={item.productName||item.title} loading="lazy"/>}</div><span>{section.type==="PRODUCTS"?"PRODUCT":section.sourceType}</span><h3>{item.productName||item.title}</h3><p>{item.summary}</p></a>)}</div></section>;
|
||||
}
|
||||
function Header() {
|
||||
const items = useNavigation("HEADER");
|
||||
@@ -398,8 +424,8 @@ function Header() {
|
||||
return (
|
||||
<header className="site-header">
|
||||
<a className="logo" href="/">
|
||||
<b>SHOPLIX</b>
|
||||
<span>Industrial Solutions</span>
|
||||
<b>HONGYU</b>
|
||||
<span>Trimmer Head Sourcing</span>
|
||||
</a>
|
||||
<nav>
|
||||
<NavigationLinks items={navigationItems}/>
|
||||
@@ -492,8 +518,8 @@ function Collection({
|
||||
slug?: string;
|
||||
categoryCode?: string;
|
||||
}) {
|
||||
const navigation = useNavigation("HEADER");
|
||||
const productCategories = useProductCategoryTree();
|
||||
const contentCategories = useContentCategories(type === "products" ? undefined : type);
|
||||
const [data, setData] = useState<Item[] | Record<string, unknown>>([]);
|
||||
const [error, setError] = useState("");
|
||||
const [pageNo, setPageNo] = useState(() => Math.max(1, Number(new URLSearchParams(location.search).get("page")) || 1));
|
||||
@@ -556,7 +582,6 @@ function Collection({
|
||||
);
|
||||
}
|
||||
const basePath = type === "products" ? "/products" : `/${type.toLowerCase()}`;
|
||||
const categoryItems = navigation.find((item) => item.url.split("?")[0] === basePath)?.children || [];
|
||||
return (
|
||||
<section className="listing">
|
||||
<Crumbs current={title} />
|
||||
@@ -576,10 +601,7 @@ function Collection({
|
||||
<a className={!categoryCode ? "active" : ""} href={basePath}>All {title}</a>
|
||||
{type === "products"
|
||||
? <ProductCategoryLinks items={productCategories} selectedCategoryCode={categoryCode}/>
|
||||
: categoryItems.map((item) => {
|
||||
const itemCategory = new URL(item.url, location.origin).searchParams.get("category");
|
||||
return <a className={itemCategory === categoryCode ? "active" : ""} href={item.url} key={`${item.title}-${item.url}`}>{item.title}<ChevronRight size={15}/></a>;
|
||||
})}
|
||||
: contentCategories.map((item) => <a className={item.categoryCode === categoryCode ? "active" : ""} href={`${basePath}?category=${encodeURIComponent(item.categoryCode)}`} key={item.categoryCode}>{item.categoryName}<ChevronRight size={15}/></a>)}
|
||||
</aside>
|
||||
<div className="cards">
|
||||
{(data as Item[]).map((item) => (
|
||||
@@ -593,6 +615,7 @@ function Collection({
|
||||
<img
|
||||
src={assetUrl(item.coverMediaUrl)}
|
||||
alt={item.productName || item.title}
|
||||
loading="lazy"
|
||||
/>
|
||||
)}
|
||||
<span>{type === "products" ? "PRODUCT" : type}</span>
|
||||
@@ -642,8 +665,8 @@ function SearchResults({ query }: { query: string }) {
|
||||
if (!keyword) { setResults([]); setLoading(false); return; }
|
||||
setLoading(true);
|
||||
Promise.all([
|
||||
post("/products/list", { pageNo: 1, pageSize: 100 }).then((data) => ({ items: data.items || [], base: "products", label: "Product" })),
|
||||
...(["NEWS", "CASE", "HELP"] as ContentType[]).map((contentType) => post("/contents/list", { contentType, pageNo: 1, pageSize: 100 }).then((data) => ({ items: data.items || [], base: contentType.toLowerCase(), label: contentType === "CASE" ? "Case" : contentType.charAt(0) + contentType.slice(1).toLowerCase() }))),
|
||||
post("/products/list", { keyword: query.trim(), pageNo: 1, pageSize: 100 }).then((data) => ({ items: data.items || [], base: "products", label: "Product" })),
|
||||
...(["NEWS", "CASE", "HELP"] as ContentType[]).map((contentType) => post("/contents/list", { contentType, keyword: query.trim(), pageNo: 1, pageSize: 100 }).then((data) => ({ items: data.items || [], base: contentType.toLowerCase(), label: contentType === "CASE" ? "Case" : contentType.charAt(0) + contentType.slice(1).toLowerCase() }))),
|
||||
]).then((groups) => {
|
||||
const matched = groups.flatMap((group) => group.items.map((item: Item) => ({ item, base: group.base, label: group.label })))
|
||||
.filter(({ item }) => [item.productName, item.title, item.summary, item.model].some((value) => value?.toLowerCase().includes(keyword)));
|
||||
@@ -674,12 +697,54 @@ function ProductDetailView({ data: d, configuration }: { data: Record<string, an
|
||||
const attributes = (d.attributes || []).slice(0, configuration?.productInformationLimit || d.attributes?.length || 0);
|
||||
const showProductInformation = configuration?.showProductInformation !== false && attributes.length > 0;
|
||||
const specifications = d.specifications || [];
|
||||
const optionSpecifications = specifications.filter((specification: any) =>
|
||||
/option|model|color|kit/i.test(`${specification.groupName || ""} ${specification.name || ""}`),
|
||||
);
|
||||
const selectAdjacentImage = (direction: number) => {
|
||||
if (productImages.length < 2) return;
|
||||
setSelectedImage((current) => (current + direction + productImages.length) % productImages.length);
|
||||
};
|
||||
useEffect(() => setSelectedImage(0), [d.productCode]);
|
||||
useEffect(() => setActiveProductTab("DETAILS"), [d.productCode]);
|
||||
useEffect(() => {
|
||||
const breadcrumbs = [
|
||||
{ name: "Products", item: `${location.origin}/products` },
|
||||
...(d.categoryBreadcrumbs || []).map((category: any) => ({
|
||||
name: category.categoryName,
|
||||
item: `${location.origin}/products?category=${encodeURIComponent(category.categoryCode)}`,
|
||||
})),
|
||||
{ name: d.productName, item: location.href },
|
||||
];
|
||||
const structuredData = JSON.stringify({
|
||||
"@context": "https://schema.org",
|
||||
"@graph": [
|
||||
{
|
||||
"@type": "Product",
|
||||
name: d.productName,
|
||||
description: d.summary,
|
||||
image: productImages.map((image: any) => new URL(assetUrl(image.url), location.origin).href),
|
||||
model: d.model,
|
||||
brand: { "@type": "Brand", name: "Hongyu" },
|
||||
manufacturer: { "@type": "Organization", name: "Yongkang Hongyu Industry and Trade Co., Ltd." },
|
||||
},
|
||||
{
|
||||
"@type": "BreadcrumbList",
|
||||
itemListElement: breadcrumbs.map((breadcrumb, index) => ({
|
||||
"@type": "ListItem", position: index + 1, name: breadcrumb.name, item: breadcrumb.item,
|
||||
})),
|
||||
},
|
||||
],
|
||||
});
|
||||
applySeo({
|
||||
title: `${d.productName} | Hongyu`,
|
||||
description: d.summary,
|
||||
canonicalUrl: `/products/${d.slug}`,
|
||||
ogTitle: d.productName,
|
||||
ogDescription: d.summary,
|
||||
ogImageUrl: productImages[0]?.url ? assetUrl(productImages[0].url) : undefined,
|
||||
structuredData,
|
||||
});
|
||||
}, [d.productCode]);
|
||||
useEffect(() => {
|
||||
if (!inquiryOpen) return;
|
||||
const closeOnEscape = (event: KeyboardEvent) => {
|
||||
@@ -695,7 +760,12 @@ function ProductDetailView({ data: d, configuration }: { data: Record<string, an
|
||||
return <article className="detail product-detail">
|
||||
<Crumbs current={String(d.productName || "Product")} parents={[
|
||||
{ label: "Products", url: "/products" },
|
||||
...(d.primaryCategoryCode && d.primaryCategoryName
|
||||
...((d.categoryBreadcrumbs || []).length > 0
|
||||
? d.categoryBreadcrumbs.map((category: any) => ({
|
||||
label: String(category.categoryName),
|
||||
url: `/products?category=${encodeURIComponent(String(category.categoryCode))}`,
|
||||
}))
|
||||
: d.primaryCategoryCode && d.primaryCategoryName
|
||||
? [{ label: String(d.primaryCategoryName), url: `/products?category=${encodeURIComponent(String(d.primaryCategoryCode))}` }]
|
||||
: []),
|
||||
]}/>
|
||||
@@ -706,12 +776,17 @@ function ProductDetailView({ data: d, configuration }: { data: Record<string, an
|
||||
? <img src={assetUrl(productImages[selectedImage].url)} alt={`${d.productName || "Product"} ${selectedImage + 1}`}/>
|
||||
: <div className="product-image-placeholder"><ImageIcon size={48}/><span>Product image coming soon</span></div>}
|
||||
</div>
|
||||
{productImages.length>1&&<div className="product-thumbnails">{productImages.map((image:any,index:number)=><button type="button" className={`product-thumbnail${index===selectedImage?' active':''}`} key={image.mediaCode||index} onClick={()=>setSelectedImage(index)}><img src={assetUrl(image.url)} alt={`${d.productName || "Product"} thumbnail ${index+1}`}/></button>)}</div>}
|
||||
{productImages.length>1&&<div className="product-thumbnails">{productImages.map((image:any,index:number)=><button type="button" className={`product-thumbnail${index===selectedImage?' active':''}`} key={image.mediaCode||index} onClick={()=>setSelectedImage(index)}><img src={assetUrl(image.url)} alt={`${d.productName || "Product"} thumbnail ${index+1}`} loading="lazy"/></button>)}</div>}
|
||||
</div>
|
||||
<div className="product-summary">
|
||||
<p className="eyebrow">PRODUCT</p>
|
||||
<h1>{d.productName}</h1>
|
||||
<p className="lead">{d.summary}</p>
|
||||
{optionSpecifications.length > 0 && <section className="product-options" aria-label="Available product options">
|
||||
<h2>Available options</h2>
|
||||
<div>{optionSpecifications.map((option: any, index: number) => <span key={`${option.name}-${index}`}><b>{option.name}</b>{option.value}</span>)}</div>
|
||||
<small>Specify the required option in your inquiry.</small>
|
||||
</section>}
|
||||
{showProductInformation && <section className="product-information">
|
||||
<h2>{configuration?.productInformationTitle || "Product information"}</h2>
|
||||
<dl>
|
||||
@@ -1030,8 +1105,8 @@ function Footer() {
|
||||
return (
|
||||
<footer>
|
||||
<div>
|
||||
<b>SHOPLIX</b>
|
||||
<p>Industrial products and expertise for global B2B projects.</p>
|
||||
<b>HONGYU</b>
|
||||
<p>Trimmer heads and garden tool accessories for global distributors.</p>
|
||||
</div>
|
||||
<div>
|
||||
<h3>Company</h3>
|
||||
|
||||
@@ -557,6 +557,46 @@ nav a:hover {
|
||||
color: #53615c;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.product-options {
|
||||
border-bottom: 1px solid #e1e7e4;
|
||||
border-top: 1px solid #e1e7e4;
|
||||
margin: 24px 0;
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.product-options h2 {
|
||||
font-size: 16px;
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
|
||||
.product-options > div {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 9px;
|
||||
}
|
||||
|
||||
.product-options span {
|
||||
background: #f1f6f4;
|
||||
border: 1px solid #cddbd6;
|
||||
color: #173c34;
|
||||
display: grid;
|
||||
font-size: 13px;
|
||||
gap: 3px;
|
||||
padding: 9px 12px;
|
||||
}
|
||||
|
||||
.product-options span b {
|
||||
font-size: 11px;
|
||||
letter-spacing: .04em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.product-options small {
|
||||
color: #66746f;
|
||||
display: block;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.category-sidebar {
|
||||
position: sticky;
|
||||
top: 106px;
|
||||
|
||||
Reference in new issue
Block a user