From 35b49be71e2fc4e2177f43400a8d2889710d2129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E6=80=9D?= <2897217417@qq.com> Date: Thu, 14 Nov 2024 16:21:16 +0800 Subject: [PATCH] =?UTF-8?q?uos=E9=A6=96=E9=A1=B5=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Pages/homepage/component/partner.jsx | 4 +- .../Pages/homepage/component/source.jsx | 36 ++++---- .../homepage/component/specialProjects.jsx | 86 +++++++++++-------- 3 files changed, 73 insertions(+), 53 deletions(-) diff --git a/src/forge/Information/Pages/homepage/component/partner.jsx b/src/forge/Information/Pages/homepage/component/partner.jsx index 9ffd31cc..50822eef 100644 --- a/src/forge/Information/Pages/homepage/component/partner.jsx +++ b/src/forge/Information/Pages/homepage/component/partner.jsx @@ -43,11 +43,11 @@ function Partner({data}) { ); } - return
+ return list && !!list.length &&

{homepagePartnersTitle}

{gridItems}
- {list && !list.length && } + {/* {list && !list.length && } */}
} diff --git a/src/forge/Information/Pages/homepage/component/source.jsx b/src/forge/Information/Pages/homepage/component/source.jsx index c9b26794..9031e223 100644 --- a/src/forge/Information/Pages/homepage/component/source.jsx +++ b/src/forge/Information/Pages/homepage/component/source.jsx @@ -56,26 +56,28 @@ function Source({data, subTitle}) {
- {sourceList.map(i=>{ + {sourceList.map(i => { const time = i.updateTime || i.createTime - return
-
-
-

{i.name}

-

{i.summary}

+ return +
+
+
+

{i.name}

+

{i.summary}

+
+
- +
+ {time && time.split(" ")[0].replace(/-/g, '.')} + + + + 下载 + +
+
-
- {time && time.split(" ")[0].replace(/-/g, '.')} - - - - 下载 - -
- -
+ })}
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)}
}