fix(market): 修复模型名称模糊搜索并统一三中心表格操作列
统一用户中心、企业中心和控制台的操作列标题、宽度与右侧固定规则,并按表格宽度固定末列,保留横向滚动。
This commit is contained in:
+11
-1
@@ -1,6 +1,6 @@
|
||||
# 变更记录(CHANGELOG)
|
||||
|
||||
> 状态:有效(持续追加) · 更新:2026-11-13 · 版本:v3.1
|
||||
> 状态:有效(持续追加) · 更新:2026-11-16 · 版本:v3.1
|
||||
|
||||
对现状仍有影响的功能与修复记录,按日期倒序。改造、迁移、优化等一次性过程不在此记录。
|
||||
|
||||
@@ -8,6 +8,16 @@
|
||||
|
||||
**记录规则**:每条写“范围、变更、影响、回滚、关联”五项;回滚优先 `git revert <提交>`,提交含多项改动时按文件还原(`git checkout <提交>^ -- <文件>`),不整仓 reset。本文不作为规则依据。
|
||||
|
||||
## 2026-11-16
|
||||
|
||||
### 修复 · 筛选卡纯色背景、模型名称搜索与三中心表格固定列
|
||||
|
||||
- **范围**:使用记录两个页签的筛选卡、`/market` 搜索,以及 `/user-center/*`、`/org/*`、`/console/*`(含系统设置)的操作表格。
|
||||
- **变更**:使用记录筛选卡移除渐变,浅色使用白色卡片底;模型搜索只匹配模型名称并忽略大小写与关键词首尾空格;三中心(含系统设置)识别末列交互并统一改为“操作”后固定右侧;无操作列且列宽超出容器时动态固定右侧末 4 / 3 / 2 / 1 列,恢复 Ant Design 官方横向滚动条。
|
||||
- **影响**:保留接口、载荷、权限、分页、筛选及操作回调;普通详情文本列不纳入操作列,固定单元格使用不透明底色并保持窄屏可读。
|
||||
- **回滚**:还原本次 `CenterActionTable`、`centerTablePolicy`、表格入口接入、`UsageRecord.css` 与 `useModelPricingData.jsx` 的变更,不涉及数据迁移。
|
||||
- **关联**:`docs/standards/UI_COMPONENT_STANDARDS.md` 第 4、5.2 节,`docs/ui/USER_CENTER_SPEC.md` 第 4.2 节,`docs/ui/MODEL_MARKET_SPEC.md` 第 8 节。
|
||||
|
||||
## 2026-11-14
|
||||
|
||||
### 功能 · 官网设置文章发布时间精确到秒
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# UI 公共组件与样式规范
|
||||
|
||||
> 状态:有效 · 适用:antd 6.7.0 · 更新:2026-11-11 · 版本:v2.1
|
||||
> 状态:有效 · 适用:antd 6.7.0 · 更新:2026-11-16 · 版本:v2.2
|
||||
|
||||
所有后台页面共用的主题与组件标准。页面规范只记录与本文不同的部分;编码约定见 `DEV_STANDARDS.md`,外壳与布局见 `GLOBAL_UI_BASELINE.md`。
|
||||
|
||||
@@ -125,6 +125,7 @@ html.dark .km-page {
|
||||
|
||||
## 4. 表格搜索栏(筛选卡)
|
||||
|
||||
- 背景:使用不透明的卡片纯色;浅色为白色,深色沿用主题卡片色,不使用渐变背景。
|
||||
- 字段竖排:标签在上(13px,次文字色,下距 8px),控件在下且宽度占满单元格。
|
||||
- 栅格:列间距与行间距 16px;按页面宽度取 3–5 列(企业中心 3 列、控制台 4 列、用户中心 5 列,时间范围可跨 2 列);≤ 768px 单列。
|
||||
- 操作:“重置”“搜索”位于右下,间距 8px;“搜索”为 primary 且 `htmlType='submit'`,回车提交。
|
||||
@@ -148,7 +149,8 @@ html.dark .km-page {
|
||||
|
||||
- 每列显式 `width`,长文本 `ellipsis` 并配 `Tooltip`;金额与数量右对齐;时间统一格式,必要时日期与时间分两行。
|
||||
- 状态列用 `Tag` 或 `Switch`(见第 11 节);启停开关请求中禁用,失败恢复原状态。
|
||||
- 操作列放在最后,按钮为 `type='link' size='small'`,危险操作加 `danger`,同一行操作间距 8–10px;只有宽表才 `fixed: 'right'`;操作较多时折叠到“更多”下拉。
|
||||
- 操作列放在最后,按钮为 `type='link' size='small'`,危险操作加 `danger`,同一行操作间距 8–10px;用户中心、企业中心、控制台(含系统设置)的操作列统一 `fixed: 'right'`;操作较多时折叠到“更多”下拉。
|
||||
- 三中心表格通过 `CenterActionTable` 统一处理,最后一列存在创建、查看、编辑、测试、详情、删除、添加、设置、配置、弹窗 / 抽屉或请求交互时,列头统一显示“操作”并固定右侧,宽度按按钮 / 交互数量计算。没有操作列但估算列宽超出容器时,从右侧固定末 4 列,列数不足时降为 3、2、1 列。固定列使用不透明底色并保持表头层级;横向滚动条遵循 Ant Design 官方固定列表格行为,允许鼠标、触控板、触屏和键盘滚动,不隐藏滚动条。
|
||||
- 列显隐只在已有列设置的表格中提供,统一使用 `ColumnSettings`(见 `docs/ui/TABLE_COLUMN_SETTINGS_SPEC.md`)。
|
||||
|
||||
### 5.3 状态
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# 后台 UI 全局基线
|
||||
|
||||
> 状态:有效 · 适用:antd 6.7.0 · 更新:2026-11-13 · 版本:v3.3
|
||||
> 状态:有效 · 适用:antd 6.7.0 · 更新:2026-11-16 · 版本:v3.4
|
||||
|
||||
后台外壳与布局基线:顶栏、侧栏、公告、页头与内容边距、登录页,以及原型未定义场景、登录关卡与验收流程。主题与组件样式见 `UI_COMPONENT_STANDARDS.md`。
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
1. **内容边距**:读取 `user-center.css` 的 `--uc-page-pad-top/x/bottom`(桌面 30 / 36 / 36px,≤ 768px 为 16 / 16 / 24px)。普通页面根节点用 `.uc-page`;数据看板 `.uc-dashboard`、服务监控 `.user-center-service-page`(`calc(64px + 顶距)`,抵消宿主 `-mt-[64px]`)、下载页 `.weyai-download--embedded` 直接引用这些变量。企业功能页(`.org-*-page`、`.knowledge-page`、`.org-workbench`)走 `org-page.css`。禁止写死页面级边距或使用 `p-4 sm:p-6 lg:p-8`。工作区块间距 `--uc-layout-gap: 18px`。
|
||||
2. **页头**:用户中心用 `<UserCenterPageHeader title subtitle extra />`,企业中心用 `OrgPageHeader`(内部复用前者)。面包屑 12 / 18px,距内容区顶 30px,父级 `--text-secondary`、当前项 `--text-primary`,分隔符左右 10px,与标题 24px;标题 28 / 32px / 650 / 字距 -0.6px(`--uc-heading`);副标题 14 / 22px、上距 6px(`--uc-subtitle`);页头与首块 18px;右侧操作放 `extra`(间距 8px,窄屏换行)。页面不得覆盖这些数值,数据看板只保留 hero 装饰层。
|
||||
3. **面包屑登记**:用户中心在 `UserCenterBreadcrumb.jsx` 的 `pageTitles` 登记,显示“用户中心 / 当前页面”;企业中心在 `OrgBreadcrumb` 的 `orgPageGroups` 登记,分组页显示“分组 / 当前页面”,其他为“企业中心 / 当前页面”,未登记页面以标题兜底。带 hero 的企业功能页在 hero 内首个元素顶部放 `<OrgBreadcrumb />`。不在原本没有面包屑的页面新增导航;没有副标题文案时只传 `title`。
|
||||
4. **滚动条**:全站滑块 `#8b8b8b`、悬停 `#636363`、宽高 6px、圆角 3px、轨道透明,值来自 `tokens.css` 的 `--brand-scroll` / `--brand-scroll-hover`,规则集中在 `src/index.css`。页面 CSS 与内联样式禁止设置 `scrollbar-width` / `scrollbar-color`(Chrome 121+ 设置后会忽略 `::-webkit-scrollbar`),标准属性只在 `@supports not selector(::-webkit-scrollbar)` 中给 Firefox。
|
||||
4. **滚动条**:全站滑块 `#8b8b8b`、悬停 `#636363`、宽高 6px、圆角 3px、轨道透明,值来自 `tokens.css` 的 `--brand-scroll` / `--brand-scroll-hover`,规则集中在 `src/index.css`。页面 CSS 与内联样式禁止设置 `scrollbar-width` / `scrollbar-color`(Chrome 121+ 设置后会忽略 `::-webkit-scrollbar`),标准属性只在 `@supports not selector(::-webkit-scrollbar)` 中给 Firefox。三中心操作表格沿用 Ant Design 固定列表格的横向滚动行为,不隐藏滚动条。
|
||||
5. **验证**:逐页核对左右边距、面包屑顶距、标题与副标题字号间距、滚动条静止与悬停颜色(桌面 / 移动 × 浅 / 深)。
|
||||
|
||||
### 4.5 登录页与认证顶栏
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# 模型超市 UI 规范(/market)
|
||||
|
||||
> 状态:有效 · 适用:antd 6.7.0 · 更新:2026-11-13 · 版本:v2.3
|
||||
> 状态:有效 · 适用:antd 6.7.0 · 更新:2026-11-16 · 版本:v2.4
|
||||
|
||||
个人端模型超市 `/market` 的规范。本页为独立视觉页面,组件映射优先于公共规范。
|
||||
|
||||
@@ -109,6 +109,7 @@
|
||||
|
||||
## 8. 验收要点
|
||||
|
||||
- 搜索仅对 `model_name` 做不区分大小写的子串匹配,忽略关键词首尾空格;描述、标签、厂商名称不参与关键词匹配,其他筛选条件仍取交集;保留原前端防抖,不新增搜索请求。
|
||||
- 视口 1920×1000 与 393×851,浅深主题;交互序列:默认厂商行 → 展开五组条件 → 选择分组 → 收起仍保持筛选与价格 → 重置 → 悬停卡片 → 键盘聚焦卡片 → 关键词搜索 → 选择厂商 → 空结果 → 整页滚动到底与厂商懒渲染 → 打开详情。
|
||||
- 响应式补充 3840×2160、2560×1440、1920×1080、中屏及断点两侧、360×800;检查两侧留白、卡片宽度、正文换行、无横向溢出,以及筛选展开和详情在窄屏上的可达性。
|
||||
- 与原型比较时使用同构模拟目录并标注;真实后端另行验证;整页 ≤ 0.5%、组件 ≤ 0.2%。
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# 用户中心 UI 规范(/user-center/\*)
|
||||
|
||||
> 状态:有效 · 适用:antd 6.7.0 · 更新:2026-11-11 · 版本:v2.2
|
||||
> 状态:有效 · 适用:antd 6.7.0 · 更新:2026-11-16 · 版本:v2.3
|
||||
|
||||
个人登录后用户中心页面的规范,只记录与公共规范不同的部分;密钥管理、服务监控见各自规范。
|
||||
|
||||
@@ -76,9 +76,9 @@
|
||||
### 4.2 使用记录
|
||||
|
||||
- 页签:纯文字页签(公共列表页签样式),与下方 20px,URL `?tab=` 同步并懒挂载。
|
||||
- 筛选卡:5 列栅格,时间范围跨 2 列;带浅暖色渐变底(仅 `.usage-record-page`);操作“重置 / 搜索”右下。
|
||||
- 筛选卡:5 列栅格,时间范围跨 2 列;背景使用 `--surface-card` 纯色(浅色为白色、深色为主题卡片色);操作“重置 / 搜索”右下。
|
||||
- 列表卡:标题 15px / 600,导出、列设置位于卡头右侧;表头字重 400(公共标准为 500,待收敛)。
|
||||
- 消费记录调用明细为固定列宽宽表,时间分两行(日期 11px、时间 15px / 600),操作列文字“查看”,随表格横向滚动。
|
||||
- 消费记录调用明细为固定列宽宽表,时间分两行(日期 11px、时间 15px / 600),操作列文字“查看”,固定在右侧;横向滚动条保留 Ant Design 官方固定列表格行为,固定列兼容规则遵循公共规范第 5.2 节。
|
||||
- 绘图与视频:三张统计卡(高 70px、间距 15px)+ 任务记录表。
|
||||
- Webhook 示例为 `<pre class='ui-notify-code'>` +“复制”链接,复制提示沿用原文案。
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
@@ -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),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -48,6 +48,7 @@ const ui = await loadFrontendModule(
|
||||
'../../hooks/common/useIsMobile': { useIsMobile: () => false },
|
||||
'../console/ConsoleContext': context,
|
||||
'../console/consoleTableAdapter': {},
|
||||
'./CenterActionTable': Ant.Table,
|
||||
'../console/ConsolePrimitives': {},
|
||||
},
|
||||
);
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
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 assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import i18next from 'i18next';
|
||||
import {
|
||||
isActionColumn,
|
||||
isCenterTableScope,
|
||||
prepareCenterColumns,
|
||||
} from '../../src/components/ui/centerTablePolicy.js';
|
||||
|
||||
test('center operation policy includes system settings and excludes unrelated routes', () => {
|
||||
for (const path of [
|
||||
'/user-center/usage-record',
|
||||
'/org/tokens',
|
||||
'/console/user',
|
||||
'/console/setting',
|
||||
'/console/setting/theme',
|
||||
])
|
||||
assert.equal(isCenterTableScope(path), true);
|
||||
for (const path of ['/market', '/organization'])
|
||||
assert.equal(isCenterTableScope(path), false);
|
||||
});
|
||||
|
||||
test('pins operations and detail callbacks without changing data, renderers or input columns', () => {
|
||||
const render = () => null;
|
||||
const columns = [
|
||||
{ key: 'name', width: 240, fixed: 'left' },
|
||||
{ title: '类型', dataIndex: 'action', render },
|
||||
{ title: '操作', key: 'actions', width: 160, render },
|
||||
];
|
||||
const result = prepareCenterColumns(columns, 1200);
|
||||
assert.deepEqual(result[0], columns[0]);
|
||||
assert.deepEqual(result[1], columns[1]);
|
||||
assert.equal(result[2].fixed, 'right');
|
||||
assert.equal(result[2].render, render);
|
||||
assert.equal(columns[2].fixed, undefined);
|
||||
assert.equal(isActionColumn(columns[1]), false);
|
||||
assert.equal(
|
||||
isActionColumn({ key: 'fail_reason', title: '详情', render }),
|
||||
true,
|
||||
);
|
||||
assert.equal(isActionColumn({ title: '详情', dataIndex: 'detail' }), false);
|
||||
assert.equal(
|
||||
isActionColumn({ title: '操作人', dataIndex: 'operator' }),
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
test('narrow containers release colliding left columns and bound the operation area', () => {
|
||||
const columns = [
|
||||
{ key: 'name', width: 240, fixed: 'left' },
|
||||
{ title: '说明', width: 300, fixed: 'right' },
|
||||
{ key: 'result', width: 300, render: () => null },
|
||||
];
|
||||
const result = prepareCenterColumns(columns, 300);
|
||||
assert.equal(result[0].fixed, 'right');
|
||||
assert.equal(result[1].fixed, 'right');
|
||||
assert.equal(result[2].fixed, 'right');
|
||||
assert.equal(result[2].width, 300);
|
||||
assert.equal(columns[0].fixed, 'left');
|
||||
});
|
||||
|
||||
test('renames interactive detail headers and sizes action columns from controls', () => {
|
||||
const renderDetail = function renderDetail() {
|
||||
return { onClick: true, Button: true };
|
||||
};
|
||||
const result = prepareCenterColumns(
|
||||
[
|
||||
{ key: 'name', width: 180 },
|
||||
{ title: '详情', dataIndex: 'detail', render: renderDetail },
|
||||
],
|
||||
900,
|
||||
);
|
||||
assert.equal(result[1].title, '操作');
|
||||
assert.equal(result[1].fixed, 'right');
|
||||
assert.ok(result[1].width >= 120);
|
||||
});
|
||||
|
||||
test('supports grouped headers and keeps ordinary tables intact', () => {
|
||||
const render = () => null;
|
||||
const grouped = [{ title: '记录', children: [{ title: '操作', render }] }];
|
||||
assert.equal(
|
||||
prepareCenterColumns(grouped, 800)[0].children[0].fixed,
|
||||
'right',
|
||||
);
|
||||
const ordinary = [{ title: '金额', dataIndex: 'amount' }];
|
||||
assert.deepEqual(prepareCenterColumns(ordinary, 300), ordinary);
|
||||
});
|
||||
|
||||
test('recognizes translated operation headers without requiring a key', async () => {
|
||||
await i18next.init({
|
||||
lng: 'en',
|
||||
resources: { en: { translation: { 操作: 'Actions' } } },
|
||||
});
|
||||
assert.equal(isActionColumn({ title: 'Actions', render: () => null }), true);
|
||||
});
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
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 assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import React from 'react';
|
||||
import { loadFrontendModule } from './helpers/frontendModule.js';
|
||||
|
||||
async function search(query, filters = {}) {
|
||||
const models = [
|
||||
{
|
||||
model_name: 'GPT-4o',
|
||||
vendor_name: 'OpenAI',
|
||||
description: '聊天模型',
|
||||
tags: '热门',
|
||||
enable_groups: ['default'],
|
||||
},
|
||||
{
|
||||
model_name: 'Claude-Sonnet',
|
||||
vendor_name: 'GPT',
|
||||
description: 'GPT-4o',
|
||||
tags: 'GPT',
|
||||
enable_groups: ['vip'],
|
||||
},
|
||||
{
|
||||
model_name: '中文模型-Pro',
|
||||
vendor_name: 'other',
|
||||
enable_groups: ['default'],
|
||||
},
|
||||
{ model_name: null, description: 'GPT', enable_groups: [] },
|
||||
];
|
||||
let index = 0;
|
||||
const state = {
|
||||
0: query,
|
||||
7: filters.group || 'all',
|
||||
10: filters.vendor || 'all',
|
||||
17: models,
|
||||
};
|
||||
const react = {
|
||||
...React,
|
||||
useState: (initial) => [
|
||||
Object.hasOwn(state, index) ? state[index++] : (++index, initial),
|
||||
() => {},
|
||||
],
|
||||
useMemo: (fn) => fn(),
|
||||
useEffect: () => {},
|
||||
useRef: (initial) => ({ current: initial }),
|
||||
useContext: () => [{}],
|
||||
};
|
||||
const { useModelPricingData: runHook } = await loadFrontendModule(
|
||||
new URL(
|
||||
'../../src/hooks/model-pricing/useModelPricingData.jsx',
|
||||
import.meta.url,
|
||||
),
|
||||
{
|
||||
react,
|
||||
'../common/useEffectEvent': { useEffectEvent: (callback) => callback },
|
||||
'react-i18next': { useTranslation: () => ({ t: (key) => key }) },
|
||||
'../../helpers': {
|
||||
API: { get: assert.fail },
|
||||
copy: assert.fail,
|
||||
getCurrencySymbol: () => '$',
|
||||
showError: assert.fail,
|
||||
showInfo: assert.fail,
|
||||
showSuccess: assert.fail,
|
||||
},
|
||||
'@/components/ui': { Modal: {} },
|
||||
'../../context/User': { UserContext: {} },
|
||||
'../../context/Status': { StatusContext: {} },
|
||||
},
|
||||
);
|
||||
return runHook().filteredModels.map((model) => model.model_name);
|
||||
}
|
||||
|
||||
test('model search matches names only, ignoring case and surrounding spaces', async () => {
|
||||
assert.deepEqual(await search(' gPt-4 '), ['GPT-4o']);
|
||||
assert.deepEqual(await search('OpenAI'), []);
|
||||
assert.deepEqual(await search('热门'), []);
|
||||
assert.deepEqual(await search('模型'), ['中文模型-Pro']);
|
||||
});
|
||||
|
||||
test('blank and missing names are safe; search still intersects existing filters', async () => {
|
||||
assert.equal((await search(' ')).length, 4);
|
||||
assert.deepEqual(await search('gpt', { vendor: 'GPT' }), []);
|
||||
assert.deepEqual(await search('gpt', { group: 'vip' }), []);
|
||||
assert.deepEqual(await search('son', { group: 'vip' }), ['Claude-Sonnet']);
|
||||
});
|
||||
@@ -163,6 +163,7 @@ async function modelTestFixture() {
|
||||
),
|
||||
Typography: { Text: 'Text' },
|
||||
},
|
||||
'../../../ui/CenterActionTable': 'Table',
|
||||
'lucide-react': { Search: 'Search' },
|
||||
'./model-test-modal.css': {},
|
||||
'../../../../helpers': {},
|
||||
|
||||
@@ -416,6 +416,7 @@ const modules = {
|
||||
'./form': {},
|
||||
'./chat': {},
|
||||
'../console/ConsoleContext': { useConsolePage: () => null },
|
||||
'./CenterActionTable': Ant.Table,
|
||||
'../console/ConsolePrimitives': {},
|
||||
'../console/consoleTableAdapter': {},
|
||||
};
|
||||
|
||||
@@ -51,6 +51,7 @@ const mocks = {
|
||||
theme: { useToken: () => ({ token }) },
|
||||
},
|
||||
'react-i18next': {},
|
||||
'../ui/CenterActionTable': 'table',
|
||||
'../common/table/TableEmpty': () => null,
|
||||
'./ConsoleContext': { useConsolePage: () => ({ page: { key: pageKey } }) },
|
||||
};
|
||||
|
||||
@@ -40,6 +40,7 @@ test('settings tables share the log empty state while other console routes retai
|
||||
react: React,
|
||||
antd: Ant,
|
||||
'react-i18next': { useTranslation: () => ({ t: (value) => value }) },
|
||||
'../ui/CenterActionTable': Ant.Table,
|
||||
'../common/table/TableEmpty': TableEmpty,
|
||||
'./ConsoleContext': { useConsolePage: () => ({ page: { key } }) },
|
||||
},
|
||||
|
||||
@@ -178,6 +178,7 @@ const { Table, Pagination } = loadUi({
|
||||
'./form': {},
|
||||
'./chat': {},
|
||||
'../console/ConsoleContext': { useConsolePage: () => null },
|
||||
'./CenterActionTable': Ant.Table,
|
||||
'../console/ConsolePrimitives': {},
|
||||
'../console/consoleTableAdapter': {},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user