fix(market): 1.修复模型超市 模糊搜索-模型名称异常的问题

feat(table): 2.新增三中心表格统一策略:

- 覆盖 `/user-center/*`、`/org/*`、`/console/*`,包含系统设置。
- 自动识别最后一列的创建、查看、编辑、测试、详情、删除、设置、弹窗、API 回调等交互。
- 操作列统一显示“操作”,固定在右侧。
- 根据按钮和文字实际宽度测量,保持操作文字单行显示。
- 非操作宽表自动固定右侧末 4 / 3 / 2 / 1 列。
- 保留 Ant Design 官方横向滚动行为,不隐藏滚动条。
This commit is contained in:
zhanjunhao
2026-11-17 10:10:28 +08:00
parent 93128a77d3
commit 34a7eca5c7
25 changed files with 595 additions and 41 deletions
+1 -1
View File
@@ -18,6 +18,7 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React, { forwardRef } from 'react';
import Table from '../ui/CenterActionTable';
import {
Alert,
Button,
@@ -26,7 +27,6 @@ import {
Empty,
Form,
Modal,
Table,
Tabs,
theme,
} from 'antd';
@@ -18,7 +18,8 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React, { useState } from 'react';
import { Modal, Button, Input, Table, Tag, Typography, Select } from 'antd';
import Table from '../../../ui/CenterActionTable';
import { Modal, Button, Input, Tag, Typography, Select } from 'antd';
import { Search } from 'lucide-react';
import { copy, showError, showInfo, showSuccess } from '../../../../helpers';
import { MODEL_TABLE_PAGE_SIZE } from '../../../../constants';
@@ -19,7 +19,8 @@ For commercial licensing, please contact support@quantumnous.com
import TableEmpty from '../../common/table/TableEmpty';
import React, { useMemo, useState } from 'react';
import { Button as AntButton, Table as AntTable } from 'antd';
import AntTable from '../../ui/CenterActionTable';
import { Button as AntButton } from 'antd';
import { Modal, Typography } from '@/components/ui';
import {
Coins,
+143
View File
@@ -0,0 +1,143 @@
/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { forwardRef, useLayoutEffect, useRef, useState } from 'react';
import { Table, theme } from 'antd';
import { colord } from 'colord';
import { isCenterTableScope, prepareCenterColumns } from './centerTablePolicy';
import './center-table.css';
const CenterTable = forwardRef(function CenterTable(
{ columns, className, scroll, style, ...props },
ref,
) {
const { token } = theme.useToken();
const base = colord(token.colorBgContainer).toRgb();
const solidColor = (color) => {
const value = colord(color).toRgb();
return colord({
r: value.r * value.a + base.r * (1 - value.a),
g: value.g * value.a + base.g * (1 - value.a),
b: value.b * value.a + base.b * (1 - value.a),
a: 1,
}).toRgbString();
};
const tableRef = useRef(null);
const [width, setWidth] = useState(0);
const [measuredActionWidths, setMeasuredActionWidths] = useState({});
const scoped = isCenterTableScope(
typeof window === 'undefined' ? '' : window.location.pathname,
);
const prepared =
scoped && columns
? prepareCenterColumns(columns, width, measuredActionWidths)
: columns;
const enabled = prepared !== columns;
useLayoutEffect(() => {
if (!enabled) return;
const root = tableRef.current?.nativeElement;
if (!root) return;
const scroller = root.querySelector('.ant-table-content,.ant-table-body');
const previousTabIndex = scroller?.getAttribute('tabindex');
if (scroller && previousTabIndex === null) scroller.tabIndex = 0;
const update = () => setWidth(root.clientWidth);
update();
const measureActionWidths = () => {
const next = {};
root.querySelectorAll('th.center-action-cell').forEach((header) => {
const marker = [...header.classList].find((name) =>
name.startsWith('center-fixed-index-'),
);
if (!marker) return;
const cells = [...root.querySelectorAll(`td.${marker}`)].filter(
(element) => element.getBoundingClientRect().width > 0,
);
const cell = cells.find((candidate) =>
candidate.querySelector('button, a, [role="button"]'),
);
const controls = cell
? [...cell.querySelectorAll('button, a, [role="button"]')].filter(
(element) => element.getBoundingClientRect().width > 0,
)
: [];
const cellStyle = getComputedStyle(cell || header);
const padding =
(Number.parseFloat(cellStyle.paddingLeft) || 0) +
(Number.parseFloat(cellStyle.paddingRight) || 0);
const gap = Number.parseFloat(cellStyle.columnGap) || 8;
const contentWidth = controls.length
? controls.reduce(
(total, element) => total + element.getBoundingClientRect().width,
0,
) +
gap * Math.max(0, controls.length - 1)
: Math.max(...cells.map((candidate) => candidate.scrollWidth), 0) -
padding;
next[marker.replace('center-fixed-index-', '')] =
contentWidth + padding;
});
setMeasuredActionWidths((current) => {
const same =
Object.keys(next).length === Object.keys(current).length &&
Object.keys(next).every(
(key) => Math.abs(next[key] - current[key]) < 1,
);
return same ? current : next;
});
};
requestAnimationFrame(measureActionWidths);
const observer = new ResizeObserver(update);
observer.observe(root);
return () => {
observer.disconnect();
if (scroller && previousTabIndex === null)
scroller.removeAttribute('tabindex');
};
}, [enabled, width]);
return (
<Table
{...props}
ref={(instance) => {
tableRef.current = instance;
if (typeof ref === 'function') ref(instance);
else if (ref) ref.current = instance;
}}
columns={prepared}
className={[className, enabled && 'center-action-table']
.filter(Boolean)
.join(' ')}
scroll={enabled ? { ...scroll, x: scroll?.x || 'max-content' } : scroll}
style={
enabled
? {
'--center-table-bg': token.colorBgContainer,
'--center-table-head-bg': solidColor(token.colorFillAlter),
'--center-table-hover-bg': solidColor(token.controlItemBgHover),
'--center-table-selected-bg': solidColor(
token.controlItemBgActive,
),
...style,
}
: style
}
/>
);
});
export default CenterTable;
+55
View File
@@ -0,0 +1,55 @@
.center-action-table {
min-width: 0;
max-width: 100%;
}
.center-action-table .ant-table-tbody > tr > .center-fixed-cell {
z-index: 2;
background: var(--center-table-bg);
background-clip: padding-box;
}
.center-action-table .ant-table-thead > tr > .center-fixed-cell {
z-index: 3;
background: var(--ur-head-bg, var(--center-table-head-bg));
background-clip: padding-box;
}
.center-action-table .ant-table-tbody > tr:hover > .center-fixed-cell {
background: var(--center-table-hover-bg);
}
.center-action-table
.ant-table-tbody
> tr.ant-table-row-selected
> .center-fixed-cell {
background: var(--center-table-selected-bg);
}
.center-action-table .center-fixed-cell {
white-space: normal;
overflow-wrap: anywhere;
}
.center-action-table .center-action-cell {
white-space: nowrap;
}
.center-action-table
.center-action-cell
:where(
.ant-space,
.ant-flex,
.flex,
.km-actions,
.oc-row-actions,
.org-row-actions,
.console-module-row-actions,
.console-channel-key-actions,
.console-channel-model-actions,
.admin-tokens-row-actions,
.website-insights-row-actions
) {
flex-wrap: nowrap;
max-width: none;
}
+133
View File
@@ -0,0 +1,133 @@
/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import i18next from 'i18next';
export const isCenterTableScope = (pathname) =>
/^\/(user-center|org|console)(\/|$)/.test(pathname || '');
const titleText = (title) => {
if (typeof title === 'string') return title.trim();
if (Array.isArray(title)) return title.map(titleText).join('');
return title?.props ? titleText(title.props.children) : '';
};
export function isActionColumn(column) {
const title = titleText(column.title);
const key = String(column.key ?? column.dataIndex ?? '');
const source =
typeof column.render === 'function' ? column.render.toString() : '';
const titleSignal =
/^(操作|计费详情|编辑|测试|删除|添加|新增|设置|配置|创建|管理|actions?|operate|operations?)$/i.test(
title,
);
const detailTitleSignal = /^(详情|查看|打开|预览|结果|失败原因)$/i.test(
title,
);
const keySignal =
/^(actions|operate|operations|billingDetailAction|fail_reason|details?)$/i.test(
key,
) && typeof column.render === 'function';
const interactionSignal =
/\b(?:onClick|onOpen|onChange|Modal|Drawer|Popconfirm|Dropdown|Button|Link|API|request|fetch|navigate)\b/i.test(
source,
);
return Boolean(
titleSignal ||
keySignal ||
interactionSignal ||
(detailTitleSignal && (interactionSignal || key === 'fail_reason')),
);
}
const leafColumns = (columns) =>
columns.flatMap((column) =>
column.children ? leafColumns(column.children) : [column],
);
const columnTitleWidth = (column) => {
const title = titleText(column.title);
return Math.max(96, Math.min(260, 32 + [...title].length * 14));
};
const columnWidth = (column) => {
const width = Number(column.width);
return Number.isFinite(width) && width > 0 ? width : columnTitleWidth(column);
};
const actionWidth = (column, measuredWidth) => {
if (Number.isFinite(measuredWidth) && measuredWidth > 0)
return Math.ceil(Math.min(360, Math.max(56, measuredWidth)));
const source =
typeof column.render === 'function' ? column.render.toString() : '';
const count = (
source.match(
/<\s*(?:Button|Link|Dropdown|Popconfirm)\b|\b(?:Button|Link|Dropdown|Popconfirm|onClick|onOpen|onChange)\b/gi,
) || []
).length;
return Math.min(360, Math.max(56, 32 + Math.max(1, count) * 44));
};
const markFixedRight = (
column,
index,
action = false,
measuredWidths = {},
) => ({
...column,
fixed: 'right',
width: action
? actionWidth(column, measuredWidths[index])
: columnWidth(column),
...(action ? { title: i18next.t('操作') || '操作' } : {}),
className: [
column.className,
'center-fixed-cell',
action && 'center-action-cell',
`center-fixed-index-${index}`,
]
.filter(Boolean)
.join(' '),
});
export function prepareCenterColumns(columns, width = 0, measuredWidths = {}) {
const leaves = leafColumns(columns);
const last = leaves.at(-1);
const hasAction = last && isActionColumn(last);
const estimatedTotal = leaves.reduce(
(total, column) => total + columnWidth(column),
0,
);
const overflow = width > 0 && estimatedTotal > width;
const fixedCount = Math.max(1, Math.min(4, leaves.length));
const fallback =
!hasAction && overflow ? new Set(leaves.slice(-fixedCount)) : new Set();
let index = 0;
return columns.map(function mapColumn(column) {
if (column.children)
return { ...column, children: column.children.map(mapColumn) };
const columnIndex = index++;
if (hasAction && column === last)
return markFixedRight(column, columnIndex, true, measuredWidths);
if (fallback.has(column)) return markFixedRight(column, columnIndex);
if (column.fixed) return { ...column, width: columnWidth(column) };
return column;
});
}
+2 -1
View File
@@ -28,6 +28,7 @@ import {
paginationShowTotal,
} from './pagination';
import { overlayMask } from './overlayPolicy';
import CenterTable from './CenterActionTable';
import './pagination.css';
import { useIsMobile } from '../../hooks/common/useIsMobile';
import { useConsolePage } from '../console/ConsoleContext';
@@ -293,7 +294,7 @@ export function Table({
...props
}) {
const consolePage = useConsolePage();
const BaseTable = consolePage ? ConsoleTable : Ant.Table;
const BaseTable = consolePage ? ConsoleTable : CenterTable;
const unified = Boolean(pagination) && isCenterPaginationScope();
const Component = unified ? CenterPaginatedTable : BaseTable;
const expandable = expandedRowRender
@@ -157,17 +157,12 @@ export const useModelPricingData = () => {
}
// 搜索筛选
if (searchValue.length > 0) {
const searchTerm = searchValue.toLowerCase();
if (searchValue.trim().length > 0) {
const searchTerm = searchValue.trim().toLowerCase();
result = result.filter(
(model) =>
(model.model_name &&
model.model_name.toLowerCase().includes(searchTerm)) ||
(model.description &&
model.description.toLowerCase().includes(searchTerm)) ||
(model.tags && model.tags.toLowerCase().includes(searchTerm)) ||
(model.vendor_name &&
model.vendor_name.toLowerCase().includes(searchTerm)),
typeof model.model_name === 'string' &&
model.model_name.toLowerCase().includes(searchTerm),
);
}
+1 -1
View File
@@ -29,6 +29,7 @@ import {
import { writeClipboardText } from '../../helpers/clipboard';
import TableEmpty from '../../components/common/table/TableEmpty';
import React, { useState, useRef, useEffect, useContext } from 'react';
import Table from '../../components/ui/CenterActionTable';
import {
Alert,
Button,
@@ -38,7 +39,6 @@ import {
Input,
Spin,
Switch,
Table,
Tag,
Tooltip,
} from 'antd';
@@ -23,7 +23,8 @@ import {
} from '@/components/common/icons/ActionIcons';
import TableEmpty from '../../../components/common/table/TableEmpty';
import React, { useMemo } from 'react';
import { Card, Table, Tag } from 'antd';
import Table from '../../../components/ui/CenterActionTable';
import { Card, Tag } from 'antd';
import { Clock } from 'lucide-react';
import { Button, Pagination } from '@/components/ui';
import { useTaskLogsData } from '../../../hooks/task-logs/useTaskLogsData';
+2 -10
View File
@@ -23,16 +23,8 @@ import {
RefreshCw as ActionRefreshCw,
} from '@/components/common/icons/ActionIcons';
import React, { useState, useEffect, useCallback, useMemo } from 'react';
import {
Empty,
Spin,
Table,
Button,
Modal,
Tooltip,
Statistic,
theme,
} from 'antd';
import Table from '../../components/ui/CenterActionTable';
import { Empty, Spin, Button, Modal, Tooltip, Statistic, theme } from 'antd';
import { Server, ChevronRight, Clock } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { API, showError } from '../../helpers';
+3 -7
View File
@@ -6,7 +6,7 @@
.usage-record-page {
--ur-card-border: #e6e9ef;
--ur-card-shadow: 0 4px 24px rgba(15, 23, 42, 0.02);
--ur-filter-bg: linear-gradient(90deg, #fffdf8 0%, #ffffff 55%);
--ur-filter-bg: var(--surface-card);
--ur-label: #6b7789;
--ur-head-bg: #f8f9fc;
--ur-head-text: #687589;
@@ -29,13 +29,9 @@
html.dark .usage-record-page {
--ur-card-border: var(--border-subtle);
--ur-card-shadow: none;
--ur-filter-bg: linear-gradient(
90deg,
color-mix(in srgb, var(--ui-color-primary) 6%, var(--surface-card)) 0%,
var(--surface-card) 55%
);
--ur-filter-bg: var(--surface-card);
--ur-label: var(--text-secondary);
--ur-head-bg: var(--ui-color-fill-0);
--ur-head-bg: color-mix(in srgb, var(--text-primary) 4%, var(--surface-card));
--ur-head-text: var(--text-secondary);
--ur-row-split: var(--border-subtle);
--ur-time-date: var(--text-secondary);