fix(market): 修复模型名称模糊搜索并统一三中心表格操作列

统一用户中心、企业中心和控制台的操作列标题、宽度与右侧固定规则,并按表格宽度固定末列,保留横向滚动。
This commit is contained in:
zhanjunhao
2026-11-17 10:10:28 +08:00
parent 822d26c0dd
commit 3dc2624e00
25 changed files with 595 additions and 41 deletions
+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;
});
}