feat(market): 异步加载组件和流程数据

master
钟良源 2 months ago
parent 63f5809c3b
commit b693e72e3e

@ -5,6 +5,8 @@ import styles from './style/market.module.less';
import { useSelector, useDispatch } from 'react-redux'; import { useSelector, useDispatch } from 'react-redux';
import { addProjectComp, addProjectBaseComp } from '@/api/scene'; import { addProjectComp, addProjectBaseComp } from '@/api/scene';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { getMyComponents, getPubComponents, getTeamComponents } from '@/api/components';
import { getMyFlowList, getPubFlowList } from '@/api/flow';
const { Row, Col } = Grid; const { Row, Col } = Grid;
const { Title, Text } = Typography; const { Title, Text } = Typography;
@ -422,12 +424,83 @@ const Market: React.FC<MarketProps> = ({ updateProjectComp }) => {
}; };
// 从缓存中获取组件列表的信息 // 从缓存中获取组件列表的信息
const getCompList = () => { const getCompList = async () => {
try {
const requests = [
{ promise: getMyComponents(), key: 'myLibs' },
{ promise: getPubComponents(), key: 'pubLibs' },
{ promise: getTeamComponents(), key: 'teamLibs' },
{
promise: getPubFlowList({
currPage: 1,
pageSize: 999
}),
key: 'pubFlow'
},
{
promise: getMyFlowList({
currPage: 1,
pageSize: 999
}),
key: 'myFlow'
}
];
const obj: any = {
myLibs: null,
pubLibs: null,
teamLibs: null,
pubFlow: null,
myFlow: null,
updateTime: dayjs().format('YYYY-MM-DD HH:mm:ss')
};
const userInfo = JSON.parse(sessionStorage.getItem('userInfo') || '{}'); const userInfo = JSON.parse(sessionStorage.getItem('userInfo') || '{}');
// 分别处理每个请求
for (const { promise, key } of requests) {
try {
const res: any = await promise;
if (res?.code === 200) {
if (key === 'pubFlow' || key === 'myFlow') {
res?.data.list.forEach(item => {
item['fontCompType'] = 'complex';
});
// 更新本地存储数据
obj[key] = res?.data.list || null;
}
// 给协同组件添加一个后续处理数据时使用的类型
else if (key === 'teamLibs') {
res.data.forEach(item => {
item.children.forEach(v => {
v['fontCompType'] = 'team';
});
});
obj[key] = res?.data || null;
}
else {
// 更新本地存储数据
res.data.forEach(item => {
item.children.forEach(v => {
v['fontCompType'] = 'normal';
});
});
obj[key] = res?.data || null;
}
}
sessionStorage.setItem(`compLibs${userInfo.userId}`, JSON.stringify(obj));
const componentData = JSON.parse(sessionStorage.getItem(`compLibs${userInfo.userId}`)); const componentData = JSON.parse(sessionStorage.getItem(`compLibs${userInfo.userId}`));
addInitState(componentData); addInitState(componentData);
} catch (error) {
console.error(`加载${key}失败:`, error);
}
}
} catch (error) {
console.error('更新组件库失败:', error);
}
}; };
useEffect(() => { useEffect(() => {
getCompList(); getCompList();
}, []); }, []);

Loading…
Cancel
Save