提交 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,9 +87,12 @@ export default function Mall(props: Props) { ...@@ -83,9 +87,12 @@ 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 style={{ flex: "auto"}}>
<Spin spinning={loading} delay={500}>
<div className={styles.listContent}> <div className={styles.listContent}>
<ul className={styles.listWrap}> <ul className={styles.listWrap}>
{productList.map((item, i) => { {productList.map((item, i) => {
...@@ -125,6 +132,7 @@ export default function Mall(props: Props) { ...@@ -125,6 +132,7 @@ export default function Mall(props: Props) {
</ul> </ul>
<Pagination <Pagination
current={pageParams.pageNo} current={pageParams.pageNo}
defaultPageSize={pageParams.pageSize}
showSizeChanger={false} showSizeChanger={false}
showQuickJumper showQuickJumper
total={count} total={count}
...@@ -133,6 +141,8 @@ export default function Mall(props: Props) { ...@@ -133,6 +141,8 @@ export default function Mall(props: Props) {
style={{ marginTop: 20 }} style={{ marginTop: 20 }}
/> />
</div> </div>
</Spin>
</div>
<div className={styles.adList}> <div className={styles.adList}>
{adList.map((item) => { {adList.map((item) => {
...@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论