import { useEffect, useState, useRef } from 'react'; import { useTranslation } from 'react-i18next'; import { useNavigate } from 'react-router-dom'; import { Space, Button, Flex } from 'antd'; import TopCardList from './components/TopCardList'; import GuideCard from './components/GuideCard'; import VersionCard from './components/VersionCard'; import QuickActions from './components/QuickActions'; import Table, { type TableRef } from '@/components/Table' import type { ColumnsType } from 'antd/es/table'; import { formatDateTime } from '@/utils/format'; import { getDashboardData, getDashboardStatistics, type DataResponse } from '@/api/common'; import { switchWorkspace } from '@/api/workspaces' const Index = () => { const { t } = useTranslation(); const navigate = useNavigate() const [dashboardData, setDashboardData] = useState(); const tableRef = useRef(null); const tableApi = getDashboardData; const getDashboardCount = async () => { try{ const res = await getDashboardStatistics(); setDashboardData(res); }catch(e) { console.log(e) } } const handleJump = (id: string) => { switchWorkspace(id) .then(() => { localStorage.removeItem('user') navigate('/') }) } const columns: ColumnsType = [ { title: t('space.spaceName'), dataIndex: 'name', key: 'name', className: 'rb:text-[#212332]' }, { title: t('space.spaceIcon'), dataIndex: 'icon', key: 'icon', render:(value: string, record: any) => { return value ? ( icon ) : (
{record.name?.charAt(0)?.toUpperCase() || '?'}
) } }, { title: t('index.appCount'), dataIndex: 'app_count', key: 'app_count', }, { title: t('index.userCount'), dataIndex: 'user_count', key: 'user_count', }, { title: t('apiKey.createdAt'), dataIndex: 'created_at', key: 'created_at', render:(value:string) => { return( {formatDateTime(Number(value) ,'YYYY-MM-DD HH:mm:ss')} ) } }, { title: t('common.operation'), key: 'action', fixed: 'right', width: 100, render: (_, record) => ( ), }, ] useEffect(() => { tableRef.current?.loadData(); }, [tableApi]); useEffect(() => { getDashboardCount(); }, []) return (
{t('index.spaceTitle')}
{t('index.spaceSubTitle')}
{/* 统计卡片 */}
{/* 引导 */}
); } export default Index