feat: add resource for first login

This commit is contained in:
jialin
2025-12-11 17:50:39 +08:00
parent b38bc8a207
commit 3dbb0de683
11 changed files with 227 additions and 82 deletions
+49 -8
View File
@@ -1,3 +1,6 @@
import useClusterList from '@/pages/cluster-management/hooks/use-cluster-list';
import useNoResourceResult from '@/pages/llmodels/hooks/use-no-resource-result';
import { useIntl } from '@umijs/max';
import { useMemoizedFn } from 'ahooks';
import { Spin } from 'antd';
import { useEffect, useState } from 'react';
@@ -8,32 +11,70 @@ import DashboardContext from './config/dashboard-context';
import { DashboardProps } from './config/types';
const Dashboard: React.FC = () => {
const intl = useIntl();
const [loading, setLoading] = useState(false);
const [data, setData] = useState<DashboardProps>({} as DashboardProps);
const { fetchAll, clusterList, workerList } = useClusterList();
const getDashboardData = useMemoizedFn(async () => {
const { noResourceResult } = useNoResourceResult({
loadend: true,
loading: false,
dataSource: clusterList.length > 0 ? workerList : [],
queryParams: {},
iconType: 'icon-dashboard',
title:
clusterList.length > 0
? intl.formatMessage({ id: 'noresult.workers.title' })
: intl.formatMessage({ id: 'noresult.cluster.title' }),
noClusters: !clusterList.length,
noWorkers: workerList.length === 0 && clusterList.length > 0,
defaultContent: {
subTitle: intl.formatMessage({ id: 'noresult.workers.subTitle' }),
noFoundText: intl.formatMessage({ id: 'noresult.workers.nofound' }),
buttonText: intl.formatMessage({ id: 'noresult.workers.button.add' }),
onClick: () => {}
}
});
const fetchDashboardData = useMemoizedFn(async () => {
try {
setLoading(true);
const res = await queryDashboardData();
setData(res);
setLoading(false);
} catch (error) {
setLoading(false);
setData({} as DashboardProps);
}
});
const initData = useMemoizedFn(async () => {
try {
setLoading(true);
const { hasClusters, hasWorkers } = await fetchAll();
if (!hasClusters || !hasWorkers) {
setLoading(false);
return;
}
await fetchDashboardData();
setLoading(false);
} catch (error) {
setLoading(false);
}
});
useEffect(() => {
getDashboardData();
initData();
}, []);
return (
<DashboardContext.Provider
value={{ ...data, fetchData: queryDashboardData }}
value={{ ...data, fetchData: fetchDashboardData, clusterList }}
>
<PageBox>
<Spin spinning={loading}>
<DashboardInner />
<Spin spinning={loading} style={{ minHeight: 300 }}>
{(!clusterList.length || !workerList.length) && !loading ? (
noResourceResult
) : loading ? null : (
<DashboardInner />
)}
</Spin>
</PageBox>
</DashboardContext.Provider>