import { Body, Cell, Header, HeaderCell, HeaderRow, Row, Table } from '@table-library/react-table-library/table'; import { useTheme as tableTheme } from '@table-library/react-table-library/theme'; import { useAutoRequest } from 'alova/client'; import { FormLoader, SectionContent, useLayoutTitle } from 'components'; import { useI18nContext } from 'i18n/i18n-react'; import type { Translation } from 'i18n/i18n-types'; import { readActivity } from '../../api/app'; import type { Stat } from '../main/types'; const SystemActivity = () => { const { data, send: loadData, error } = useAutoRequest(readActivity, { pollingTime: 2000 }); const { LL } = useI18nContext(); useLayoutTitle(LL.DATA_TRAFFIC()); const stats_theme = tableTheme({ Table: ` --data-table-library_grid-template-columns: repeat(1, minmax(0, 1fr)) 90px 90px 80px; `, BaseRow: ` font-size: 14px; `, HeaderRow: ` text-transform: uppercase; background-color: black; color: #90CAF9; .th { height: 36px; border-bottom: 1px solid #565656; } `, Row: ` .td { padding: 8px; border-top: 1px solid #565656; border-bottom: 1px solid #565656; } &:nth-of-type(odd) .td { background-color: #303030; } &:nth-of-type(even) .td { background-color: #1e1e1e; } `, BaseCell: ` &:not(:first-of-type) { text-align: center; } ` }); const showName = (id: number) => { const name: keyof Translation['STATUS_NAMES'] = id; return LL.STATUS_NAMES[name](); }; const showQuality = (stat: Stat) => { if (stat.q === 0 || stat.s + stat.f === 0) { return; } if (stat.q === 100) { return
{stat.q}%
; } if (stat.q >= 95) { return
{stat.q}%
; } else { return
{stat.q}%
; } }; const content = () => { if (!data) { return ; } return ( {(tableList: Stat[]) => ( <>
{LL.SUCCESS()} {LL.FAIL()} {LL.QUALITY()}
{tableList.map((stat: Stat) => ( {showName(stat.id)} {Intl.NumberFormat().format(stat.s)} {Intl.NumberFormat().format(stat.f)} {showQuality(stat)} ))} )}
); }; return {content()}; }; export default SystemActivity;