提交 40e08c40 作者: 翁进城

对接商城广告

上级 fc6e072f
...@@ -32,10 +32,18 @@ export interface ListPageGoodsInfoResp { ...@@ -32,10 +32,18 @@ export interface ListPageGoodsInfoResp {
"totalPage": 0 "totalPage": 0
} }
export interface Ad {
id: number;
imageUrl: string;
}
export default { export default {
//web-商品信息-分页 //web-商品信息-分页
listPageGoodsInfo: (params: ListPageGoodsInfoParams, options = {}): Promise<Response<ListPageGoodsInfoResp>> => { listPageGoodsInfo: (params: ListPageGoodsInfoParams, options = {}): Promise<Response<ListPageGoodsInfoResp>> => {
return request('/pms/webProductMall/listPageGoodsInfo', 'post', params, options) return request('/pms/webProductMall/listPageGoodsInfo', 'post', params, options)
},
//产品商城广告位
ad: (): Promise<Response<Array<Ad>>> => {
return request('/pms/webProductMall/ad')
} }
} }
\ No newline at end of file
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { Button, Empty, Pagination, Select, Space, Tag } from "antd"; import { Empty, Pagination, Image } 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 Image from "next/image";
import Filter, { AdapterResult, FilterResult } from "~/components/filter"; import Filter, { AdapterResult, FilterResult } from "~/components/filter";
import api, { Goods, ListPageGoodsInfoParams } from "./api"; import api, { Ad, Goods, ListPageGoodsInfoParams } from "./api";
// 此函数在构建时被调用 // 此函数在构建时被调用
export async function getServerSideProps() { export async function getServerSideProps() {
...@@ -18,21 +17,23 @@ type Props = {}; ...@@ -18,21 +17,23 @@ type Props = {};
export default function Mall(props: Props) { export default function Mall(props: Props) {
const router = useRouter(); const router = useRouter();
const [productList, setProductList] = useState<Array<Goods>>([]); const [productList, setProductList] = useState<Array<Goods>>([]); //商品列表
const [filterResult, setFilterResult] = useState<AdapterResult>({}); const [filterResult, setFilterResult] = useState<AdapterResult>({}); //筛选结果
const [pageParams, setPageParams] = useState({ const [pageParams, setPageParams] = useState({
pageNo: 1, pageNo: 1,
pageSize: 16, pageSize: 16,
}); }); //分页器对象
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>>([]); //广告列表
useEffect(() => { useEffect(() => {
//中断前一次请求 //中断前一次列表请求
abort?.abort(); abort?.abort();
setAbort(new AbortController()); setAbort(new AbortController());
}, [filterResult, pageParams]); }, [filterResult, pageParams]);
//端口列表请求
useEffect(() => { useEffect(() => {
api api
.listPageGoodsInfo( .listPageGoodsInfo(
...@@ -50,7 +51,17 @@ export default function Mall(props: Props) { ...@@ -50,7 +51,17 @@ export default function Mall(props: Props) {
}); });
}, [abort]); }, [abort]);
const onFilterChange = (filterResult: FilterResult, adapterFilterResult: AdapterResult) => { //广告请求
useEffect(() => {
api.ad().then((res) => {
setAdList(res.result || []);
});
}, []);
const onFilterChange = (
filterResult: FilterResult,
adapterFilterResult: AdapterResult
) => {
console.log("filterResult", filterResult, adapterFilterResult); console.log("filterResult", filterResult, adapterFilterResult);
setFilterResult(adapterFilterResult); setFilterResult(adapterFilterResult);
}; };
...@@ -79,7 +90,7 @@ export default function Mall(props: Props) { ...@@ -79,7 +90,7 @@ export default function Mall(props: Props) {
<li <li
key={i} key={i}
className={styles.item} className={styles.item}
onClick={() => router.push("/mall/detail/1")} onClick={() => router.push("/mall/detail/" + item.id)}
> >
<div className={styles.imgBox}> <div className={styles.imgBox}>
<Image <Image
...@@ -88,6 +99,7 @@ export default function Mall(props: Props) { ...@@ -88,6 +99,7 @@ export default function Mall(props: Props) {
className={styles.img} className={styles.img}
width={116} width={116}
height={116} height={116}
preview={false}
></Image> ></Image>
</div> </div>
<div className={styles.title}>{item.goodsName}</div> <div className={styles.title}>{item.goodsName}</div>
...@@ -99,7 +111,13 @@ export default function Mall(props: Props) { ...@@ -99,7 +111,13 @@ export default function Mall(props: Props) {
); );
})} })}
{productList.length === 0 && ( {productList.length === 0 && (
<Empty style={{ paddingTop: 20, width: '100%', textAlign: "center" }}></Empty> <Empty
style={{
paddingTop: 20,
width: "100%",
textAlign: "center",
}}
></Empty>
)} )}
</ul> </ul>
<Pagination <Pagination
...@@ -109,13 +127,23 @@ export default function Mall(props: Props) { ...@@ -109,13 +127,23 @@ export default function Mall(props: Props) {
total={count} total={count}
onChange={onPageChange} onChange={onPageChange}
hideOnSinglePage={true} hideOnSinglePage={true}
style={{marginTop: 20}} style={{ marginTop: 20 }}
/> />
</div> </div>
<div className={styles.adList}> <div className={styles.adList}>
<div className={styles.ad}></div> {adList.map((item) => {
<div className={styles.ad}></div> return (
<Image
key={item.id}
className={styles.ad}
src={item.imageUrl}
width="270"
height="270"
preview={false}
></Image>
);
})}
</div> </div>
</div> </div>
</div> </div>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论