Merge pull request #242 from iszcz/new512

渠道批量添加模型
This commit is contained in:
Calcium-Ion 2024-05-13 14:33:57 +08:00 committed by GitHub
commit 5ac3d25f54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -99,6 +99,7 @@ const EditChannel = (props) => {
'mj_blend', 'mj_blend',
'mj_upscale', 'mj_upscale',
'mj_describe', 'mj_describe',
'mj_uploads',
]; ];
break; break;
case 5: case 5:
@ -118,6 +119,7 @@ const EditChannel = (props) => {
'mj_high_variation', 'mj_high_variation',
'mj_low_variation', 'mj_low_variation',
'mj_pan', 'mj_pan',
'mj_uploads',
]; ];
break; break;
default: default:
@ -296,24 +298,39 @@ const EditChannel = (props) => {
} }
}; };
const addCustomModel = () => { const addCustomModels = () => {
if (customModel.trim() === '') return; if (customModel.trim() === '') return;
if (inputs.models.includes(customModel)) return showError('该模型已存在!'); // 使用逗号分隔字符串,然后去除每个模型名称前后的空格
const modelArray = customModel.split(',').map(model => model.trim());
let localModels = [...inputs.models]; let localModels = [...inputs.models];
localModels.push(customModel); let localModelOptions = [...modelOptions];
let localModelOptions = []; let hasError = false;
localModelOptions.push({
key: customModel, modelArray.forEach(model => {
text: customModel, // 检查模型是否已存在,且模型名称非空
value: customModel, if (model && !localModels.includes(model)) {
localModels.push(model); // 添加到模型列表
localModelOptions.push({ // 添加到下拉选项
key: model,
text: model,
value: model,
}); });
setModelOptions((modelOptions) => { } else if (model) {
return [...modelOptions, ...localModelOptions]; showError('某些模型已存在!');
hasError = true;
}
}); });
if (hasError) return; // 如果有错误则终止操作
// 更新状态值
setModelOptions(localModelOptions);
setCustomModel(''); setCustomModel('');
handleInputChange('models', localModels); handleInputChange('models', localModels);
}; };
return ( return (
<> <>
<SideSheet <SideSheet
@ -540,7 +557,7 @@ const EditChannel = (props) => {
</Space> </Space>
<Input <Input
addonAfter={ addonAfter={
<Button type='primary' onClick={addCustomModel}> <Button type='primary' onClick={addCustomModels}>
填入 填入
</Button> </Button>
} }