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({});