import RefreshIcon from '@mui/icons-material/Refresh'; import { Box, Button } from '@mui/material'; 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 { useRequest } from 'alova'; import { useEffect } from 'react'; import * as EMSESP from './api'; import type { Stat } from './types'; import type { Translation } from 'i18n/i18n-types'; import type { FC } from 'react'; import { ButtonRow, FormLoader, SectionContent, useLayoutTitle } from 'components'; import { useI18nContext } from 'i18n/i18n-react'; const SystemActivity: FC = () => { const { data: data, send: loadData, error } = useRequest(EMSESP.readActivity); const { LL } = useI18nContext(); useLayoutTitle(LL.ACTIVITY()); 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; } ` }); useEffect(() => { const timer = setInterval(() => loadData(), 30000); return () => { clearInterval(timer); }; }); const showName = (id: any) => { 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: any) => ( <>
{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;