diff --git a/.github/workflows/backend-build.yml b/.github/workflows/backend-build.yml index 3db61c6..616dfdf 100644 --- a/.github/workflows/backend-build.yml +++ b/.github/workflows/backend-build.yml @@ -2,7 +2,7 @@ name: Backend Docker Build and Publish on: push: - branches: [main, master, workflow-dev] + branches: [main, master, workflow-dev, dev] paths: - "backend/**" tags: ["v*.*.*"] diff --git a/.github/workflows/frontend-build.yml b/.github/workflows/frontend-build.yml index bd985ae..ed8fe97 100644 --- a/.github/workflows/frontend-build.yml +++ b/.github/workflows/frontend-build.yml @@ -2,7 +2,7 @@ name: Frontend Docker Build and Publish on: push: - branches: [main, master, workflow-dev] + branches: [main, master, workflow-dev, dev] paths: - "frontend/**" tags: ["v*.*.*"] diff --git a/frontend/src/components/DataTable.tsx b/frontend/src/components/DataTable.tsx index bad437f..2982880 100644 --- a/frontend/src/components/DataTable.tsx +++ b/frontend/src/components/DataTable.tsx @@ -1,4 +1,4 @@ -import React, { ReactNode, useState, KeyboardEvent } from "react"; +import React, { ReactNode, useMemo, useState } from "react"; import { Table, TableHeader, @@ -19,7 +19,7 @@ import { DropdownSection, } from "@heroui/dropdown"; import { Tooltip } from "@heroui/tooltip"; -import { NumberInput } from "@heroui/number-input"; +import { Input } from "@heroui/input"; import LoadingSpinner from "./LoadingSpinner"; import ErrorDisplay from "./ErrorDisplay"; @@ -105,6 +105,8 @@ export interface DataTableProps { selectedKeys?: Selection; onSelectionChange?: (keys: Set) => void; selectionToolbarContent?: ReactNode; + showJumper?: boolean; + showCustomPageSize?: boolean; } // 通用DataTable组件 @@ -142,6 +144,8 @@ export const DataTable = ({ selectedKeys, onSelectionChange, selectionToolbarContent, + showJumper = true, + showCustomPageSize = true, }: DataTableProps) => { // 获取表头列 const headerColumns = React.useMemo(() => { @@ -155,25 +159,46 @@ export const DataTable = ({ // 每页行数 const pageSizeOptions = [5, 10, 15, 30, 50]; const [pageSizeSelectedKeys, setPageSizeSelectedKeys] = useState( - new Set([selectedSize.toString()]), + pageSizeOptions.includes(selectedSize) + ? new Set([selectedSize.toString()]) + : new Set(["custom"]), ); // 自定义页面大小 - const [customPageSize, setCustomPageSize] = useState(null); + const [customPageSize, setCustomPageSize] = useState( + selectedSize.toString(), + ); + + // 验证自定义页面大小的函数 + const validateCustomPageSize = (value: string): boolean => { + return ( + value.match(/^\d+$/) && + Number(value) >= minPageSize && + Number(value) <= maxPageSize + ); + }; + + // 判断自定义页面大小是否无效 + const isInvalidCustomPageSize = useMemo(() => { + return !validateCustomPageSize(customPageSize); + }, [customPageSize, minPageSize, maxPageSize]); // 处理自定义页面大小应用 const applyCustomPageSize = () => { - if ( - customPageSize === null || - customPageSize < minPageSize || - customPageSize > maxPageSize - ) { + if (isInvalidCustomPageSize) { return; } - setSize?.(customPageSize); - setPageSizeSelectedKeys(new Set([customPageSize.toString()])); - setCustomPageSize(selectedSize); + const customPageSizeNumber = Number(customPageSize); + + setSize?.(customPageSizeNumber); + if (pageSizeOptions.includes(customPageSizeNumber)) { + setPageSizeSelectedKeys(new Set([customPageSize])); + } else { + setPageSizeSelectedKeys(new Set(["custom"])); + } + + setCustomPageSize(customPageSize); onPageChange(1); }; @@ -191,7 +216,7 @@ export const DataTable = ({ {pages > 1 && ( @@ -300,6 +325,7 @@ export const DataTable = ({ if (key && key !== "custom") { setSize(Number(key)); setPageSizeSelectedKeys(new Set([key])); + setCustomPageSize(key); onPageChange(1); } }} @@ -309,59 +335,45 @@ export const DataTable = ({ {size} ))} - - { - e.preventDefault(); - e.stopPropagation(); - applyCustomPageSize(); - }} - > - 应用 - - } - startContent={ - { - if (value < minPageSize) { - return `页面大小不能小于 ${minPageSize}`; + {showCustomPageSize && ( + + { + e.preventDefault(); + e.stopPropagation(); + applyCustomPageSize(); + }} + > + 应用 + + } + startContent={ + maxPageSize) { - return `页面大小不能大于 ${maxPageSize}`; - } - - return null; - }} - value={customPageSize} - onKeyDown={handleKeyDown} - onValueChange={(value) => { - setCustomPageSize(value); - }} - /> - } - textValue="自定义页面大小" - /> - + errorMessage={`页面大小必须在 ${minPageSize} 到 ${maxPageSize} 之间`} + isInvalid={isInvalidCustomPageSize} + placeholder={`${minPageSize}-${maxPageSize}`} + radius="sm" + size="sm" + value={customPageSize} + onKeyDown={handleKeyDown} + onValueChange={setCustomPageSize} + /> + } + textValue="自定义页面大小" + /> + + )} )} @@ -396,6 +408,16 @@ export const DataTable = ({ selectionMode, selectedKeys, selectionToolbarContent, + pages, + setSize, + selectedSize, + pageSizeSelectedKeys, + customPageSize, + isInvalidCustomPageSize, + minPageSize, + maxPageSize, + applyCustomPageSize, + handleKeyDown, ]); // 渲染表格 diff --git a/frontend/src/components/endpoints/DetailDrawer.tsx b/frontend/src/components/endpoints/DetailDrawer.tsx index a1d77e6..8fabf77 100644 --- a/frontend/src/components/endpoints/DetailDrawer.tsx +++ b/frontend/src/components/endpoints/DetailDrawer.tsx @@ -251,6 +251,7 @@ const EndpointDetailDrawer = ({ renderCell={renderCell} selectedSize={size} setSize={setSize} + showCustomPageSize={false} title="可用模型" total={endpoint.ai_models.total} onPageChange={handlePageChange} diff --git a/frontend/src/components/models/DetailDrawer.tsx b/frontend/src/components/models/DetailDrawer.tsx index d913aad..aeec424 100644 --- a/frontend/src/components/models/DetailDrawer.tsx +++ b/frontend/src/components/models/DetailDrawer.tsx @@ -241,6 +241,7 @@ const ModelDetailDrawer = ({ id, isOpen, onClose }: ModelDetailProps) => { renderCell={renderCell} selectedSize={size} setSize={setSize} + showCustomPageSize={false} title="可用端点" total={model.endpoints.total} onPageChange={handlePageChange} diff --git a/frontend/src/pages/settings.tsx b/frontend/src/pages/settings.tsx index b4f4d79..9305577 100644 --- a/frontend/src/pages/settings.tsx +++ b/frontend/src/pages/settings.tsx @@ -178,34 +178,36 @@ const Settings = () => { - -

系统设置

-
-
-
- - setUpdateEndpointTaskInterval(Number(e.target.value)) - } - /> -
-
- + {isAdmin && ( + +

系统设置

+ +
+
+ + setUpdateEndpointTaskInterval(Number(e.target.value)) + } + /> +
+
+ +
-
- - + + + )}

账户信息