Optimize sort and filter in log page
This commit is contained in:
9
src/ant-design.d.ts
vendored
9
src/ant-design.d.ts
vendored
@@ -1,14 +1,17 @@
|
|||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import { CustomIconComponentProps } from '@ant-design/icons/es/components/Icon'
|
import { CustomIconComponentProps } from '@ant-design/icons/es/components/Icon'
|
||||||
import { TablePaginationConfig } from 'antd/lib'
|
import { TablePaginationConfig } from 'antd/lib'
|
||||||
import { FilterValue } from 'antd/es/table/interface'
|
import { ColumnsType, FilterValue, SorterResult, SortOrder } from 'antd/es/table/interface'
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
type IconComponent =
|
type IconComponent =
|
||||||
| React.ComponentType<CustomIconComponentProps | React.SVGProps<SVGSVGElement>>
|
| React.ComponentType<CustomIconComponentProps | React.SVGProps<SVGSVGElement>>
|
||||||
| React.ForwardRefExoticComponent<CustomIconComponentProps>
|
| React.ForwardRefExoticComponent<CustomIconComponentProps>
|
||||||
|
|
||||||
type PaginationConfig = TablePaginationConfig
|
type _TablePaginationConfig = TablePaginationConfig
|
||||||
|
|
||||||
type FilterVal = FilterValue
|
type _ColumnsType<T> = ColumnsType<T>
|
||||||
|
type _FilterValue = FilterValue
|
||||||
|
type _SorterResult<T> = SorterResult<T>
|
||||||
|
type _SortOrder = SortOrder
|
||||||
}
|
}
|
||||||
|
|||||||
8
src/global.d.ts
vendored
8
src/global.d.ts
vendored
@@ -157,12 +157,14 @@ interface PageVo<T> {
|
|||||||
interface PageParam {
|
interface PageParam {
|
||||||
currentPage?: number
|
currentPage?: number
|
||||||
pageSize?: number
|
pageSize?: number
|
||||||
|
sortField?: string
|
||||||
|
sortOrder?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TableParams {
|
interface TableParams {
|
||||||
pagination?: PaginationConfig
|
pagination?: _TablePaginationConfig
|
||||||
sortField?: string
|
sortField?: React.Key | readonly React.Key[]
|
||||||
sortOrder?: string
|
sortOrder?: _SortOrder
|
||||||
filters?: Record<string, FilterVal | null>
|
filters?: Record<string, FilterVal | null>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { ColumnsType, FilterValue, SorterResult } from 'antd/es/table/interface'
|
|
||||||
import { TablePaginationConfig } from 'antd/lib'
|
|
||||||
import FitFullScreen from '@/components/common/FitFullScreen.tsx'
|
import FitFullScreen from '@/components/common/FitFullScreen.tsx'
|
||||||
import Card from '@/components/common/Card'
|
import Card from '@/components/common/Card'
|
||||||
import { r_getSysLog } from '@/services/system.tsx'
|
import { r_getSysLog } from '@/services/system.tsx'
|
||||||
@@ -20,7 +18,7 @@ const Log: React.FC = () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const dataColumns: ColumnsType<SysLogGetVo> = [
|
const dataColumns: _ColumnsType<SysLogGetVo> = [
|
||||||
{
|
{
|
||||||
title: '类型',
|
title: '类型',
|
||||||
dataIndex: 'logType',
|
dataIndex: 'logType',
|
||||||
@@ -30,7 +28,11 @@ const Log: React.FC = () => {
|
|||||||
) : (
|
) : (
|
||||||
<AntdTag>{value}</AntdTag>
|
<AntdTag>{value}</AntdTag>
|
||||||
),
|
),
|
||||||
align: 'center'
|
align: 'center',
|
||||||
|
filters: [
|
||||||
|
{ text: 'Info', value: 'INFO' },
|
||||||
|
{ text: 'Error', value: 'ERROR' }
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '操作者',
|
title: '操作者',
|
||||||
@@ -43,59 +45,93 @@ const Log: React.FC = () => {
|
|||||||
<AntdTag>Anonymous</AntdTag>
|
<AntdTag>Anonymous</AntdTag>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: '操作时间',
|
|
||||||
dataIndex: 'operateTime',
|
|
||||||
render: (value: string) => getLocalTime(value),
|
|
||||||
align: 'center'
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
title: '请求方式',
|
title: '请求方式',
|
||||||
dataIndex: 'requestMethod',
|
dataIndex: 'requestMethod',
|
||||||
align: 'center'
|
align: 'center',
|
||||||
|
filters: [
|
||||||
|
{ text: 'GET', value: 'GET' },
|
||||||
|
{ text: 'POST', value: 'POST' },
|
||||||
|
{ text: 'PUT', value: 'PUT' },
|
||||||
|
{ text: 'PATCH', value: 'PATCH' },
|
||||||
|
{ text: 'DELETE', value: 'DELETE' },
|
||||||
|
{ text: 'HEAD', value: 'HEAD' },
|
||||||
|
{ text: 'OPTIONS', value: 'OPTIONS' }
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '请求 Url',
|
title: '请求 Url',
|
||||||
render: (_value, record) =>
|
render: (_value, record) =>
|
||||||
`${record.requestServerAddress}${record.requestUri}${
|
`${record.requestServerAddress}${record.requestUri}${
|
||||||
record.requestParams ? `?${record.requestParams}` : ''
|
record.requestParams ? `?${record.requestParams}` : ''
|
||||||
}`
|
}`,
|
||||||
|
onCell: () => ({
|
||||||
|
style: {
|
||||||
|
wordBreak: 'break-word'
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '请求 IP',
|
title: '请求 IP',
|
||||||
dataIndex: 'requestIp',
|
dataIndex: 'requestIp',
|
||||||
align: 'center'
|
align: 'center'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: '开始时间',
|
||||||
|
dataIndex: 'startTime',
|
||||||
|
render: (value: string) => getLocalTime(value),
|
||||||
|
align: 'center',
|
||||||
|
sorter: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '执行时间',
|
||||||
|
dataIndex: 'executeTime',
|
||||||
|
render: (value, record) => (
|
||||||
|
<AntdTooltip
|
||||||
|
title={`${getLocalTime(record.startTime)} ~ ${getLocalTime(record.endTime)}`}
|
||||||
|
>
|
||||||
|
{`${value}ms`}
|
||||||
|
</AntdTooltip>
|
||||||
|
),
|
||||||
|
align: 'center',
|
||||||
|
sorter: true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: '异常',
|
title: '异常',
|
||||||
dataIndex: 'exception',
|
dataIndex: 'exception',
|
||||||
render: (value: boolean, record) => (value ? record.exceptionInfo : '无'),
|
render: (value: boolean, record) => (value ? record.exceptionInfo : '无'),
|
||||||
align: 'center'
|
align: 'center'
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: '执行时间',
|
|
||||||
dataIndex: 'executeTime',
|
|
||||||
render: (value, record) => (
|
|
||||||
<AntdTooltip
|
|
||||||
title={`${getLocalTime(record.startTime)} - ${getLocalTime(record.endTime)}`}
|
|
||||||
>
|
|
||||||
{`${value}ms`}
|
|
||||||
</AntdTooltip>
|
|
||||||
),
|
|
||||||
align: 'center'
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
title: '用户代理',
|
title: '用户代理',
|
||||||
dataIndex: 'userAgent'
|
dataIndex: 'userAgent',
|
||||||
|
onCell: () => ({
|
||||||
|
style: {
|
||||||
|
wordBreak: 'break-word'
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
const handleOnTableChange = (
|
const handleOnTableChange = (
|
||||||
pagination: TablePaginationConfig,
|
pagination: _TablePaginationConfig,
|
||||||
filters: Record<string, FilterValue | null>,
|
filters: Record<string, _FilterValue | null>,
|
||||||
sorter: SorterResult<SysLogGetVo> | SorterResult<SysLogGetVo>[]
|
sorter: _SorterResult<SysLogGetVo> | _SorterResult<SysLogGetVo>[]
|
||||||
) => {
|
) => {
|
||||||
setTableParams({ pagination, filters, ...sorter })
|
if (Array.isArray(sorter)) {
|
||||||
|
setTableParams({
|
||||||
|
pagination,
|
||||||
|
filters,
|
||||||
|
sortField: sorter.map((value) => value.field).join(',')
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
setTableParams({
|
||||||
|
pagination,
|
||||||
|
filters,
|
||||||
|
sortField: sorter.field,
|
||||||
|
sortOrder: sorter.order
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (pagination.pageSize !== tableParams.pagination?.pageSize) {
|
if (pagination.pageSize !== tableParams.pagination?.pageSize) {
|
||||||
setLogData([])
|
setLogData([])
|
||||||
@@ -107,10 +143,20 @@ const Log: React.FC = () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
void r_getSysLog({
|
void r_getSysLog(
|
||||||
|
tableParams.sortField && tableParams.sortOrder
|
||||||
|
? {
|
||||||
|
currentPage: tableParams.pagination?.current,
|
||||||
|
pageSize: tableParams.pagination?.pageSize,
|
||||||
|
sortField: tableParams.sortField as string,
|
||||||
|
sortOrder: tableParams.sortOrder,
|
||||||
|
...tableParams.filters
|
||||||
|
}
|
||||||
|
: {
|
||||||
currentPage: tableParams.pagination?.current,
|
currentPage: tableParams.pagination?.current,
|
||||||
pageSize: tableParams.pagination?.pageSize
|
pageSize: tableParams.pagination?.pageSize
|
||||||
})
|
}
|
||||||
|
)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const data = res.data
|
const data = res.data
|
||||||
if (data.code === DATABASE_SELECT_SUCCESS) {
|
if (data.code === DATABASE_SELECT_SUCCESS) {
|
||||||
|
|||||||
Reference in New Issue
Block a user