2025-02-28 21:13:30 +08:00
|
|
|
|
import React, { useEffect, useState } from 'react';
|
2025-04-04 12:00:38 +08:00
|
|
|
|
import {
|
|
|
|
|
|
Table,
|
|
|
|
|
|
Button,
|
|
|
|
|
|
Input,
|
|
|
|
|
|
Modal,
|
|
|
|
|
|
Form,
|
|
|
|
|
|
Space,
|
|
|
|
|
|
Typography,
|
|
|
|
|
|
Radio,
|
|
|
|
|
|
Notification,
|
|
|
|
|
|
} from '@douyinfe/semi-ui';
|
|
|
|
|
|
import {
|
|
|
|
|
|
IconDelete,
|
|
|
|
|
|
IconPlus,
|
|
|
|
|
|
IconSearch,
|
|
|
|
|
|
IconSave,
|
|
|
|
|
|
IconBolt,
|
|
|
|
|
|
} from '@douyinfe/semi-icons';
|
2025-06-03 23:56:39 +08:00
|
|
|
|
import { API, showError, showSuccess } from '../../../helpers';
|
2025-02-28 21:13:30 +08:00
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
|
|
|
|
|
|
|
export default function ModelRatioNotSetEditor(props) {
|
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
const [models, setModels] = useState([]);
|
|
|
|
|
|
const [visible, setVisible] = useState(false);
|
|
|
|
|
|
const [batchVisible, setBatchVisible] = useState(false);
|
|
|
|
|
|
const [currentModel, setCurrentModel] = useState(null);
|
|
|
|
|
|
const [searchText, setSearchText] = useState('');
|
|
|
|
|
|
const [currentPage, setCurrentPage] = useState(1);
|
|
|
|
|
|
const [pageSize, setPageSize] = useState(10);
|
|
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
|
|
const [enabledModels, setEnabledModels] = useState([]);
|
|
|
|
|
|
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
|
|
|
|
|
|
const [batchFillType, setBatchFillType] = useState('ratio');
|
|
|
|
|
|
const [batchFillValue, setBatchFillValue] = useState('');
|
|
|
|
|
|
const [batchRatioValue, setBatchRatioValue] = useState('');
|
2025-04-04 12:00:38 +08:00
|
|
|
|
const [batchCompletionRatioValue, setBatchCompletionRatioValue] =
|
|
|
|
|
|
useState('');
|
2025-02-28 21:13:30 +08:00
|
|
|
|
const { Text } = Typography;
|
|
|
|
|
|
// 定义可选的每页显示条数
|
|
|
|
|
|
const pageSizeOptions = [10, 20, 50, 100];
|
|
|
|
|
|
|
|
|
|
|
|
const getAllEnabledModels = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = await API.get('/api/channel/models_enabled');
|
|
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
|
if (success) {
|
|
|
|
|
|
setEnabledModels(data);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
showError(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error(t('获取启用模型失败:'), error);
|
|
|
|
|
|
showError(t('获取启用模型失败'));
|
|
|
|
|
|
}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
};
|
2025-02-28 21:13:30 +08:00
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
// 获取所有启用的模型
|
|
|
|
|
|
getAllEnabledModels();
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const modelPrice = JSON.parse(props.options.ModelPrice || '{}');
|
|
|
|
|
|
const modelRatio = JSON.parse(props.options.ModelRatio || '{}');
|
|
|
|
|
|
const completionRatio = JSON.parse(props.options.CompletionRatio || '{}');
|
|
|
|
|
|
|
|
|
|
|
|
// 找出所有未设置价格和倍率的模型
|
2025-04-04 12:00:38 +08:00
|
|
|
|
const unsetModels = enabledModels.filter((modelName) => {
|
2025-02-28 21:13:30 +08:00
|
|
|
|
const hasPrice = modelPrice[modelName] !== undefined;
|
|
|
|
|
|
const hasRatio = modelRatio[modelName] !== undefined;
|
2025-04-04 12:00:38 +08:00
|
|
|
|
|
2025-02-28 23:28:47 +08:00
|
|
|
|
// 如果模型没有价格或者没有倍率设置,则显示
|
|
|
|
|
|
return !hasPrice && !hasRatio;
|
2025-02-28 21:13:30 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 创建模型数据
|
2025-04-04 12:00:38 +08:00
|
|
|
|
const modelData = unsetModels.map((name) => ({
|
2025-02-28 21:13:30 +08:00
|
|
|
|
name,
|
2025-02-28 23:28:47 +08:00
|
|
|
|
price: modelPrice[name] || '',
|
|
|
|
|
|
ratio: modelRatio[name] || '',
|
2025-04-04 12:00:38 +08:00
|
|
|
|
completionRatio: completionRatio[name] || '',
|
2025-02-28 21:13:30 +08:00
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
setModels(modelData);
|
|
|
|
|
|
// 清空选择
|
|
|
|
|
|
setSelectedRowKeys([]);
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error(t('JSON解析错误:'), error);
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [props.options, enabledModels]);
|
|
|
|
|
|
|
|
|
|
|
|
// 首先声明分页相关的工具函数
|
|
|
|
|
|
const getPagedData = (data, currentPage, pageSize) => {
|
|
|
|
|
|
const start = (currentPage - 1) * pageSize;
|
|
|
|
|
|
const end = start + pageSize;
|
|
|
|
|
|
return data.slice(start, end);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 处理页面大小变化
|
|
|
|
|
|
const handlePageSizeChange = (size) => {
|
|
|
|
|
|
setPageSize(size);
|
|
|
|
|
|
// 重新计算当前页,避免数据丢失
|
|
|
|
|
|
const totalPages = Math.ceil(filteredModels.length / size);
|
|
|
|
|
|
if (currentPage > totalPages) {
|
|
|
|
|
|
setCurrentPage(totalPages || 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 在 return 语句之前,先处理过滤和分页逻辑
|
2025-04-04 12:00:38 +08:00
|
|
|
|
const filteredModels = models.filter((model) =>
|
|
|
|
|
|
searchText
|
|
|
|
|
|
? model.name.toLowerCase().includes(searchText.toLowerCase())
|
|
|
|
|
|
: true,
|
2025-02-28 21:13:30 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// 然后基于过滤后的数据计算分页数据
|
|
|
|
|
|
const pagedData = getPagedData(filteredModels, currentPage, pageSize);
|
|
|
|
|
|
|
|
|
|
|
|
const SubmitData = async () => {
|
|
|
|
|
|
setLoading(true);
|
|
|
|
|
|
const output = {
|
|
|
|
|
|
ModelPrice: JSON.parse(props.options.ModelPrice || '{}'),
|
|
|
|
|
|
ModelRatio: JSON.parse(props.options.ModelRatio || '{}'),
|
2025-04-04 12:00:38 +08:00
|
|
|
|
CompletionRatio: JSON.parse(props.options.CompletionRatio || '{}'),
|
2025-02-28 21:13:30 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 数据转换 - 只处理已修改的模型
|
2025-04-04 12:00:38 +08:00
|
|
|
|
models.forEach((model) => {
|
2025-02-28 21:13:30 +08:00
|
|
|
|
// 只有当用户设置了值时才更新
|
|
|
|
|
|
if (model.price !== '') {
|
|
|
|
|
|
// 如果价格不为空,则转换为浮点数,忽略倍率参数
|
|
|
|
|
|
output.ModelPrice[model.name] = parseFloat(model.price);
|
|
|
|
|
|
} else {
|
2025-04-04 12:00:38 +08:00
|
|
|
|
if (model.ratio !== '')
|
|
|
|
|
|
output.ModelRatio[model.name] = parseFloat(model.ratio);
|
|
|
|
|
|
if (model.completionRatio !== '')
|
|
|
|
|
|
output.CompletionRatio[model.name] = parseFloat(
|
|
|
|
|
|
model.completionRatio,
|
|
|
|
|
|
);
|
2025-02-28 21:13:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 准备API请求数组
|
|
|
|
|
|
const finalOutput = {
|
|
|
|
|
|
ModelPrice: JSON.stringify(output.ModelPrice, null, 2),
|
|
|
|
|
|
ModelRatio: JSON.stringify(output.ModelRatio, null, 2),
|
2025-04-04 12:00:38 +08:00
|
|
|
|
CompletionRatio: JSON.stringify(output.CompletionRatio, null, 2),
|
2025-02-28 21:13:30 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const requestQueue = Object.entries(finalOutput).map(([key, value]) => {
|
|
|
|
|
|
return API.put('/api/option/', {
|
|
|
|
|
|
key,
|
2025-04-04 12:00:38 +08:00
|
|
|
|
value,
|
2025-02-28 21:13:30 +08:00
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 批量处理请求
|
|
|
|
|
|
const results = await Promise.all(requestQueue);
|
|
|
|
|
|
|
|
|
|
|
|
// 验证结果
|
|
|
|
|
|
if (requestQueue.length === 1) {
|
|
|
|
|
|
if (results.includes(undefined)) return;
|
|
|
|
|
|
} else if (requestQueue.length > 1) {
|
|
|
|
|
|
if (results.includes(undefined)) {
|
|
|
|
|
|
return showError(t('部分保存失败,请重试'));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查每个请求的结果
|
|
|
|
|
|
for (const res of results) {
|
|
|
|
|
|
if (!res.data.success) {
|
|
|
|
|
|
return showError(res.data.message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
showSuccess(t('保存成功'));
|
|
|
|
|
|
props.refresh();
|
|
|
|
|
|
// 重新获取未设置的模型
|
|
|
|
|
|
getAllEnabledModels();
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error(t('保存失败:'), error);
|
|
|
|
|
|
showError(t('保存失败,请重试'));
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
setLoading(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const columns = [
|
|
|
|
|
|
{
|
|
|
|
|
|
title: t('模型名称'),
|
|
|
|
|
|
dataIndex: 'name',
|
|
|
|
|
|
key: 'name',
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: t('模型固定价格'),
|
|
|
|
|
|
dataIndex: 'price',
|
|
|
|
|
|
key: 'price',
|
|
|
|
|
|
render: (text, record) => (
|
|
|
|
|
|
<Input
|
|
|
|
|
|
value={text}
|
|
|
|
|
|
placeholder={t('按量计费')}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
onChange={(value) => updateModel(record.name, 'price', value)}
|
2025-02-28 21:13:30 +08:00
|
|
|
|
/>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
),
|
2025-02-28 21:13:30 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: t('模型倍率'),
|
|
|
|
|
|
dataIndex: 'ratio',
|
|
|
|
|
|
key: 'ratio',
|
|
|
|
|
|
render: (text, record) => (
|
|
|
|
|
|
<Input
|
|
|
|
|
|
value={text}
|
|
|
|
|
|
placeholder={record.price !== '' ? t('模型倍率') : t('输入模型倍率')}
|
|
|
|
|
|
disabled={record.price !== ''}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
onChange={(value) => updateModel(record.name, 'ratio', value)}
|
2025-02-28 21:13:30 +08:00
|
|
|
|
/>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
),
|
2025-02-28 21:13:30 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: t('补全倍率'),
|
|
|
|
|
|
dataIndex: 'completionRatio',
|
|
|
|
|
|
key: 'completionRatio',
|
|
|
|
|
|
render: (text, record) => (
|
|
|
|
|
|
<Input
|
|
|
|
|
|
value={text}
|
|
|
|
|
|
placeholder={record.price !== '' ? t('补全倍率') : t('输入补全倍率')}
|
|
|
|
|
|
disabled={record.price !== ''}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
onChange={(value) =>
|
|
|
|
|
|
updateModel(record.name, 'completionRatio', value)
|
|
|
|
|
|
}
|
2025-02-28 21:13:30 +08:00
|
|
|
|
/>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
),
|
|
|
|
|
|
},
|
2025-02-28 21:13:30 +08:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const updateModel = (name, field, value) => {
|
|
|
|
|
|
if (value !== '' && isNaN(value)) {
|
|
|
|
|
|
showError(t('请输入数字'));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
setModels((prev) =>
|
|
|
|
|
|
prev.map((model) =>
|
|
|
|
|
|
model.name === name ? { ...model, [field]: value } : model,
|
|
|
|
|
|
),
|
2025-02-28 21:13:30 +08:00
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const addModel = (values) => {
|
|
|
|
|
|
// 检查模型名称是否存在, 如果存在则拒绝添加
|
2025-04-04 12:00:38 +08:00
|
|
|
|
if (models.some((model) => model.name === values.name)) {
|
2025-02-28 21:13:30 +08:00
|
|
|
|
showError(t('模型名称已存在'));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
setModels((prev) => [
|
|
|
|
|
|
{
|
|
|
|
|
|
name: values.name,
|
|
|
|
|
|
price: values.price || '',
|
|
|
|
|
|
ratio: values.ratio || '',
|
|
|
|
|
|
completionRatio: values.completionRatio || '',
|
|
|
|
|
|
},
|
|
|
|
|
|
...prev,
|
|
|
|
|
|
]);
|
2025-02-28 21:13:30 +08:00
|
|
|
|
setVisible(false);
|
|
|
|
|
|
showSuccess(t('添加成功'));
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 批量填充功能
|
|
|
|
|
|
const handleBatchFill = () => {
|
|
|
|
|
|
if (selectedRowKeys.length === 0) {
|
|
|
|
|
|
showError(t('请先选择需要批量设置的模型'));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (batchFillType === 'bothRatio') {
|
|
|
|
|
|
if (batchRatioValue === '' || batchCompletionRatioValue === '') {
|
|
|
|
|
|
showError(t('请输入模型倍率和补全倍率'));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (isNaN(batchRatioValue) || isNaN(batchCompletionRatioValue)) {
|
|
|
|
|
|
showError(t('请输入有效的数字'));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (batchFillValue === '') {
|
|
|
|
|
|
showError(t('请输入填充值'));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (isNaN(batchFillValue)) {
|
|
|
|
|
|
showError(t('请输入有效的数字'));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 根据选择的类型批量更新模型
|
2025-04-04 12:00:38 +08:00
|
|
|
|
setModels((prev) =>
|
|
|
|
|
|
prev.map((model) => {
|
2025-02-28 21:13:30 +08:00
|
|
|
|
if (selectedRowKeys.includes(model.name)) {
|
|
|
|
|
|
if (batchFillType === 'price') {
|
|
|
|
|
|
return {
|
|
|
|
|
|
...model,
|
|
|
|
|
|
price: batchFillValue,
|
|
|
|
|
|
ratio: '',
|
2025-04-04 12:00:38 +08:00
|
|
|
|
completionRatio: '',
|
2025-02-28 21:13:30 +08:00
|
|
|
|
};
|
|
|
|
|
|
} else if (batchFillType === 'ratio') {
|
|
|
|
|
|
return {
|
|
|
|
|
|
...model,
|
|
|
|
|
|
price: '',
|
2025-04-04 12:00:38 +08:00
|
|
|
|
ratio: batchFillValue,
|
2025-02-28 21:13:30 +08:00
|
|
|
|
};
|
|
|
|
|
|
} else if (batchFillType === 'completionRatio') {
|
|
|
|
|
|
return {
|
|
|
|
|
|
...model,
|
|
|
|
|
|
price: '',
|
2025-04-04 12:00:38 +08:00
|
|
|
|
completionRatio: batchFillValue,
|
2025-02-28 21:13:30 +08:00
|
|
|
|
};
|
|
|
|
|
|
} else if (batchFillType === 'bothRatio') {
|
|
|
|
|
|
return {
|
|
|
|
|
|
...model,
|
|
|
|
|
|
price: '',
|
|
|
|
|
|
ratio: batchRatioValue,
|
2025-04-04 12:00:38 +08:00
|
|
|
|
completionRatio: batchCompletionRatioValue,
|
2025-02-28 21:13:30 +08:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return model;
|
2025-04-04 12:00:38 +08:00
|
|
|
|
}),
|
2025-02-28 21:13:30 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
setBatchVisible(false);
|
|
|
|
|
|
Notification.success({
|
|
|
|
|
|
title: t('批量设置成功'),
|
|
|
|
|
|
content: t('已为 {{count}} 个模型设置{{type}}', {
|
|
|
|
|
|
count: selectedRowKeys.length,
|
2025-04-04 12:00:38 +08:00
|
|
|
|
type:
|
|
|
|
|
|
batchFillType === 'price'
|
|
|
|
|
|
? t('固定价格')
|
|
|
|
|
|
: batchFillType === 'ratio'
|
|
|
|
|
|
? t('模型倍率')
|
|
|
|
|
|
: batchFillType === 'completionRatio'
|
|
|
|
|
|
? t('补全倍率')
|
|
|
|
|
|
: t('模型倍率和补全倍率'),
|
2025-02-28 21:13:30 +08:00
|
|
|
|
}),
|
|
|
|
|
|
duration: 3,
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleBatchTypeChange = (value) => {
|
|
|
|
|
|
console.log(t('Changing batch type to:'), value);
|
|
|
|
|
|
setBatchFillType(value);
|
2025-04-04 12:00:38 +08:00
|
|
|
|
|
2025-02-28 21:13:30 +08:00
|
|
|
|
// 切换类型时清空对应的值
|
|
|
|
|
|
if (value !== 'bothRatio') {
|
|
|
|
|
|
setBatchFillValue('');
|
|
|
|
|
|
} else {
|
|
|
|
|
|
setBatchRatioValue('');
|
|
|
|
|
|
setBatchCompletionRatioValue('');
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const rowSelection = {
|
|
|
|
|
|
selectedRowKeys,
|
|
|
|
|
|
onChange: (selectedKeys) => {
|
|
|
|
|
|
setSelectedRowKeys(selectedKeys);
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
<Space vertical align='start' style={{ width: '100%' }}>
|
2025-02-28 21:13:30 +08:00
|
|
|
|
<Space>
|
|
|
|
|
|
<Button icon={<IconPlus />} onClick={() => setVisible(true)}>
|
|
|
|
|
|
{t('添加模型')}
|
|
|
|
|
|
</Button>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
<Button
|
|
|
|
|
|
icon={<IconBolt />}
|
|
|
|
|
|
type='secondary'
|
2025-02-28 21:13:30 +08:00
|
|
|
|
onClick={() => setBatchVisible(true)}
|
|
|
|
|
|
disabled={selectedRowKeys.length === 0}
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('批量设置')} ({selectedRowKeys.length})
|
|
|
|
|
|
</Button>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
<Button
|
|
|
|
|
|
type='primary'
|
|
|
|
|
|
icon={<IconSave />}
|
|
|
|
|
|
onClick={SubmitData}
|
|
|
|
|
|
loading={loading}
|
|
|
|
|
|
>
|
2025-02-28 21:13:30 +08:00
|
|
|
|
{t('应用更改')}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
prefix={<IconSearch />}
|
|
|
|
|
|
placeholder={t('搜索模型名称')}
|
|
|
|
|
|
value={searchText}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
setSearchText(value);
|
2025-02-28 21:13:30 +08:00
|
|
|
|
setCurrentPage(1);
|
|
|
|
|
|
}}
|
|
|
|
|
|
style={{ width: 200 }}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</Space>
|
|
|
|
|
|
|
2025-04-04 12:00:38 +08:00
|
|
|
|
<Text>
|
|
|
|
|
|
{t('此页面仅显示未设置价格或倍率的模型,设置后将自动从列表中移除')}
|
|
|
|
|
|
</Text>
|
|
|
|
|
|
|
2025-02-28 21:13:30 +08:00
|
|
|
|
<Table
|
|
|
|
|
|
columns={columns}
|
|
|
|
|
|
dataSource={pagedData}
|
|
|
|
|
|
rowSelection={rowSelection}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
rowKey='name'
|
2025-02-28 21:13:30 +08:00
|
|
|
|
pagination={{
|
|
|
|
|
|
currentPage: currentPage,
|
|
|
|
|
|
pageSize: pageSize,
|
|
|
|
|
|
total: filteredModels.length,
|
2025-04-04 12:00:38 +08:00
|
|
|
|
onPageChange: (page) => setCurrentPage(page),
|
2025-02-28 21:13:30 +08:00
|
|
|
|
onPageSizeChange: handlePageSizeChange,
|
|
|
|
|
|
pageSizeOptions: pageSizeOptions,
|
|
|
|
|
|
formatPageText: (page) =>
|
|
|
|
|
|
t('第 {{start}} - {{end}} 条,共 {{total}} 条', {
|
|
|
|
|
|
start: page.currentStart,
|
|
|
|
|
|
end: page.currentEnd,
|
2025-04-04 12:00:38 +08:00
|
|
|
|
total: filteredModels.length,
|
2025-02-28 21:13:30 +08:00
|
|
|
|
}),
|
|
|
|
|
|
showTotal: true,
|
2025-04-04 12:00:38 +08:00
|
|
|
|
showSizeChanger: true,
|
2025-02-28 21:13:30 +08:00
|
|
|
|
}}
|
|
|
|
|
|
empty={
|
|
|
|
|
|
<div style={{ textAlign: 'center', padding: '20px' }}>
|
|
|
|
|
|
{t('没有未设置的模型')}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</Space>
|
|
|
|
|
|
|
|
|
|
|
|
{/* 添加模型弹窗 */}
|
|
|
|
|
|
<Modal
|
|
|
|
|
|
title={t('添加模型')}
|
|
|
|
|
|
visible={visible}
|
|
|
|
|
|
onCancel={() => setVisible(false)}
|
|
|
|
|
|
onOk={() => {
|
|
|
|
|
|
currentModel && addModel(currentModel);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Form>
|
|
|
|
|
|
<Form.Input
|
2025-04-04 12:00:38 +08:00
|
|
|
|
field='name'
|
2025-02-28 21:13:30 +08:00
|
|
|
|
label={t('模型名称')}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
placeholder='strawberry'
|
2025-02-28 21:13:30 +08:00
|
|
|
|
required
|
2025-04-04 12:00:38 +08:00
|
|
|
|
onChange={(value) =>
|
|
|
|
|
|
setCurrentModel((prev) => ({ ...prev, name: value }))
|
|
|
|
|
|
}
|
2025-02-28 21:13:30 +08:00
|
|
|
|
/>
|
|
|
|
|
|
<Form.Switch
|
2025-04-04 12:00:38 +08:00
|
|
|
|
field='priceMode'
|
|
|
|
|
|
label={
|
|
|
|
|
|
<>
|
|
|
|
|
|
{t('定价模式')}:
|
|
|
|
|
|
{currentModel?.priceMode ? t('固定价格') : t('倍率模式')}
|
|
|
|
|
|
</>
|
|
|
|
|
|
}
|
|
|
|
|
|
onChange={(checked) => {
|
|
|
|
|
|
setCurrentModel((prev) => ({
|
2025-02-28 21:13:30 +08:00
|
|
|
|
...prev,
|
|
|
|
|
|
price: '',
|
|
|
|
|
|
ratio: '',
|
|
|
|
|
|
completionRatio: '',
|
2025-04-04 12:00:38 +08:00
|
|
|
|
priceMode: checked,
|
2025-02-28 21:13:30 +08:00
|
|
|
|
}));
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
{currentModel?.priceMode ? (
|
|
|
|
|
|
<Form.Input
|
2025-04-04 12:00:38 +08:00
|
|
|
|
field='price'
|
2025-02-28 21:13:30 +08:00
|
|
|
|
label={t('固定价格(每次)')}
|
|
|
|
|
|
placeholder={t('输入每次价格')}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
onChange={(value) =>
|
|
|
|
|
|
setCurrentModel((prev) => ({ ...prev, price: value }))
|
|
|
|
|
|
}
|
2025-02-28 21:13:30 +08:00
|
|
|
|
/>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<Form.Input
|
2025-04-04 12:00:38 +08:00
|
|
|
|
field='ratio'
|
2025-02-28 21:13:30 +08:00
|
|
|
|
label={t('模型倍率')}
|
|
|
|
|
|
placeholder={t('输入模型倍率')}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
onChange={(value) =>
|
|
|
|
|
|
setCurrentModel((prev) => ({ ...prev, ratio: value }))
|
|
|
|
|
|
}
|
2025-02-28 21:13:30 +08:00
|
|
|
|
/>
|
|
|
|
|
|
<Form.Input
|
2025-04-04 12:00:38 +08:00
|
|
|
|
field='completionRatio'
|
2025-02-28 21:13:30 +08:00
|
|
|
|
label={t('补全倍率')}
|
|
|
|
|
|
placeholder={t('输入补全价格')}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
onChange={(value) =>
|
|
|
|
|
|
setCurrentModel((prev) => ({
|
|
|
|
|
|
...prev,
|
|
|
|
|
|
completionRatio: value,
|
|
|
|
|
|
}))
|
|
|
|
|
|
}
|
2025-02-28 21:13:30 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</Form>
|
|
|
|
|
|
</Modal>
|
|
|
|
|
|
|
|
|
|
|
|
{/* 批量设置弹窗 */}
|
|
|
|
|
|
<Modal
|
|
|
|
|
|
title={t('批量设置模型参数')}
|
|
|
|
|
|
visible={batchVisible}
|
|
|
|
|
|
onCancel={() => setBatchVisible(false)}
|
|
|
|
|
|
onOk={handleBatchFill}
|
|
|
|
|
|
width={500}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Form>
|
|
|
|
|
|
<Form.Section text={t('设置类型')}>
|
|
|
|
|
|
<div style={{ marginBottom: '16px' }}>
|
|
|
|
|
|
<Space>
|
|
|
|
|
|
<Radio
|
|
|
|
|
|
checked={batchFillType === 'price'}
|
|
|
|
|
|
onChange={() => handleBatchTypeChange('price')}
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('固定价格')}
|
|
|
|
|
|
</Radio>
|
|
|
|
|
|
<Radio
|
|
|
|
|
|
checked={batchFillType === 'ratio'}
|
|
|
|
|
|
onChange={() => handleBatchTypeChange('ratio')}
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('模型倍率')}
|
|
|
|
|
|
</Radio>
|
|
|
|
|
|
<Radio
|
|
|
|
|
|
checked={batchFillType === 'completionRatio'}
|
|
|
|
|
|
onChange={() => handleBatchTypeChange('completionRatio')}
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('补全倍率')}
|
|
|
|
|
|
</Radio>
|
|
|
|
|
|
<Radio
|
|
|
|
|
|
checked={batchFillType === 'bothRatio'}
|
|
|
|
|
|
onChange={() => handleBatchTypeChange('bothRatio')}
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('模型倍率和补全倍率同时设置')}
|
|
|
|
|
|
</Radio>
|
|
|
|
|
|
</Space>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Form.Section>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
|
2025-02-28 21:13:30 +08:00
|
|
|
|
{batchFillType === 'bothRatio' ? (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<Form.Input
|
2025-04-04 12:00:38 +08:00
|
|
|
|
field='batchRatioValue'
|
2025-02-28 21:13:30 +08:00
|
|
|
|
label={t('模型倍率值')}
|
|
|
|
|
|
placeholder={t('请输入模型倍率')}
|
|
|
|
|
|
value={batchRatioValue}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
onChange={(value) => setBatchRatioValue(value)}
|
2025-02-28 21:13:30 +08:00
|
|
|
|
/>
|
|
|
|
|
|
<Form.Input
|
2025-04-04 12:00:38 +08:00
|
|
|
|
field='batchCompletionRatioValue'
|
2025-02-28 21:13:30 +08:00
|
|
|
|
label={t('补全倍率值')}
|
|
|
|
|
|
placeholder={t('请输入补全倍率')}
|
|
|
|
|
|
value={batchCompletionRatioValue}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
onChange={(value) => setBatchCompletionRatioValue(value)}
|
2025-02-28 21:13:30 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<Form.Input
|
2025-04-04 12:00:38 +08:00
|
|
|
|
field='batchFillValue'
|
2025-02-28 21:13:30 +08:00
|
|
|
|
label={
|
2025-04-04 12:00:38 +08:00
|
|
|
|
batchFillType === 'price'
|
|
|
|
|
|
? t('固定价格值')
|
2025-02-28 21:13:30 +08:00
|
|
|
|
: batchFillType === 'ratio'
|
|
|
|
|
|
? t('模型倍率值')
|
|
|
|
|
|
: t('补全倍率值')
|
|
|
|
|
|
}
|
|
|
|
|
|
placeholder={t('请输入数值')}
|
|
|
|
|
|
value={batchFillValue}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
onChange={(value) => setBatchFillValue(value)}
|
2025-02-28 21:13:30 +08:00
|
|
|
|
/>
|
|
|
|
|
|
)}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
|
|
|
|
|
|
<Text type='tertiary'>
|
|
|
|
|
|
{t('将为选中的 ')} <Text strong>{selectedRowKeys.length}</Text>{' '}
|
|
|
|
|
|
{t(' 个模型设置相同的值')}
|
2025-02-28 21:13:30 +08:00
|
|
|
|
</Text>
|
|
|
|
|
|
<div style={{ marginTop: '8px' }}>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
<Text type='tertiary'>
|
|
|
|
|
|
{t('当前设置类型: ')}{' '}
|
|
|
|
|
|
<Text strong>
|
|
|
|
|
|
{batchFillType === 'price'
|
|
|
|
|
|
? t('固定价格')
|
|
|
|
|
|
: batchFillType === 'ratio'
|
|
|
|
|
|
? t('模型倍率')
|
|
|
|
|
|
: batchFillType === 'completionRatio'
|
|
|
|
|
|
? t('补全倍率')
|
|
|
|
|
|
: t('模型倍率和补全倍率')}
|
|
|
|
|
|
</Text>
|
2025-02-28 21:13:30 +08:00
|
|
|
|
</Text>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Form>
|
|
|
|
|
|
</Modal>
|
|
|
|
|
|
</>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|