Complete main UI #37

Merged
FatttSnake merged 192 commits from FatttSnake into dev 2024-02-23 16:31:17 +08:00
2 changed files with 58 additions and 11 deletions
Showing only changes of commit 810c301398 - Show all commits

View File

@@ -18,7 +18,7 @@ import { TopLevelFormatterParams } from 'echarts/types/dist/shared'
import '@/assets/css/pages/system/index.scss' import '@/assets/css/pages/system/index.scss'
import { useUpdatedEffect } from '@/util/hooks' import { useUpdatedEffect } from '@/util/hooks'
import { formatByteSize } from '@/util/common' import { formatByteSize } from '@/util/common'
import { utcToLocalTime } from '@/util/datetime' import { getTimesBetweenTwoTimes, utcToLocalTime } from '@/util/datetime'
import { import {
r_sys_statistic_active, r_sys_statistic_active,
r_sys_statistic_cpu, r_sys_statistic_cpu,
@@ -223,7 +223,17 @@ const OnlineInfo: React.FC = () => {
setCurrentOnlineCount(data.current) setCurrentOnlineCount(data.current)
setTimeout(() => { setTimeout(() => {
const dataList = data.history.map((value) => [value.time, value.record]) const dataList = getTimesBetweenTwoTimes(
data.history[0].time,
data.history[data.history.length - 1].time,
'minute'
).map((time) => [
time,
data.history.find(
(value) => value.time.substring(0, 16) === time.substring(0, 16)
)?.record ?? 0
])
onlineInfoEChartsRef.current = echarts.init( onlineInfoEChartsRef.current = echarts.init(
onlineInfoDivRef.current, onlineInfoDivRef.current,
null, null,
@@ -342,14 +352,32 @@ const ActiveInfo: React.FC = () => {
setIsLoading(false) setIsLoading(false)
setTimeout(() => { setTimeout(() => {
const registerList = data.registerHistory.map((value) => [ const registerList = data.registerHistory.length
value.time, ? getTimesBetweenTwoTimes(
value.count data.registerHistory[0].time,
data.registerHistory[data.registerHistory.length - 1].time,
'day'
).map((time) => [
time,
data.registerHistory.find(
(value) =>
value.time.substring(0, 10) === time.substring(0, 10)
)?.count ?? 0
]) ])
const loginList = data.loginHistory.map((value) => [ : []
value.time, const loginList = data.loginHistory.length
value.count ? getTimesBetweenTwoTimes(
data.loginHistory[0].time,
data.loginHistory[data.loginHistory.length - 1].time,
'day'
).map((time) => [
time,
data.loginHistory.find(
(value) =>
value.time.substring(0, 10) === time.substring(0, 10)
)?.count ?? 0
]) ])
: []
activeInfoEChartsRef.current = echarts.init( activeInfoEChartsRef.current = echarts.init(
activeInfoDivRef.current, activeInfoDivRef.current,

View File

@@ -1,4 +1,4 @@
import moment from 'moment/moment' import moment, { unitOfTime } from 'moment/moment'
import dayjs from 'dayjs' import dayjs from 'dayjs'
export const getNowLocalTime = (format: string = 'yyyy-MM-DD HH:mm:ssZ') => { export const getNowLocalTime = (format: string = 'yyyy-MM-DD HH:mm:ssZ') => {
@@ -36,3 +36,22 @@ export const utcToMillisecond = (utcTime: string) => {
export const millisecondToUtc = (millisecond: number) => { export const millisecondToUtc = (millisecond: number) => {
return moment(millisecond).toISOString() return moment(millisecond).toISOString()
} }
export const getTimesBetweenTwoTimes = (
startTime: string,
endTime: string,
interval: unitOfTime.Diff
) => {
const timesList: string[] = []
const start = moment.utc(startTime)
const end = moment.utc(endTime)
const count = end.diff(start, interval)
timesList.push(start.toISOString())
for (let i = 0; i < count; i++) {
timesList.push(start.add(1, interval).toISOString())
}
return timesList
}