From b5e9481868bb5d3c1fdf68cdfdc8490d44630e06 Mon Sep 17 00:00:00 2001 From: awenes <1121353141@qq.com> Date: Mon, 25 Sep 2023 22:43:08 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E9=97=A8=E6=88=B7=E7=AB=AF=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=88=86=E7=BB=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/pages/Application/Application.tsx | 63 ++++++++++--------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/eiam-portal/src/main/portal-fe/src/pages/Application/Application.tsx b/eiam-portal/src/main/portal-fe/src/pages/Application/Application.tsx index d9ffd99f..4649e1a3 100644 --- a/eiam-portal/src/main/portal-fe/src/pages/Application/Application.tsx +++ b/eiam-portal/src/main/portal-fe/src/pages/Application/Application.tsx @@ -25,7 +25,7 @@ import { } from '@ant-design/pro-components'; import { App, Avatar, Badge, Card, Typography } from 'antd'; import React, { useRef, useState } from 'react'; -import { AppList, InitLoginType } from './data.d'; +import { AppGroupList, AppList, InitLoginType } from './data.d'; import { getAppGroupList, queryAppList } from './service'; import useStyle from './style'; import classnames from 'classnames'; @@ -58,18 +58,34 @@ const CardList = () => { const { message } = App.useApp(); const actionRef = useRef(); const [searchParams, setSearchParams] = useState>(); + const [appGroupList, setAppGroupList] = useState([]); const [loading, setLoading] = useState(false); - const [items, setItems] = useState<{ key: string; label: React.JSX.Element }[]>([ - { - key: all, - label: ( - - {intl.formatMessage({ id: 'pages.application.group_all' })} - {renderBadge(0, currentGroup === 'all')} - - ), - }, - ]); + + const getItems = () => { + let data: { key: string; label: React.JSX.Element }[] = [ + { + key: all, + label: ( + + {intl.formatMessage({ id: 'pages.application.group_all' })} + {renderBadge(0, currentGroup === 'all')} + + ), + }, + ]; + appGroupList.forEach((item) => { + data.push({ + key: item.id, + label: ( + + {item.name} + {renderBadge(item.appCount, currentGroup === item.id)} + + ), + }); + }); + return data; + }; const initSso = (idpInitUrl: string) => { const div = window.document.createElement('div'); @@ -91,21 +107,8 @@ const CardList = () => { setLoading(false); }); if (success && result) { - let data: { key: string; label: React.JSX.Element }[] = []; - result.forEach((item) => { - data.push({ - key: item.id, - label: ( - - {item.name} - {renderBadge(item.appCount, currentGroup === item.id)} - - ), - }); - }); - setItems((values) => { - return values.concat(data); - }); + setAppGroupList(result); + setCurrentGroup(all); // 手动请求 actionRef.current?.reload(); } @@ -133,12 +136,12 @@ const CardList = () => { request={queryAppList} pagination={{}} toolbar={ - items.length > 0 + appGroupList?.length > 0 ? { menu: { type: 'tab', activeKey: currentGroup, - items: items, + items: getItems(), onChange(key) { if (key) { setCurrentGroup(key); @@ -212,7 +215,7 @@ const CardList = () => { return Promise.resolve(); }} onReset={() => { - if (items.length > 0) { + if (currentGroup && currentGroup !== all) { setSearchParams({ groupId: currentGroup }); } else { setSearchParams({});