From de008edc6843a67be6b2c97fe70d5a3731977139 Mon Sep 17 00:00:00 2001 From: scarqin Date: Wed, 25 Dec 2024 16:51:41 +0800 Subject: [PATCH] feat: pagination and search api --- .../src/components/aoplatform/PageList.tsx | 83 +++++++++------- .../keySettings/components/ApiKeyModal.tsx | 26 +++-- .../core/src/pages/keySettings/index.tsx | 96 ++++++++++--------- .../core/src/pages/system/SystemList.tsx | 25 +++-- 4 files changed, 120 insertions(+), 110 deletions(-) diff --git a/frontend/packages/common/src/components/aoplatform/PageList.tsx b/frontend/packages/common/src/components/aoplatform/PageList.tsx index 43530e26..5e41f1b2 100644 --- a/frontend/packages/common/src/components/aoplatform/PageList.tsx +++ b/frontend/packages/common/src/components/aoplatform/PageList.tsx @@ -1,4 +1,12 @@ +import { SearchOutlined } from '@ant-design/icons' +import type { ActionType, ParamsType, ProColumns, ProTableProps } from '@ant-design/pro-components' +import { DragSortTable, ProTable } from '@ant-design/pro-components' +import WithPermission from '@common/components/aoplatform/WithPermission' +import { PERMISSION_DEFINITION } from '@common/const/permissions' +import { withMinimumDelay } from '@common/utils/ux' import { Button, Dropdown, Input, MenuProps, TablePaginationConfig } from 'antd' +import { FilterValue, SorterResult, TableCurrentDataSource } from 'antd/es/table/interface' +import { debounce } from 'lodash-es' import { ChangeEvent, RefAttributes, @@ -9,16 +17,8 @@ import { useRef, useState } from 'react' -import type { ActionType, ParamsType, ProColumns, ProTableProps } from '@ant-design/pro-components' -import { DragSortTable, ProTable } from '@ant-design/pro-components' -import './PageList.module.css' -import { SearchOutlined } from '@ant-design/icons' -import { debounce } from 'lodash-es' -import WithPermission from '@common/components/aoplatform/WithPermission' -import { FilterValue, SorterResult, TableCurrentDataSource } from 'antd/es/table/interface' import { useGlobalContext } from '../../contexts/GlobalStateContext' -import { PERMISSION_DEFINITION } from '@common/const/permissions' -import { withMinimumDelay } from '@common/utils/ux' +import './PageList.module.css' export type PageProColumns = ProColumns & { btnNums?: number } @@ -104,7 +104,6 @@ const PageList = >( const { accessData, checkPermission, accessInit, state } = useGlobalContext() const [minTableWidth, setMinTableWidth] = useState(0) - // 使用useImperativeHandle来自定义暴露给父组件的实例值 useImperativeHandle(ref, () => actionRef.current!) useEffect(() => { @@ -209,6 +208,32 @@ const PageList = >( ) } + const getTableActions = () => { + return [ + ...(beforeSearchNode ? [beforeSearchNode] : []), + ...(searchPlaceholder + ? [ + debounce(onSearchWordChange, 100)(e) : undefined} + onPressEnter={() => (manualReloadTable ? manualReloadTable() : actionRef.current?.reload?.())} + allowClear + placeholder={searchPlaceholder} + prefix={ + { + actionRef.current?.reload?.() + }} + /> + } + /> + ] + : []) + ] + } + const requestWithDelay = ( params: ParamsType & { pageSize?: number | undefined; current?: number | undefined; keyword?: string | undefined }, sort: unknown, @@ -229,7 +254,15 @@ const PageList = >( columns={newColumns} rowKey={primaryKey} search={false} - pagination={false} + pagination={ + showPagination + ? { + showSizeChanger: true, + showQuickJumper: true, + size: 'default' + } + : false + } request={request} dragSortKey={dragSortKey} onDragSortEnd={onDragSortEnd} @@ -239,6 +272,9 @@ const PageList = >( density: false, setting: false }} + toolbar={{ + actions: getTableActions() + }} headerTitle={headerTitle()} /> ) : ( @@ -260,28 +296,7 @@ const PageList = >( ) : null ]} toolbar={{ - actions: [ - ...[beforeSearchNode], - ...[ - searchPlaceholder ? ( - debounce(onSearchWordChange, 100)(e) : undefined} - onPressEnter={() => (manualReloadTable ? manualReloadTable() : actionRef.current?.reload?.())} - allowClear - placeholder={searchPlaceholder} - prefix={ - { - actionRef.current?.reload?.() - }} - /> - } - /> - ) : null - ] - ] + actions: getTableActions() }} options={{ reload: false, @@ -304,7 +319,6 @@ const PageList = >( } : false } - rowKey={primaryKey} onChange={( pagination: TablePaginationConfig, filters: Record, @@ -319,6 +333,7 @@ const PageList = >( ) onChange?.(pagination, filters, sorter, extra) }} + rowKey={primaryKey} dataSource={dataSource} search={false} headerTitle={headerTitle()} diff --git a/frontend/packages/core/src/pages/keySettings/components/ApiKeyModal.tsx b/frontend/packages/core/src/pages/keySettings/components/ApiKeyModal.tsx index 23349e5a..c9ab7eff 100644 --- a/frontend/packages/core/src/pages/keySettings/components/ApiKeyModal.tsx +++ b/frontend/packages/core/src/pages/keySettings/components/ApiKeyModal.tsx @@ -76,7 +76,7 @@ const ApiKeyModal: React.FC = ({ return ( = ({ width={600} >
- + @@ -96,15 +92,15 @@ const ApiKeyModal: React.FC = ({ name="name" label={
- {$t('* API KEY')} + {$t('API Key')} {mode === 'add' && ( - {$t('Get API KEY from OpenAI')} + {$t('从 OpenAI 获取 API Key')} )}
} - rules={[{ required: true, message: $t('Please input the API key') }]} + rules={[{ required: true, message: $t('请输入 API Key') }]} > {mode === 'add' ? (