Commit ec1e6088 authored by chenshouchao's avatar chenshouchao

feat: 完成cardtable

parent 48d91de2
.tableBox {
display: flex;
justify-content: flex-start;
flex-wrap: wrap;
}
.itemBox {
}
import style from "./index.module.css"; import style from "./index.module.css";
interface ICardTableProps { interface ICardTableProps {
data: Array<any>; data: Array<any>; // 列表数据
renderItem: any; renderItem: any; // 单个卡片的渲染函数
tableKey?: string; // 表格数据的key
numberOfColumns?: number; // 列数 每行渲染几个
horizontalSpacing?: number; // 水平方向的间隔
verticalSpacing?: number; // 垂直方向的间隔
} }
const CardTable = (props: ICardTableProps) => { const CardTable = (props: ICardTableProps) => {
const { data, renderItem } = props; const {
return <div>CardTable</div>; data,
renderItem,
tableKey = "id",
numberOfColumns = 3,
horizontalSpacing = 20,
verticalSpacing = 20,
} = props;
return (
<div
className={style.tableBox}
style={{
marginLeft: `-${horizontalSpacing / 2}px`,
marginRight: `-${horizontalSpacing / 2}px`,
}}
>
{data.map((item, index) => {
return (
<div
className={style.itemBox}
key={item[tableKey] ? item[tableKey] : index}
style={{
width: `${100 / numberOfColumns}%`,
paddingLeft: `${horizontalSpacing / 2}px`,
paddingRight: `${horizontalSpacing / 2}px`,
paddingBottom: `${verticalSpacing}px`,
boxSizing: "border-box",
}}
>
{renderItem(item, index)}
</div>
);
})}
</div>
);
}; };
export default CardTable; export default CardTable;
...@@ -51,9 +51,6 @@ const useMyRouter = () => { ...@@ -51,9 +51,6 @@ const useMyRouter = () => {
route.path = `${routeHead}/${item.id}${route.path}` route.path = `${routeHead}/${item.id}${route.path}`
if (Array.isArray(route.children)) { if (Array.isArray(route.children)) {
route.children.forEach((childrenItem: any, index: number) => { route.children.forEach((childrenItem: any, index: number) => {
console.log(route)
console.log(childrenItem)
console.log(routeHead)
if (childrenItem.path) { if (childrenItem.path) {
childrenRoutes.push({ childrenRoutes.push({
...childrenItem, ...childrenItem,
...@@ -63,7 +60,6 @@ const useMyRouter = () => { ...@@ -63,7 +60,6 @@ const useMyRouter = () => {
}) })
} }
}) })
// http://localhost:8088/v3/product/resourceCenter/userResources/seeEnv
route.children = route.children.filter((childrenItem: any) => !childrenItem.path) route.children = route.children.filter((childrenItem: any) => !childrenItem.path)
} }
} }
......
import CardTable from "@/components/CommonComponents/CardTable";
const CardTableDemo = () => { const CardTableDemo = () => {
return <div>CardTableDemo</div>; const list = [
{
id: 1,
},
{
id: 2,
},
{
id: 3,
},
{
id: 4,
},
{
id: 5,
},
{
id: 6,
},
{
id: 7,
},
{
id: 8,
},
{
id: 9,
},
{
id: 10,
},
{
id: 11,
},
{
id: 12,
},
{
id: 13,
},
];
const renderItem = (item: any) => {
return (
<div style={{ border: "1px solid red", height: "200px" }}>{item.id}</div>
);
};
return (
<div>
CardTableDemo
<CardTable
data={list}
renderItem={renderItem}
numberOfColumns={4}
></CardTable>
</div>
);
}; };
export default CardTableDemo; export default CardTableDemo;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment