提交 3524e2b9 作者: 翁进城

商城列表加载时优化

上级 9393282f
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
flex-shrink: 0; flex-shrink: 0;
flex-direction: column; flex-direction: column;
gap: 12px; gap: 12px;
width: 270px;
.ad { .ad {
width: 270px; width: 270px;
...@@ -26,13 +27,14 @@ ...@@ -26,13 +27,14 @@
.listContent{ .listContent{
width: 100%; width: 100%;
} }
.listWrap { .listWrap {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
gap: 12px; gap: 12px;
height: auto; height: 856px;
.item { .item {
cursor: pointer; cursor: pointer;
......
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { Empty, Pagination, Image } from "antd"; import { Empty, Pagination, Image, Spin } from "antd";
import Layout from "~/components/layout"; import Layout from "~/components/layout";
import styles from "./index.module.scss"; import styles from "./index.module.scss";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import Filter, { AdapterResult, FilterResult } from "~/components/filter"; import Filter, { AdapterResult, FilterResult } from "~/components/filter";
import api, { Ad, Goods, ListPageGoodsInfoParams } from "./api"; import api, { Ad, Goods, ListPageGoodsInfoParams } from "./api";
import errImg from "~/assets/errImg";
// 此函数在构建时被调用 // 此函数在构建时被调用
export async function getServerSideProps() { export async function getServerSideProps() {
...@@ -26,6 +27,7 @@ export default function Mall(props: Props) { ...@@ -26,6 +27,7 @@ export default function Mall(props: Props) {
const [count, setCount] = useState(0); //商品总数 const [count, setCount] = useState(0); //商品总数
const [abort, setAbort] = useState<AbortController | null>(null); //请求中断对你 const [abort, setAbort] = useState<AbortController | null>(null); //请求中断对你
const [adList, setAdList] = useState<Array<Ad>>([]); //广告列表 const [adList, setAdList] = useState<Array<Ad>>([]); //广告列表
const [loading, setLoading] = useState(false);
useEffect(() => { useEffect(() => {
//中断前一次列表请求 //中断前一次列表请求
...@@ -38,6 +40,7 @@ export default function Mall(props: Props) { ...@@ -38,6 +40,7 @@ export default function Mall(props: Props) {
if (!abort) { if (!abort) {
return; return;
} }
setLoading(true);
api api
.listPageGoodsInfo( .listPageGoodsInfo(
{ {
...@@ -51,6 +54,7 @@ export default function Mall(props: Props) { ...@@ -51,6 +54,7 @@ export default function Mall(props: Props) {
.then((res) => { .then((res) => {
setProductList(res.result?.list || []); setProductList(res.result?.list || []);
setCount(res.result?.totalCount || 0); setCount(res.result?.totalCount || 0);
setLoading(false);
}); });
}, [abort]); }, [abort]);
...@@ -83,55 +87,61 @@ export default function Mall(props: Props) { ...@@ -83,55 +87,61 @@ export default function Mall(props: Props) {
showResultItem showResultItem
onChange={onFilterChange} onChange={onFilterChange}
></Filter> ></Filter>
<div className={styles.productList}> <div className={styles.productList}>
<div className={styles.title}>四旋翼无人机</div> <div className={styles.title}>四旋翼无人机</div>
<div className={styles.main}> <div className={styles.main}>
<div className={styles.listContent}> <div style={{ flex: "auto"}}>
<ul className={styles.listWrap}> <Spin spinning={loading} delay={500}>
{productList.map((item, i) => { <div className={styles.listContent}>
return ( <ul className={styles.listWrap}>
<li {productList.map((item, i) => {
key={i} return (
className={styles.item} <li
onClick={() => router.push("/mall/detail/" + item.id)} key={i}
> className={styles.item}
<div className={styles.imgBox}> onClick={() => router.push("/mall/detail/" + item.id)}
<Image >
alt="" <div className={styles.imgBox}>
src={item.imgUrl} <Image
className={styles.img} alt=""
width={116} src={item.imgUrl}
height={116} className={styles.img}
preview={false} width={116}
></Image> height={116}
</div> preview={false}
<div className={styles.title}>{item.goodsName}</div> ></Image>
<div className={styles.sellCount}> </div>
半年售 <div className={styles.title}>{item.goodsName}</div>
{(Math.floor(Math.random() * 901) + 100).toFixed(0)} <div className={styles.sellCount}>
</div> 半年售
</li> {(Math.floor(Math.random() * 901) + 100).toFixed(0)}
); </div>
})} </li>
{productList.length === 0 && ( );
<Empty })}
style={{ {productList.length === 0 && (
paddingTop: 20, <Empty
width: "100%", style={{
textAlign: "center", paddingTop: 20,
}} width: "100%",
></Empty> textAlign: "center",
)} }}
</ul> ></Empty>
<Pagination )}
current={pageParams.pageNo} </ul>
showSizeChanger={false} <Pagination
showQuickJumper current={pageParams.pageNo}
total={count} defaultPageSize={pageParams.pageSize}
onChange={onPageChange} showSizeChanger={false}
hideOnSinglePage={true} showQuickJumper
style={{ marginTop: 20 }} total={count}
/> onChange={onPageChange}
hideOnSinglePage={true}
style={{ marginTop: 20 }}
/>
</div>
</Spin>
</div> </div>
<div className={styles.adList}> <div className={styles.adList}>
...@@ -144,6 +154,7 @@ export default function Mall(props: Props) { ...@@ -144,6 +154,7 @@ export default function Mall(props: Props) {
width="270" width="270"
height="270" height="270"
preview={false} preview={false}
fallback={errImg}
></Image> ></Image>
); );
})} })}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论