调整暂存帮助部分结构 & 简化获取当前用户IP代码
This commit is contained in:
@@ -15,7 +15,7 @@ import {useState} from 'react'
|
||||
import {statisticsResourceUsage} from '@/actions/dashboard'
|
||||
import {ExtraResp} from '@/lib/api'
|
||||
import {toast} from 'sonner'
|
||||
import {addDays, format} from 'date-fns'
|
||||
import {addDays, compareAsc, format, subDays} from 'date-fns'
|
||||
import {Label} from '@/components/ui/label'
|
||||
import {ChartConfig, ChartContainer} from '@/components/ui/chart'
|
||||
import {CartesianGrid, XAxis, YAxis, Tooltip, Area, AreaChart, Legend} from 'recharts'
|
||||
@@ -41,17 +41,12 @@ export default function Charts({initialData}: ChartsProps) {
|
||||
})
|
||||
const handler = form.handleSubmit(
|
||||
async (value) => {
|
||||
// 获取当前日期
|
||||
const today = new Date()
|
||||
// 计算7天前的日期
|
||||
const sevenDaysAgo = new Date()
|
||||
sevenDaysAgo.setDate(today.getDate() - 3)
|
||||
const sevenDaysAgo = subDays(today, 7)
|
||||
const res = {
|
||||
resource_no: value.resource_no ?? '',
|
||||
create_after: value.create_after ?? sevenDaysAgo,
|
||||
create_before: value.create_before ?? today,
|
||||
// create_after: value.create_after ? format(value.create_after, 'yyyy-MM-dd') : format(sevenDaysAgo, 'yyyy-MM-dd'),
|
||||
// create_before: value.create_before ? format(value.create_before, 'yyyy-MM-dd') : format(today, 'yyyy-MM-dd'),
|
||||
}
|
||||
|
||||
const resp = await statisticsResourceUsage(res)
|
||||
@@ -69,8 +64,7 @@ export default function Charts({initialData}: ChartsProps) {
|
||||
date: item.date,
|
||||
count: item.count,
|
||||
}))
|
||||
formattedData.sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime())
|
||||
|
||||
formattedData.sort((a, b) => compareAsc(a.date, b.date))
|
||||
setSubmittedData(formattedData)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -333,7 +333,7 @@ export default function WhitelistPage(props: WhitelistPageProps) {
|
||||
className="shrink-0"
|
||||
theme="outline"
|
||||
>
|
||||
{wait ? <Loader2 className="w-4 h-4 animate-spin"/> : '获取当前IP'}
|
||||
{wait ? <Loader2 className="w-4 h-4 animate-spin"/> : '使用当前IP'}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user