feat(compGrid): 更新组件类型并支持分页数据加载

- 修改 componentType 类型定义
- 引入 getMyFlowList与 getPubFlowList 接口,实现远程数据获取
- 添加分页逻辑
master
钟良源 4 months ago
parent 9d9f930078
commit 7df26f5dd6

@ -3,23 +3,49 @@ import styles from './style/compGrid.module.less';
import CompNode from './compNode'; import CompNode from './compNode';
import { complexData } from './test/tempData'; import { complexData } from './test/tempData';
import { Input, Grid, Pagination } from '@arco-design/web-react'; import { Input, Grid, Pagination } from '@arco-design/web-react';
import { getMyFlowList, getPubFlowList } from '@/api/flow';
const InputSearch = Input.Search; const InputSearch = Input.Search;
const Row = Grid.Row; const Row = Grid.Row;
const Col = Grid.Col; const Col = Grid.Col;
interface CompGridProps { interface CompGridProps {
componentType: 'myComplex' | 'publicComplex'; componentType: 'minePage' | 'publicList';
} }
const CompGrid: React.FC<CompGridProps> = ({ componentType }) => { const CompGrid: React.FC<CompGridProps> = ({ componentType }) => {
const [currentComponentType, setCurrentComponentType] = useState('');
const [compData, setCompData] = useState([]); const [compData, setCompData] = useState([]);
const [paginationData, setPaginationData] = useState({ totalCount: 0, currPage: 1, pageSize: 11 });
useEffect(() => { useEffect(() => {
setCurrentComponentType(componentType); if (componentType) getComponentData(componentType);
setCompData(complexData[`${componentType}`]);
}, [componentType]); }, [componentType]);
const getComponentData = async (key: 'minePage' | 'publicList') => {
const apiList = {
minePage: getMyFlowList,
publicList: getPubFlowList
};
const res: any = await apiList[key]({
currPage: paginationData.currPage,
pageSize: paginationData.pageSize
});
if (res.code === 200) {
setCompData(res.data.list);
setPaginationData({
totalCount: res.data.totalCount,
currPage: res.data.currPage,
pageSize: res.data.pageSize
});
}
};
useEffect(() => {
getComponentData(componentType);
}, [paginationData.currPage]);
return ( return (
<> <>
<div className={styles['comp-grid-container']}> <div className={styles['comp-grid-container']}>
@ -45,7 +71,15 @@ const CompGrid: React.FC<CompGridProps> = ({ componentType }) => {
})} })}
</Row> </Row>
<div className={styles['comp-grid-footer']}> <div className={styles['comp-grid-footer']}>
<Pagination total={200} /> <Pagination
total={paginationData.totalCount + 200}
onChange={(number) => {
setPaginationData({
...paginationData,
currPage: number
});
}}
/>
</div> </div>
</div> </div>
</> </>

@ -1,35 +1,45 @@
import React from 'react'; import React, { useState } from 'react';
import styles from './style/index.module.less'; import styles from './style/index.module.less';
import CustomCard from '@/components/CustomCard/index'; import CustomCard from '@/components/CustomCard/index';
import { Tabs } from '@arco-design/web-react'; import { Tabs } from '@arco-design/web-react';
import CompGrid from './compGrid'; import CompGrid from './compGrid';
import { getPubFlowList, getMyFlowList } from '@/api/flow';
const TabPane = Tabs.TabPane; const TabPane = Tabs.TabPane;
function CompositeCompLibrary() { function CompositeCompLibrary() {
const [activeKey, setActiveKey] = useState<'minePage' | 'publicList'>('minePage');
const handelChangeTabs = (key) => {
setActiveKey(key);
};
return ( return (
<> <>
<div className={styles['composite-comp-library-container']}> <div className={styles['composite-comp-library-container']}>
<CustomCard> <CustomCard>
<Tabs defaultActiveTab="1"> <Tabs
defaultActiveTab={activeKey}
onChange={(e) => handelChangeTabs(e)}
>
<TabPane <TabPane
key="1" key="minePage"
title={ title={
<span> <span>
<span></span> <span></span>
</span> </span>
} }
> >
<CompGrid componentType="myComplex" /> <CompGrid componentType="minePage" />
</TabPane> </TabPane>
<TabPane <TabPane
key="2" key="publicList"
title={ title={
<span> <span>
<span></span> <span></span>
</span> </span>
}> }>
<CompGrid componentType="publicComplex" /> <CompGrid componentType="publicList" />
</TabPane> </TabPane>
</Tabs> </Tabs>
</CustomCard> </CustomCard>

Loading…
Cancel
Save