Add scope select to online statistic

This commit is contained in:
2023-12-19 10:25:20 +08:00
parent 33368f7f89
commit 9b1beed8b5
3 changed files with 37 additions and 7 deletions

View File

@@ -156,6 +156,7 @@ const OnlineInfo: React.FC = () => {
const onlineInfoEChartsRef = useRef<echarts.EChartsType | null>(null)
const [isLoading, setIsLoading] = useState(false)
const [currentOnlineCount, setCurrentOnlineCount] = useState(-1)
const [scope, setScope] = useState('WEAK')
useUpdatedEffect(() => {
const chartResizeObserver = new ResizeObserver(() => {
@@ -173,14 +174,23 @@ const OnlineInfo: React.FC = () => {
getOnlineInfo()
}, [])
const getOnlineInfo = () => {
const handleOnScopeChange = (value: string) => {
setScope(value)
getOnlineInfo(value)
}
const handleOnRefresh = () => {
getOnlineInfo()
}
const getOnlineInfo = (_scope: string = scope) => {
if (isLoading) {
return
}
setIsLoading(true)
void r_sys_statistic_online().then((res) => {
void r_sys_statistic_online({ scope: _scope }).then((res) => {
const response = res.data
if (response.success) {
const data = response.data
@@ -224,15 +234,30 @@ const OnlineInfo: React.FC = () => {
<>
<FlexBox gap={10} direction={'horizontal'}>
<span style={{ whiteSpace: 'nowrap' }}>线</span>
<AntdTag> {currentOnlineCount}</AntdTag>
<AntdTag>
{currentOnlineCount === -1 ? '获取中...' : currentOnlineCount}
</AntdTag>
</FlexBox>
</>
}
loading={isLoading}
expand={
<AntdButton title={'刷新'} onClick={() => getOnlineInfo()}>
<Icon component={IconFatwebRefresh} />
</AntdButton>
<>
<AntdSelect value={scope} onChange={handleOnScopeChange} disabled={isLoading}>
<AntdSelect.Option key={'DAY'}></AntdSelect.Option>
<AntdSelect.Option key={'WEAK'}>7</AntdSelect.Option>
<AntdSelect.Option key={'MONTH'}>30</AntdSelect.Option>
<AntdSelect.Option key={'QUARTER'}>3</AntdSelect.Option>
<AntdSelect.Option key={'YEAR'}>12</AntdSelect.Option>
<AntdSelect.Option key={'TWO_YEARS'}>2</AntdSelect.Option>
<AntdSelect.Option key={'THREE_YEARS'}>3</AntdSelect.Option>
<AntdSelect.Option key={'FIVE_YEARS'}>5</AntdSelect.Option>
<AntdSelect.Option key={'ALL'}></AntdSelect.Option>
</AntdSelect>
<AntdButton title={'刷新'} onClick={handleOnRefresh} disabled={isLoading}>
<Icon component={IconFatwebRefresh} />
</AntdButton>
</>
}
>
<FlexBox className={'card-content'} direction={'horizontal'}>