diff --git a/src/forge/Information/Pages/homepage/component/specialProjects.jsx b/src/forge/Information/Pages/homepage/component/specialProjects.jsx
index bb4d4ee2..58fe5b38 100644
--- a/src/forge/Information/Pages/homepage/component/specialProjects.jsx
+++ b/src/forge/Information/Pages/homepage/component/specialProjects.jsx
@@ -1,6 +1,6 @@
import React , { useEffect, useState } from 'react';
import { getSpecialProjectDetail, getSpecialProjectList, getSpecialProjectTypeList, getImage } from '../../../api';
-import { Col, Divider, Row, Tag } from 'antd';
+import { Col, Divider, Icon, Row, Tag } from 'antd';
import Nodata from '../../../../Nodata';
import '../index.scss';
import { TypeCarousel } from './project';
@@ -12,6 +12,9 @@ function SpecialProjects({data, subTitle}) {
const [projectList, setProjectList] = useState([]);
const [selectedItem, setSelectedItem] = useState(null);
const [projectDetail, setProjectDetail] = useState({});
+ const relevancyTypes = ["PAPER", "PATENT", "PROJECT"]
+ const itemsPerRow = 3;
+
useEffect(()=>{
id && getSpecialProjectTypeList(id, {
@@ -36,39 +39,51 @@ function SpecialProjects({data, subTitle}) {
})
}, [typeId])
- useEffect(()=>{
- selectedItem && getSpecialProjectDetail(selectedItem).then(res=>{
- if(res){
- const rows = res.data.rows;
- // 根据类型分类
- const rowsByType = rows.reduce((acc, item) => {
- // 如果acc中没有当前item.type的数组,则创建一个
- if (!acc[item.type]) {
- acc[item.type] = [];
- }
- // 将当前item添加到对应type的数组中
- acc[item.type].push(item);
- return acc;
- }, {});
- setProjectDetail({
- detail: projectList.find(item => item.id === selectedItem),
- ...rowsByType
- });
- }
- })
- }, [selectedItem])
+ async function getRelevancyList(id, type, pageSize=5) {
+ const res = await getSpecialProjectDetail(id, {
+ type,
+ pageNum: 1,
+ pageSize
+ });
+ return res.data;
+ }
- const itemsPerRow = 3;
-
- const handleItemClick = (id) => {
+ const handleItemClick = async (id) => {
setSelectedItem(selectedItem === id ? null : id);
+ if(id === selectedItem) return
+ const data = await Promise.all(relevancyTypes.map(async (item) => {
+ return {[item]: await getRelevancyList(id, item)};
+ }));
+ const [a,b,c] = data
+ setProjectDetail({
+ detail: projectList.find(item => item.id === id),
+ ...a,
+ ...b,
+ ...c
+ });
};
- const list = (title, table1, table2, table3, list)=>{
+ const showMore = (type, isShowAll) => {
+ return
+ {
+ const data = await getRelevancyList(selectedItem, type, isShowAll ? 5 : 1000);
+ const detail = {
+ ...projectDetail
+ }
+ detail[type] = data
+ setProjectDetail(detail);
+ }}>{isShowAll ? '收起' : '展开'}
+
+ }
+
+ const listItem = (title, table1, table2, table3, res)=>{
+ const type = title === "论文" ? "PAPER": "PATENT"
+ const {rows:list, total} = res;
+ const isShowAll = list.length === total
return !!list.length &&
{title}
-
+
{table1}
{table2}
{table3}
@@ -88,11 +103,14 @@ function SpecialProjects({data, subTitle}) {
})}
+ {total > 5 && showMore(type, isShowAll)}
{!list.length &&
}
}
- const list2 = (title, table1, table2, list)=>{
+ const list2Item = (title, table1, table2, res)=>{
+ const {rows:list, total} = res;
+ const isShowAll = list.length === total
return !!list.length &&
{title}
@@ -110,6 +128,7 @@ function SpecialProjects({data, subTitle}) {
})}
+ {total > 5 && showMore("PROJECT", isShowAll)}
{!list.length &&
}
}
@@ -140,8 +159,7 @@ function SpecialProjects({data, subTitle}) {
// 如果当前行包含选中项,添加详情面板
if (currentRow.some(item => item.key === selectedItem?.toString())) {
-
- const {detail, PAPER=[], PATENT=[], PROJECT=[]} = projectDetail;
+ const {detail, PAPER={rows:[]}, PATENT={rows:[]}, PROJECT={rows:[]}} = projectDetail;
const {name, projectLeader, awards, introductionImageIdentifier} = detail || {};
rendered.push(
@@ -153,10 +171,10 @@ function SpecialProjects({data, subTitle}) {
{ introductionImageIdentifier &&
简介:
}
{
- PAPER.length + PATENT.length + PROJECT.length > 0 &&
- {list("论文", "论文标题", "作者", "单位", PAPER)}
- {list("专利", "专利标题", "作者", "单位", PATENT)}
- {list2("开源项目", "项目名称", "参与者", PROJECT)}
+ PAPER.rows.length + PATENT.rows.length + PROJECT.rows.length > 0 &&
+ {listItem("论文", "论文标题", "作者", "单位", PAPER)}
+ {listItem("专利", "专利标题", "作者", "单位", PATENT)}
+ {list2Item("开源项目", "项目名称", "参与者", PROJECT)}
}