功能迭代
This commit is contained in:
1 parent
baf555c9b3
commit
da4e9a57a8
17 files changed
+98
-184
No files matched your search
+17
-5
@@ -376,7 +376,7 @@ 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"?{}:{contentType:section.sourceType||"CASE"};post(path,body).then(data=>setItems((data.items||[]).slice(0,section.limit||3))).catch(()=>setItems([]))},[section.type,section.sourceType,section.limit]);
|
||||
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]);
|
||||
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>;
|
||||
}
|
||||
@@ -496,6 +496,8 @@ function Collection({
|
||||
const productCategories = useProductCategoryTree();
|
||||
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));
|
||||
const [totalPages, setTotalPages] = useState(0);
|
||||
useEffect(() => {
|
||||
const run = async () => {
|
||||
try {
|
||||
@@ -509,16 +511,19 @@ function Collection({
|
||||
} else {
|
||||
const x = await post(
|
||||
type === "products" ? "/products/list" : "/contents/list",
|
||||
type === "products" ? { categoryCode } : { contentType: type, categoryCode },
|
||||
type === "products"
|
||||
? { categoryCode, pageNo, pageSize: 12 }
|
||||
: { contentType: type, categoryCode, pageNo, pageSize: 12 },
|
||||
);
|
||||
setData(x.items || []);
|
||||
setTotalPages(x.totalPages || 0);
|
||||
}
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : "Unable to load");
|
||||
}
|
||||
};
|
||||
void run();
|
||||
}, [type, slug, categoryCode]);
|
||||
}, [type, slug, categoryCode, pageNo]);
|
||||
if (error) return <ErrorState message={error} />;
|
||||
if (slug && !Array.isArray(data)) {
|
||||
const d = data as Record<string, any>;
|
||||
@@ -608,6 +613,13 @@ function Collection({
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
{totalPages > 1 && (
|
||||
<nav className="site-pagination" aria-label={`${title} pagination`}>
|
||||
<button type="button" disabled={pageNo <= 1} onClick={() => setPageNo((value) => value - 1)}>Previous</button>
|
||||
<span>Page {pageNo} of {totalPages}</span>
|
||||
<button type="button" disabled={pageNo >= totalPages} onClick={() => setPageNo((value) => value + 1)}>Next</button>
|
||||
</nav>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -630,8 +642,8 @@ function SearchResults({ query }: { query: string }) {
|
||||
if (!keyword) { setResults([]); setLoading(false); return; }
|
||||
setLoading(true);
|
||||
Promise.all([
|
||||
post("/products/list", {}).then((data) => ({ items: data.items || [], base: "products", label: "Product" })),
|
||||
...(["NEWS", "CASE", "HELP"] as ContentType[]).map((contentType) => post("/contents/list", { contentType }).then((data) => ({ items: data.items || [], base: contentType.toLowerCase(), label: contentType === "CASE" ? "Case" : contentType.charAt(0) + contentType.slice(1).toLowerCase() }))),
|
||||
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() }))),
|
||||
]).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)));
|
||||
|
||||
@@ -528,6 +528,35 @@ nav a:hover {
|
||||
.collection-layout .cards {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.site-pagination {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
gap: 18px;
|
||||
justify-content: center;
|
||||
margin: 42px 0 0;
|
||||
}
|
||||
|
||||
.site-pagination button {
|
||||
background: #0d6d5e;
|
||||
border: 1px solid #0d6d5e;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
min-width: 104px;
|
||||
padding: 11px 18px;
|
||||
}
|
||||
|
||||
.site-pagination button:disabled {
|
||||
background: #edf1ef;
|
||||
border-color: #d9e0dd;
|
||||
color: #8c9893;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.site-pagination span {
|
||||
color: #53615c;
|
||||
font-size: 14px;
|
||||
}
|
||||
.category-sidebar {
|
||||
position: sticky;
|
||||
top: 106px;
|
||||
|
||||
Reference in new issue
Block a user