feat: 自行开发设计 ui样式优化 超管端-控制台 相关的页面

This commit is contained in:
zhanjunhao
2026-11-09 21:45:37 +08:00
parent 6ad95e2baa
commit 5713d541b0
242 changed files with 9242 additions and 5043 deletions
@@ -18,14 +18,7 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import {
Button,
Dropdown,
Modal,
Switch,
Typography,
Select,
} from '@/components/ui';
import { Button, Dropdown, Modal, Switch, Typography } from '@/components/ui';
import CompactModeToggle from '../../common/ui/CompactModeToggle';
import { isRoot } from '../../../helpers';
@@ -40,7 +33,7 @@ const renderBatchDeleteContent = (t) => (
);
const ChannelsActions = ({
enableBatchDelete,
selectedChannels,
batchDeleteChannels,
setShowBatchSetTag,
testAllChannels,
@@ -50,17 +43,9 @@ const ChannelsActions = ({
compactMode,
setCompactMode,
idSort,
setIdSort,
setEnableBatchDelete,
enableTagMode,
setEnableTagMode,
statusFilter,
setStatusFilter,
getFormValues,
loadChannels,
searchChannels,
activeTypeKey,
activePage,
pageSize,
setActivePage,
t,
@@ -74,7 +59,7 @@ const ChannelsActions = ({
{isRoot() && (
<Button
size='small'
disabled={!enableBatchDelete}
disabled={!selectedChannels.length}
type='danger'
className='w-full md:w-auto'
onClick={() => {
@@ -92,7 +77,7 @@ const ChannelsActions = ({
{isRoot() && (
<Button
size='small'
disabled={!enableBatchDelete}
disabled={!selectedChannels.length}
type='tertiary'
onClick={() => setShowBatchSetTag(true)}
className='w-full md:w-auto'
@@ -209,54 +194,6 @@ const ChannelsActions = ({
{/* 右侧:设置开关区域 */}
<div className='flex flex-col md:flex-row items-start md:items-center gap-2 w-full md:w-auto order-1 md:order-2'>
<div className='flex items-center justify-between w-full md:w-auto'>
<Typography.Text strong className='mr-2'>
{t('使用ID排序')}
</Typography.Text>
<Switch
size='small'
checked={idSort}
onChange={(v) => {
localStorage.setItem('id-sort', v + '');
setIdSort(v);
const { searchKeyword, searchGroup, searchModel } =
getFormValues();
if (
searchKeyword === '' &&
searchGroup === '' &&
searchModel === ''
) {
loadChannels(activePage, pageSize, v, enableTagMode);
} else {
searchChannels(
enableTagMode,
activeTypeKey,
statusFilter,
activePage,
pageSize,
v,
);
}
}}
/>
</div>
{isRoot() && (
<div className='flex items-center justify-between w-full md:w-auto'>
<Typography.Text strong className='mr-2'>
{t('开启批量操作')}
</Typography.Text>
<Switch
size='small'
checked={enableBatchDelete}
onChange={(v) => {
localStorage.setItem('enable-batch-delete', v + '');
setEnableBatchDelete(v);
}}
/>
</div>
)}
<div className='flex items-center justify-between w-full md:w-auto'>
<Typography.Text strong className='mr-2'>
{t('标签聚合模式')}
@@ -272,33 +209,6 @@ const ChannelsActions = ({
}}
/>
</div>
<div className='flex items-center justify-between w-full md:w-auto'>
<Typography.Text strong className='mr-2'>
{t('状态筛选')}
</Typography.Text>
<Select
size='small'
value={statusFilter}
onChange={(v) => {
localStorage.setItem('channel-status-filter', v);
setStatusFilter(v);
setActivePage(1);
loadChannels(
1,
pageSize,
idSort,
enableTagMode,
activeTypeKey,
v,
);
}}
>
<Select.Option value='all'>{t('全部')}</Select.Option>
<Select.Option value='enabled'>{t('已启用')}</Select.Option>
<Select.Option value='disabled'>{t('已禁用')}</Select.Option>
</Select>
</div>
</div>
</div>
</div>
@@ -17,15 +17,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import { writeClipboardText } from '../../../helpers/clipboard';
import React, { useState } from 'react';
import { Switch } from 'antd';
import {
Button,
Dropdown,
InputNumber,
Modal,
Progress,
Space,
SplitButtonGroup,
Tag,
Tooltip,
} from '@/components/ui';
@@ -42,9 +42,39 @@ import {
hoverOrClickTrigger,
} from '../../../helpers';
import { CHANNEL_OPTIONS } from '../../../constants';
import { IconTreeTriangleDown, IconMore } from '@/components/ui/icons';
import { IconTreeTriangleDown } from '@/components/ui/icons';
import { ShuffleBrandIcon } from '../../common/icons/BrandIcons';
function ChannelStatusSwitch({ record, manageChannel, t }) {
const [loading, setLoading] = useState(false);
return (
<Switch
size='small'
checked={record.status === 1}
checkedChildren={t('启用')}
unCheckedChildren={t('禁用')}
disabled={!isRoot()}
loading={loading}
aria-label={t('状态')}
onClick={(_, event) => event.stopPropagation()}
onChange={async (checked) => {
setLoading(true);
try {
await manageChannel(
record.id,
checked ? 'enable' : 'disable',
record,
);
} catch (error) {
showError(error.message);
} finally {
setLoading(false);
}
}}
/>
);
}
// 删除单个渠道的确认文案:若该渠道被其他渠道列为兜底,追加影响说明。
// 查询失败不阻塞删除,仅回退为原确认文案
const buildDeleteConfirmContent = async (channelId, t) => {
@@ -360,8 +390,7 @@ export const getChannelsColumns = ({
theme='outline'
onClick={(e) => {
e.stopPropagation();
navigator.clipboard
.writeText(record.remark)
writeClipboardText(record.remark)
.then(() => {
showSuccess(t('复制成功'));
})
@@ -425,13 +454,46 @@ export const getChannelsColumns = ({
title: t('状态'),
dataIndex: 'status',
render: (text, record, index) => {
const statusControl =
record.children !== undefined ? (
renderStatus(text, record.channel_info, t)
) : (
<Space>
<ChannelStatusSwitch
record={record}
manageChannel={manageChannel}
t={t}
/>
{record.channel_info?.is_multi_key && (
<span>
{(record.channel_info.multi_key_size || 0) -
Object.keys(record.channel_info.multi_key_status_list || {})
.length}
/{record.channel_info.multi_key_size || 0}
</span>
)}
</Space>
);
if (text === 3) {
if (record.other_info === '') {
record.other_info = '{}';
let otherInfo;
try {
otherInfo =
typeof record.other_info === 'string'
? JSON.parse(record.other_info)
: record.other_info;
} catch {
return statusControl;
}
let otherInfo = JSON.parse(record.other_info);
let reason = otherInfo['status_reason'];
let time = otherInfo['status_time'];
if (
!otherInfo ||
typeof otherInfo !== 'object' ||
Array.isArray(otherInfo) ||
(!otherInfo.status_reason && !otherInfo.status_time)
) {
return statusControl;
}
const reason = otherInfo.status_reason || '';
const time = otherInfo.status_time;
return (
<div>
<Tooltip
@@ -439,12 +501,12 @@ export const getChannelsColumns = ({
t('原因:') + reason + t(',时间:') + timestamp2string(time)
}
>
{renderStatus(text, record.channel_info, t)}
{statusControl}
</Tooltip>
</div>
);
} else {
return renderStatus(text, record.channel_info, t);
return statusControl;
}
},
},
@@ -660,7 +722,7 @@ export const getChannelsColumns = ({
},
{
key: COLUMN_KEYS.OPERATE,
title: '',
title: t('操作'),
dataIndex: 'operate',
fixed: 'right',
render: (text, record, index) => {
@@ -704,105 +766,63 @@ export const getChannelsColumns = ({
];
return (
<Space wrap>
<Space wrap className='console-module-row-actions'>
{isRoot() && (
<SplitButtonGroup
className='overflow-hidden'
aria-label={t('测试单个渠道操作项目组')}
>
<>
<Button
type='link'
size='small'
type='tertiary'
onClick={() => testChannel(record, '')}
>
{t('测试')}
</Button>
<Button
type='link'
size='small'
type='tertiary'
icon={<IconTreeTriangleDown />}
onClick={() => {
setCurrentTestChannel(record);
setShowModelTestModal(true);
}}
/>
</SplitButtonGroup>
)}
{isRoot() && (
<>
{record.status === 1 ? (
>
{t('批量测试')}
</Button>
<Button
type='link'
size='small'
onClick={() => {
setEditingChannel(record);
setShowEdit(true);
}}
>
{t('编辑')}
</Button>
<Button
type='link'
danger
size='small'
onClick={moreMenuItems[0].onClick}
>
{t('删除')}
</Button>
<Button
type='link'
size='small'
onClick={moreMenuItems[1].onClick}
>
{t('复制')}
</Button>
{record.channel_info?.is_multi_key && (
<Button
type='danger'
size='small'
onClick={() =>
manageChannel(record.id, 'disable', record)
}
>
{t('禁用')}
</Button>
) : (
<Button
size='small'
onClick={() => manageChannel(record.id, 'enable', record)}
>
{t('启用')}
</Button>
)}
{record.channel_info?.is_multi_key ? (
<SplitButtonGroup aria-label={t('多密钥渠道操作项目组')}>
<Button
type='tertiary'
size='small'
onClick={() => {
setEditingChannel(record);
setShowEdit(true);
}}
>
{t('编辑')}
</Button>
<Dropdown
trigger='click'
position='bottomRight'
menu={[
{
node: 'item',
name: t('多密钥管理'),
onClick: () => {
setCurrentMultiKeyChannel(record);
setShowMultiKeyManageModal(true);
},
},
]}
>
<Button
type='tertiary'
size='small'
icon={<IconTreeTriangleDown />}
/>
</Dropdown>
</SplitButtonGroup>
) : (
<Button
type='tertiary'
type='link'
size='small'
onClick={() => {
setEditingChannel(record);
setShowEdit(true);
setCurrentMultiKeyChannel(record);
setShowMultiKeyManageModal(true);
}}
>
{t('编辑')}
{t('多密钥管理')}
</Button>
)}
<Dropdown
trigger='click'
position='bottomRight'
menu={moreMenuItems}
>
<Button icon={<IconMore />} type='tertiary' size='small' />
</Dropdown>
</>
)}
</Space>
@@ -814,21 +834,21 @@ export const getChannelsColumns = ({
{isRoot() && (
<>
<Button
type='tertiary'
type='link'
size='small'
onClick={() => manageTag(record.key, 'enable')}
>
{t('启用全部')}
</Button>
<Button
type='tertiary'
type='link'
size='small'
onClick={() => manageTag(record.key, 'disable')}
>
{t('禁用全部')}
</Button>
<Button
type='tertiary'
type='link'
size='small'
onClick={() => {
setShowEditTag(true);
+99 -128
View File
@@ -18,15 +18,12 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import { Button, Form } from '@/components/ui';
import { Form } from '@/components/ui';
import { IconSearch } from '@/components/ui/icons';
import { isRoot } from '../../../helpers';
import { ConsoleFilterActions } from '../../console/ConsoleModuleFilters';
import { useFilterSearch } from '../../../hooks/common/useFilterSearch';
const ChannelsFilters = ({
setEditingChannel,
setShowEdit,
refresh,
setShowColumnSelector,
formInitValues,
setFormApi,
searchChannels,
@@ -37,148 +34,122 @@ const ChannelsFilters = ({
searching,
autoBanExclusionFilter,
setAutoBanExclusionFilter,
statusFilter,
setStatusFilter,
t,
}) => {
const { scheduleSearch, submitSearch, cancelPendingSearch } = useFilterSearch(
() => searchChannels(enableTagMode),
);
return (
<div className='flex flex-col md:flex-row justify-between items-center gap-2 w-full'>
<div className='flex gap-2 w-full md:w-auto order-2 md:order-1'>
{isRoot() && (
<Button
size='small'
theme='light'
type='primary'
className='w-full md:w-auto'
onClick={() => {
setEditingChannel({
id: undefined,
});
setShowEdit(true);
}}
>
{t('添加渠道')}
</Button>
)}
<Button
size='small'
type='tertiary'
className='w-full md:w-auto'
onClick={refresh}
>
{t('刷新')}
</Button>
<Button
size='small'
type='tertiary'
onClick={() => setShowColumnSelector(true)}
className='w-full md:w-auto'
>
{t('列设置')}
</Button>
</div>
<div className='w-full'>
<div className='flex flex-col md:flex-row items-center gap-2 w-full md:w-auto order-1 md:order-2'>
<Form
initValues={formInitValues}
initValues={{
...formInitValues,
searchGroup: formInitValues.searchGroup || undefined,
}}
getFormApi={(api) => setFormApi(api)}
onSubmit={() => searchChannels(enableTagMode)}
onSubmit={submitSearch}
onValueChange={scheduleSearch}
allowEmpty={true}
autoComplete='off'
layout='horizontal'
layout='vertical'
trigger='change'
stopValidateWithError={false}
className='flex flex-col md:flex-row items-center gap-2 w-full'
className='console-module-filter-form'
>
<div className='relative w-full md:w-64'>
<Form.Input
size='small'
field='searchKeyword'
prefix={<IconSearch />}
placeholder={t('渠道ID,名称,密钥,API地址')}
showClear
pure
/>
<div className='console-module-filter-grid'>
<div className='console-module-field'>
<Form.Input
label={t('渠道ID,名称,密钥,API地址')}
size='small'
field='searchKeyword'
prefix={<IconSearch />}
placeholder={t('渠道ID,名称,密钥,API地址')}
showClear
/>
</div>
<div className='console-module-field'>
<Form.Input
label={t('模型名称')}
size='small'
field='searchModel'
prefix={<IconSearch />}
placeholder={t('模型关键字')}
showClear
/>
</div>
<div className='console-module-field'>
<Form.Select
label={t('分组')}
size='small'
field='searchGroup'
placeholder={t('选择分组')}
optionList={[...groupOptions]}
className='w-full'
showClear
/>
</div>
<div className='console-module-field'>
<Form.Select
label={t('自动封禁')}
size='small'
placeholder={t('自动封禁')}
value={autoBanExclusionFilter}
optionList={[
{ label: t('全部'), value: 'all' },
{ label: t('参与'), value: 'included' },
{ label: t('已排除'), value: 'excluded' },
]}
className='w-full'
showClear
onChange={(value) => {
const newValue = value || 'all';
localStorage.setItem(
'channel-autoban-exclusion-filter',
newValue,
);
setAutoBanExclusionFilter(newValue);
scheduleSearch();
}}
/>
</div>
<div className='console-module-field'>
<Form.Select
label={t('状态')}
placeholder={t('全部状态')}
value={statusFilter}
onChange={(value) => {
localStorage.setItem('channel-status-filter', value);
setStatusFilter(value);
scheduleSearch();
}}
optionList={[
{ label: t('全部'), value: 'all' },
{ label: t('已启用'), value: 'enabled' },
{ label: t('已禁用'), value: 'disabled' },
]}
/>
</div>
</div>
<div className='w-full md:w-48'>
<Form.Input
size='small'
field='searchModel'
prefix={<IconSearch />}
placeholder={t('模型关键字')}
showClear
pure
/>
</div>
<div className='w-full md:w-32'>
<Form.Select
size='small'
field='searchGroup'
placeholder={t('选择分组')}
optionList={[
{ label: t('选择分组'), value: null },
...groupOptions,
]}
className='w-full'
showClear
pure
onChange={() => {
// 延迟执行搜索,让表单值先更新
setTimeout(() => {
searchChannels(enableTagMode);
}, 0);
}}
/>
</div>
<div className='w-full md:w-32'>
<Form.Select
size='small'
field='autoBanExclusionFilter'
placeholder={t('自动封禁')}
value={autoBanExclusionFilter}
optionList={[
{ label: t('全部'), value: 'all' },
{ label: t('参与'), value: 'included' },
{ label: t('已排除'), value: 'excluded' },
]}
className='w-full'
showClear
pure
onChange={(value) => {
const newValue = value || 'all';
localStorage.setItem(
'channel-autoban-exclusion-filter',
newValue,
);
setAutoBanExclusionFilter(newValue);
}}
/>
</div>
<Button
size='small'
type='tertiary'
htmlType='submit'
<ConsoleFilterActions
loading={loading || searching}
className='w-full md:w-auto'
>
{t('查询')}
</Button>
<Button
size='small'
type='tertiary'
onClick={() => {
onReset={() => {
if (formApi) {
formApi.reset();
cancelPendingSearch();
setStatusFilter('all');
setAutoBanExclusionFilter('all');
localStorage.setItem('channel-status-filter', 'all');
localStorage.setItem('channel-autoban-exclusion-filter', 'all');
// 重置后立即查询,使用setTimeout确保表单重置完成
setTimeout(() => {
refresh();
searchChannels(enableTagMode, undefined, 'all');
}, 100);
}
}}
className='w-full md:w-auto'
>
{t('重置')}
</Button>
/>
</Form>
</div>
</div>
+47 -21
View File
@@ -17,13 +17,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useMemo } from 'react';
import { Empty } from '@/components/ui';
import TableEmpty from '../../common/table/TableEmpty';
import React, { useMemo, useState } from 'react';
import CardTable from '../../common/ui/CardTable';
import {
IllustrationNoResult,
IllustrationNoResultDark,
} from '../../common/illustrations';
import { isRoot } from '../../../helpers';
import { getChannelsColumns } from './ChannelsColumnDefs';
const ChannelsTable = (channelsData) => {
@@ -34,7 +32,7 @@ const ChannelsTable = (channelsData) => {
activePage,
pageSize,
channelCount,
enableBatchDelete,
selectedChannels,
compactMode,
visibleColumns,
setSelectedChannels,
@@ -66,8 +64,25 @@ const ChannelsTable = (channelsData) => {
autoBanExclusionFilter,
// Daily quota info
dailyQuotaInfo,
idSort,
setIdSort,
enableTagMode,
loadChannels,
} = channelsData;
const [idSortOrder, setIdSortOrder] = useState('descend');
const handleTableChange = ({ sorter, extra, action }) => {
if ((action ?? extra?.action) !== 'sort') return;
const order = sorter?.columnKey === COLUMN_KEYS.ID ? sorter.order : null;
setIdSortOrder(order || 'descend');
const nextIdSort = Boolean(order);
if (nextIdSort === idSort) return;
localStorage.setItem('id-sort', String(nextIdSort));
setIdSort(nextIdSort);
loadChannels(activePage, pageSize, nextIdSort, enableTagMode);
};
// Filter channels based on auto-ban exclusion filter
const filteredChannels = useMemo(() => {
if (!autoBanExclusionFilter || autoBanExclusionFilter === 'all') {
@@ -174,14 +189,28 @@ const ChannelsTable = (channelsData) => {
}, [visibleColumns, allColumns]);
const tableColumns = useMemo(() => {
const sortableColumns = visibleColumnsList.map((column) =>
column.key === COLUMN_KEYS.ID
? {
...column,
sorter: (a, b) => {
if (a.children !== undefined || b.children !== undefined)
return 0;
return Number(a.id) - Number(b.id);
},
sortOrder: idSort ? idSortOrder : null,
}
: column,
);
return compactMode
? visibleColumnsList.map(({ fixed, ...rest }) => rest)
: visibleColumnsList;
}, [compactMode, visibleColumnsList]);
? sortableColumns.map(({ fixed, ...rest }) => rest)
: sortableColumns;
}, [compactMode, visibleColumnsList, COLUMN_KEYS.ID, idSort, idSortOrder]);
return (
<CardTable
columns={tableColumns}
onChange={handleTableChange}
dataSource={filteredChannels}
scroll={compactMode ? undefined : { x: 'max-content' }}
pagination={{
@@ -197,24 +226,21 @@ const ChannelsTable = (channelsData) => {
expandAllRows={false}
onRow={handleRow}
rowSelection={
enableBatchDelete
isRoot()
? {
selectedRowKeys: selectedChannels.map(
(channel) => channel.key ?? String(channel.id),
),
getCheckboxProps: (record) => ({
disabled: record.children !== undefined,
}),
onChange: (selectedRowKeys, selectedRows) => {
setSelectedChannels(selectedRows);
},
}
: null
}
empty={
<Empty
image={<IllustrationNoResult style={{ width: 150, height: 150 }} />}
darkModeImage={
<IllustrationNoResultDark style={{ width: 150, height: 150 }} />
}
description={t('搜索无结果')}
style={{ padding: 30 }}
/>
}
empty={<TableEmpty />}
className='rounded-xl overflow-hidden'
size='middle'
loading={loading || searching}
+29 -5
View File
@@ -19,8 +19,11 @@ For commercial licensing, please contact support@quantumnous.com
import React from 'react';
import { Tabs, TabPane, Tag } from '@/components/ui';
import { Button } from 'antd';
import { Plus } from 'lucide-react';
import { CHANNEL_OPTIONS } from '../../../constants';
import { getChannelIcon } from '../../../helpers';
import { getChannelIcon, isRoot } from '../../../helpers';
import './channels-tabs.css';
const ChannelsTabs = ({
enableTagMode,
@@ -33,9 +36,30 @@ const ChannelsTabs = ({
pageSize,
idSort,
setActivePage,
setEditingChannel,
setShowEdit,
t,
}) => {
if (enableTagMode) return null;
const createButton = isRoot() ? (
<Button
className='console-create-action'
type='primary'
size='middle'
icon={<Plus size={16} />}
onClick={() => {
setEditingChannel({ id: undefined });
setShowEdit(true);
}}
>
{t('创建渠道')}
</Button>
) : null;
if (enableTagMode) {
return createButton ? (
<div className='flex justify-end'>{createButton}</div>
) : null;
}
const handleTabChange = (key) => {
setActiveTypeKey(key);
@@ -46,10 +70,10 @@ const ChannelsTabs = ({
return (
<Tabs
activeKey={activeTypeKey}
type='card'
collapsible
type='line'
onChange={handleTabChange}
className='mb-2'
className='channels-tabs mb-2'
tabBarExtraContent={createButton}
>
<TabPane
itemKey='all'
@@ -0,0 +1,5 @@
.channels-tabs > .ant-tabs-nav > .ant-tabs-extra-content {
align-self: flex-end;
/* Match the space below the tab labels above the navigation divider. */
margin-bottom: 12px;
}
+10
View File
@@ -19,6 +19,7 @@ For commercial licensing, please contact support@quantumnous.com
import React from 'react';
import CardPro from '../../common/ui/CardPro';
import { ColumnSettingsButton } from '../../common/table/ColumnSettings';
import ChannelsTable from './ChannelsTable';
import ChannelsActions from './ChannelsActions';
import ChannelsFilters from './ChannelsFilters';
@@ -64,11 +65,20 @@ const ChannelsPage = () => {
{/* Main Content */}
<CardPro
tableTitle={channelsData.t('渠道列表')}
tableActionsOffset
type='type3'
tabsArea={<ChannelsTabs {...channelsData} />}
actionsArea={<ChannelsActions {...channelsData} />}
searchArea={<ChannelsFilters {...channelsData} />}
tableActions={
<ColumnSettingsButton
open={channelsData.showColumnSelector}
onClick={() => channelsData.setShowColumnSelector(true)}
/>
}
paginationArea={createCardProPagination({
showRange: false,
currentPage: channelsData.activePage,
pageSize: channelsData.pageSize,
total: channelsData.channelCount,
@@ -18,16 +18,15 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import { Modal, Button, Checkbox } from '@/components/ui';
import { ColumnVisibilitySettings } from '../../../common/table/ColumnSettings';
import { getChannelsColumns } from '../ChannelsColumnDefs';
const ColumnSelectorModal = ({
showColumnSelector,
setShowColumnSelector,
visibleColumns,
handleColumnVisibilityChange,
handleSelectAll,
initDefaultColumns,
setVisibleColumns,
getDefaultColumnVisibility,
COLUMN_KEYS,
t,
// Props needed for getChannelsColumns
@@ -69,59 +68,14 @@ const ColumnSelectorModal = ({
});
return (
<Modal
title={t('列设置')}
visible={showColumnSelector}
onCancel={() => setShowColumnSelector(false)}
footer={
<div className='flex justify-end'>
<Button onClick={() => initDefaultColumns()}>{t('重置')}</Button>
<Button onClick={() => setShowColumnSelector(false)}>
{t('取消')}
</Button>
<Button onClick={() => setShowColumnSelector(false)}>
{t('确定')}
</Button>
</div>
}
>
<div style={{ marginBottom: 20 }}>
<Checkbox
checked={Object.values(visibleColumns).every((v) => v === true)}
indeterminate={
Object.values(visibleColumns).some((v) => v === true) &&
!Object.values(visibleColumns).every((v) => v === true)
}
onChange={(e) => handleSelectAll(e.target.checked)}
>
{t('全选')}
</Checkbox>
</div>
<div
className='flex flex-wrap max-h-96 overflow-y-auto rounded-lg p-4'
style={{ border: '1px solid var(--ui-color-border)' }}
>
{allColumns.map((column) => {
// Skip columns without title
if (!column.title) {
return null;
}
return (
<div key={column.key} className='w-1/2 mb-4 pr-2'>
<Checkbox
checked={!!visibleColumns[column.key]}
onChange={(e) =>
handleColumnVisibilityChange(column.key, e.target.checked)
}
>
{column.title}
</Checkbox>
</div>
);
})}
</div>
</Modal>
<ColumnVisibilitySettings
showColumnSelector={showColumnSelector}
setShowColumnSelector={setShowColumnSelector}
columns={allColumns.filter((column) => !!column.title)}
visibleColumns={visibleColumns}
setVisibleColumns={setVisibleColumns}
getDefaultColumnVisibility={getDefaultColumnVisibility}
/>
);
};
@@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import '../../../console/module-alignment.css';
import React, { useEffect, useState, useRef, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import {
@@ -60,18 +61,14 @@ import ChannelKeyDisplay from '../../../common/ui/ChannelKeyDisplay';
import { useSecureVerification } from '../../../../hooks/common/useSecureVerification';
import { createApiCalls } from '../../../../services/secureVerification';
import {
IconSave,
IconClose,
IconServer,
IconSetting,
IconCode,
IconGlobe,
IconBolt,
IconChevronUp,
IconChevronDown,
} from '@/components/ui/icons';
const { Text, Title } = Typography;
const { Text } = Typography;
const MODEL_MAPPING_EXAMPLE = {
'gpt-3.5-turbo': 'gpt-3.5-turbo-0125',
@@ -351,23 +348,6 @@ const EditChannelModal = (props) => {
t,
]);
// 表单块导航相关状态
const formSectionRefs = useRef({
basicInfo: null,
apiConfig: null,
modelConfig: null,
advancedSettings: null,
channelExtraSettings: null,
});
const [currentSectionIndex, setCurrentSectionIndex] = useState(0);
const formSections = [
'basicInfo',
'apiConfig',
'modelConfig',
'advancedSettings',
'channelExtraSettings',
];
const formContainerRef = useRef(null);
const doubaoApiClickCountRef = useRef(0);
const initialModelsRef = useRef([]);
const initialModelMappingRef = useRef('');
@@ -411,43 +391,6 @@ const EditChannelModal = (props) => {
});
};
// 表单导航功能
const scrollToSection = (sectionKey) => {
const sectionElement = formSectionRefs.current[sectionKey];
if (sectionElement) {
sectionElement.scrollIntoView({
behavior: 'smooth',
block: 'start',
inline: 'nearest',
});
}
};
const navigateToSection = (direction) => {
const availableSections = formSections.filter((section) => {
if (section === 'apiConfig') {
return showApiConfigCard;
}
return true;
});
let newIndex;
if (direction === 'up') {
newIndex =
currentSectionIndex > 0
? currentSectionIndex - 1
: availableSections.length - 1;
} else {
newIndex =
currentSectionIndex < availableSections.length - 1
? currentSectionIndex + 1
: 0;
}
setCurrentSectionIndex(newIndex);
scrollToSection(availableSections[newIndex]);
};
const handleApiConfigSecretClick = () => {
if (inputs.type !== 45) return;
const next = doubaoApiClickCountRef.current + 1;
@@ -1055,8 +998,6 @@ const EditChannelModal = (props) => {
fetchModelGroups();
// 重置手动输入模式状态
setUseManualInput(false);
// 重置导航状态
setCurrentSectionIndex(0);
} else {
// 统一的模态框关闭重置逻辑
resetModalState();
@@ -1655,7 +1596,7 @@ const EditChannelModal = (props) => {
const batchAllowed = !isEdit || isMultiKeyChannel;
const batchExtra = batchAllowed ? (
<Space>
<Space wrap className='console-channel-key-actions'>
{!isEdit && (
<Checkbox
disabled={isEdit}
@@ -1827,76 +1768,25 @@ const EditChannelModal = (props) => {
return (
<>
<SideSheet
placement={isEdit ? 'right' : 'left'}
title={
<Space>
<Tag color='blue' shape='circle'>
{isEdit ? t('编辑') : t('新建')}
</Tag>
<Title heading={4} className='m-0'>
{isEdit ? t('更新渠道信息') : t('创建新的渠道')}
</Title>
</Space>
}
rootClassName='console-channel-drawer'
classNames={{ header: 'console-channel-editor-header' }}
placement='right'
title={isEdit ? t('更新渠道信息') : t('创建新的渠道')}
bodyStyle={{ padding: '0' }}
visible={props.visible}
width={isMobile ? '100%' : 600}
footer={
<div className='flex justify-between items-center'>
<div className='flex gap-2'>
<Button
size='small'
type='tertiary'
icon={<IconChevronUp />}
onClick={() => navigateToSection('up')}
style={{
borderRadius: '50%',
width: '32px',
height: '32px',
padding: 0,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
title={t('上一个表单块')}
/>
<Button
size='small'
type='tertiary'
icon={<IconChevronDown />}
onClick={() => navigateToSection('down')}
style={{
borderRadius: '50%',
width: '32px',
height: '32px',
padding: 0,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
title={t('下一个表单块')}
/>
</div>
<Space>
<Button
theme='solid'
onClick={() => formApiRef.current?.submitForm()}
icon={<IconSave />}
>
{t('提交')}
</Button>
<Button
theme='light'
type='primary'
onClick={handleCancel}
icon={<IconClose />}
>
{t('取消')}
</Button>
</Space>
<div className='console-channel-footer'>
<Button onClick={handleCancel}>{t('取消')}</Button>
<Button
theme='solid'
type='primary'
onClick={() => formApiRef.current?.submitForm()}
>
{t('提交')}
</Button>
</div>
}
closeIcon={null}
onCancel={() => handleCancel()}
>
<Form
@@ -1907,16 +1797,12 @@ const EditChannelModal = (props) => {
>
{() => (
<Spin spinning={loading}>
<div className='p-2' ref={formContainerRef}>
<div ref={(el) => (formSectionRefs.current.basicInfo = el)}>
<div className='console-channel-sections p-2'>
<div>
<Card className='!rounded-2xl shadow-sm border-0 mb-6'>
{/* Header: Basic Info */}
<div className='flex items-center mb-2'>
<Avatar
size='small'
color='blue'
className='mr-2 shadow-md'
>
<div className='console-channel-section'>
<Avatar size='small' color='blue'>
<IconServer size={16} />
</Avatar>
<div>
@@ -2438,9 +2324,8 @@ const EditChannelModal = (props) => {
<Form.Input
field='openai_organization'
label={t('组织')}
placeholder={t('请输入组织org-xxx')}
placeholder={t('组织 org-xxx(留空使用默认组织)')}
showClear
helpText={t('组织,不填则为默认组织')}
onChange={(value) =>
handleInputChange('openai_organization', value)
}
@@ -2451,18 +2336,14 @@ const EditChannelModal = (props) => {
{/* API Configuration Card */}
{showApiConfigCard && (
<div ref={(el) => (formSectionRefs.current.apiConfig = el)}>
<div>
<Card className='!rounded-2xl shadow-sm border-0 mb-6'>
{/* Header: API Config */}
<div
className='flex items-center mb-2'
className='console-channel-section'
onClick={handleApiConfigSecretClick}
>
<Avatar
size='small'
color='green'
className='mr-2 shadow-md'
>
<Avatar size='small' color='green'>
<IconGlobe size={16} />
</Avatar>
<div>
@@ -2679,15 +2560,11 @@ const EditChannelModal = (props) => {
)}
{/* Model Configuration Card */}
<div ref={(el) => (formSectionRefs.current.modelConfig = el)}>
<div>
<Card className='!rounded-2xl shadow-sm border-0 mb-6'>
{/* Header: Model Config */}
<div className='flex items-center mb-2'>
<Avatar
size='small'
color='purple'
className='mr-2 shadow-md'
>
<div className='console-channel-section'>
<Avatar size='small' color='purple'>
<IconCode size={16} />
</Avatar>
<div>
@@ -2740,7 +2617,7 @@ const EditChannelModal = (props) => {
};
}}
extraText={
<Space wrap>
<Space wrap className='console-channel-model-actions'>
<Button
size='small'
type='primary'
@@ -2778,13 +2655,15 @@ const EditChannelModal = (props) => {
<Button
size='small'
type='tertiary'
onClick={() => {
onClick={async () => {
if (inputs.models.length === 0) {
showInfo(t('没有模型可以复制'));
return;
}
try {
copy(inputs.models.join(','));
if (!(await copy(inputs.models.join(',')))) {
throw new Error('Clipboard copy failed');
}
showSuccess(t('模型列表已复制到剪贴板'));
} catch (error) {
showError(t('复制失败'));
@@ -2888,17 +2767,11 @@ const EditChannelModal = (props) => {
</div>
{/* Advanced Settings Card */}
<div
ref={(el) => (formSectionRefs.current.advancedSettings = el)}
>
<div>
<Card className='!rounded-2xl shadow-sm border-0 mb-6'>
{/* Header: Advanced Settings */}
<div className='flex items-center mb-2'>
<Avatar
size='small'
color='orange'
className='mr-2 shadow-md'
>
<div className='console-channel-section'>
<Avatar size='small' color='orange'>
<IconSetting size={16} />
</Avatar>
<div>
@@ -3432,19 +3305,11 @@ const EditChannelModal = (props) => {
</div>
{/* Channel Extra Settings Card */}
<div
ref={(el) =>
(formSectionRefs.current.channelExtraSettings = el)
}
>
<div>
<Card className='!rounded-2xl shadow-sm border-0 mb-6'>
{/* Header: Channel Extra Settings */}
<div className='flex items-center mb-2'>
<Avatar
size='small'
color='violet'
className='mr-2 shadow-md'
>
<div className='console-channel-section'>
<Avatar size='small' color='violet'>
<IconBolt size={16} />
</Avatar>
<div>
@@ -17,19 +17,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import {
Modal,
Button,
Input,
Table,
Tag,
Typography,
Select,
} from '@/components/ui';
import { IconSearch } from '@/components/ui/icons';
import React, { useState } from 'react';
import { Modal, Button, Input, Table, Tag, Typography, Select } from 'antd';
import { Search } from 'lucide-react';
import { copy, showError, showInfo, showSuccess } from '../../../../helpers';
import { MODEL_TABLE_PAGE_SIZE } from '../../../../constants';
import './model-test-modal.css';
const ModelTestModal = ({
showModelTestModal,
@@ -48,19 +41,19 @@ const ModelTestModal = ({
setModelTablePage,
selectedEndpointType,
setSelectedEndpointType,
allSelectingRef,
isMobile,
t,
}) => {
const [paginationSize, setPaginationSize] = useState(MODEL_TABLE_PAGE_SIZE);
const hasChannel = Boolean(currentTestChannel);
const models =
typeof currentTestChannel?.models === 'string'
? currentTestChannel.models.split(',').filter(Boolean)
: [];
const filteredModels = hasChannel
? currentTestChannel.models
.split(',')
.filter((model) =>
model.toLowerCase().includes(modelSearchKeyword.toLowerCase()),
)
: [];
const filteredModels = models.filter((model) =>
model.toLowerCase().includes(modelSearchKeyword.toLowerCase()),
);
const endpointTypeOptions = [
{ value: '', label: t('自动检测') },
@@ -100,8 +93,7 @@ const ModelTestModal = ({
const handleSelectSuccess = () => {
if (!currentTestChannel) return;
const successKeys = currentTestChannel.models
.split(',')
const successKeys = models
.filter((m) => m.toLowerCase().includes(modelSearchKeyword.toLowerCase()))
.filter((m) => {
const result = modelTestResults[`${currentTestChannel.id}-${m}`];
@@ -126,34 +118,27 @@ const ModelTestModal = ({
{
title: t('状态'),
dataIndex: 'status',
width: 112,
render: (text, record) => {
const testResult =
modelTestResults[`${currentTestChannel.id}-${record.model}`];
const isTesting = testingModels.has(record.model);
if (isTesting) {
return (
<Tag color='blue' shape='circle'>
{t('测试中')}
</Tag>
);
return <Tag color='processing'>{t('测试中')}</Tag>;
}
if (!testResult) {
return (
<Tag color='grey' shape='circle'>
{t('未开始')}
</Tag>
);
return <Tag>{t('未开始')}</Tag>;
}
return (
<div className='flex items-center gap-2'>
<Tag color={testResult.success ? 'green' : 'red'} shape='circle'>
<div className='model-test-status'>
<Tag color={testResult.success ? 'success' : 'error'}>
{testResult.success ? t('成功') : t('失败')}
</Tag>
{testResult.success && (
<Typography.Text type='tertiary'>
<Typography.Text type='secondary'>
{t('请求时长: ${time}s').replace(
'${time}',
testResult.time.toFixed(2),
@@ -165,13 +150,15 @@ const ModelTestModal = ({
},
},
{
title: '',
title: t('操作'),
dataIndex: 'operate',
width: 72,
align: 'left',
render: (text, record) => {
const isTesting = testingModels.has(record.model);
return (
<Button
type='tertiary'
type='link'
onClick={() =>
testChannel(
currentTestChannel,
@@ -191,9 +178,7 @@ const ModelTestModal = ({
const dataSource = (() => {
if (!hasChannel) return [];
const start = (modelTablePage - 1) * MODEL_TABLE_PAGE_SIZE;
const end = start + MODEL_TABLE_PAGE_SIZE;
return filteredModels.slice(start, end).map((model) => ({
return filteredModels.map((model) => ({
model,
key: model,
}));
@@ -202,114 +187,110 @@ const ModelTestModal = ({
return (
<Modal
title={
hasChannel ? (
<div className='flex flex-col gap-2 w-full'>
<div className='flex items-center gap-2'>
<Typography.Text
strong
className='!text-[var(--ui-color-text-0)] !text-base'
>
{currentTestChannel.name} {t('渠道的模型测试')}
</Typography.Text>
<Typography.Text type='tertiary' size='small'>
{t('共')} {currentTestChannel.models.split(',').length}{' '}
{t('个模型')}
</Typography.Text>
</div>
</div>
) : null
hasChannel ? `${currentTestChannel.name} ${t('渠道的模型测试')}` : null
}
visible={showModelTestModal}
open={showModelTestModal}
onCancel={handleCloseModal}
footer={
hasChannel ? (
<div className='flex justify-end'>
<div className='model-test-footer'>
{isBatchTesting ? (
<Button type='danger' onClick={handleCloseModal}>
<Button danger onClick={handleCloseModal}>
{t('停止测试')}
</Button>
) : (
<Button type='tertiary' onClick={handleCloseModal}>
{t('取消')}
</Button>
<Button onClick={handleCloseModal}>{t('取消')}</Button>
)}
<Button
type='primary'
onClick={batchTestModels}
loading={isBatchTesting}
disabled={isBatchTesting}
disabled={isBatchTesting || selectedModelKeys.length === 0}
>
{isBatchTesting
? t('测试中...')
: t('批量测试${count}个模型').replace(
'${count}',
filteredModels.length,
)}
{isBatchTesting ? t('测试中...') : t('批量测试')}
</Button>
</div>
) : null
}
maskClosable={!isBatchTesting}
className='!rounded-lg'
size={isMobile ? 'full-width' : 'large'}
rootClassName='console-overlay model-test-modal'
width={isMobile ? 'calc(100vw - 32px)' : 514.8}
centered
styles={{ body: { maxHeight: 'none', overflow: 'visible' } }}
>
{hasChannel && (
<div className='model-test-scroll'>
<div className='model-test-content'>
{/* 端点类型选择器 */}
<div className='flex items-center gap-2 w-full mb-2'>
<Typography.Text strong>{t('端点类型')}:</Typography.Text>
<div className='model-test-endpoint'>
<Typography.Text strong id='model-test-endpoint-label'>
{t('端点类型')}:
</Typography.Text>
<Select
value={selectedEndpointType}
onChange={setSelectedEndpointType}
optionList={endpointTypeOptions}
className='!w-full'
options={endpointTypeOptions}
aria-labelledby='model-test-endpoint-label'
placeholder={t('选择端点类型')}
/>
</div>
{/* 搜索与操作按钮 */}
<div className='flex items-center justify-end gap-2 w-full mb-2'>
<div className='model-test-toolbar'>
<Input
placeholder={t('搜索模型...')}
value={modelSearchKeyword}
onChange={(v) => {
setModelSearchKeyword(v);
onChange={(event) => {
setModelSearchKeyword(event.target.value);
setModelTablePage(1);
}}
className='!w-full'
prefix={<IconSearch />}
showClear
prefix={<Search size={16} />}
allowClear
/>
<Button onClick={handleCopySelected}>{t('复制已选')}</Button>
<Button type='tertiary' onClick={handleSelectSuccess}>
{t('选择成功')}
</Button>
<Button onClick={handleSelectSuccess}>{t('选择成功')}</Button>
</div>
<div className='model-test-list-header'>
<Typography.Text strong>{t('模型列表')}</Typography.Text>
<Typography.Text type='secondary'>
{t('共 {{count}} 个模型', { count: models.length })}
</Typography.Text>
<Typography.Text type='secondary' aria-live='polite'>
{t('已选择 {{count}} 个模型', {
count: selectedModelKeys.length,
})}
</Typography.Text>
</div>
<Table
size='middle'
tableLayout='fixed'
className='model-test-table'
columns={columns}
scroll={{
x: 400,
y: `clamp(80px, calc(100dvh - ${isMobile ? 500 : 440}px), 400px)`,
}}
dataSource={dataSource}
rowSelection={{
selectedRowKeys: selectedModelKeys,
onChange: (keys) => {
if (allSelectingRef.current) {
allSelectingRef.current = false;
return;
}
setSelectedModelKeys(keys);
},
onSelectAll: (checked) => {
allSelectingRef.current = true;
setSelectedModelKeys(checked ? filteredModels : []);
},
preserveSelectedRowKeys: true,
columnWidth: 40,
onChange: (keys) => setSelectedModelKeys(keys),
}}
pagination={{
currentPage: modelTablePage,
pageSize: MODEL_TABLE_PAGE_SIZE,
current: modelTablePage,
pageSize: paginationSize,
total: filteredModels.length,
showSizeChanger: false,
onPageChange: (page) => setModelTablePage(page),
showTotal: (total) => t('共 {{total}} 条', { total }),
size: 'small',
onChange: (page, size) => {
setModelTablePage(size !== paginationSize ? 1 : page);
setPaginationSize(size);
},
}}
/>
</div>
@@ -0,0 +1,76 @@
.model-test-list-header {
display: flex;
align-items: baseline;
flex-wrap: wrap;
gap: 8px;
}
.model-test-content {
display: flex;
flex-direction: column;
gap: 16px;
padding-top: 8px;
}
.model-test-endpoint,
.model-test-toolbar,
.model-test-footer {
display: flex;
align-items: center;
gap: 8px;
}
.model-test-endpoint > .ant-typography {
flex-shrink: 0;
white-space: nowrap;
}
.model-test-endpoint > .ant-select,
.model-test-toolbar > .ant-input-affix-wrapper {
flex: 1;
min-width: 0;
}
.model-test-toolbar > .ant-btn {
flex-shrink: 0;
}
.model-test-status {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8px;
}
.model-test-table .ant-table-cell {
overflow-wrap: anywhere;
}
.model-test-table .ant-table-selection-column {
vertical-align: middle;
}
.model-test-table .ant-btn-link {
padding-inline: 0;
}
.model-test-table .ant-table-pagination {
margin: 16px 0 0;
row-gap: 8px;
}
.model-test-footer {
justify-content: flex-end;
flex-wrap: wrap;
padding-top: 8px;
}
@media (max-width: 600px) {
.model-test-toolbar {
flex-wrap: wrap;
}
.model-test-toolbar > .ant-input-affix-wrapper {
flex-basis: 100%;
}
}