feat: 自行开发设计 ui样式优化 超管端-控制台 相关的页面
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user