From 5f0322b67240550ff86eeda97c2cd1d60540c0a5 Mon Sep 17 00:00:00 2001 From: CalciumIon <1808837298@qq.com> Date: Wed, 11 Dec 2024 21:31:29 +0800 Subject: [PATCH] feat: Add custom model input functionality in EditTagModal - Introduced a new input field for adding custom model names in the EditTagModal component. - Implemented logic to handle the addition of custom models, including validation to prevent duplicates. - Enhanced user experience by providing feedback when attempting to add existing models. - Updated state management to reflect changes in the model options dynamically. --- web/src/pages/Channel/EditTagModal.js | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/web/src/pages/Channel/EditTagModal.js b/web/src/pages/Channel/EditTagModal.js index 2182980d..b38a7dcb 100644 --- a/web/src/pages/Channel/EditTagModal.js +++ b/web/src/pages/Channel/EditTagModal.js @@ -16,6 +16,7 @@ const EditTagModal = (props) => { const [groupOptions, setGroupOptions] = useState([]); const [basicModels, setBasicModels] = useState([]); const [fullModels, setFullModels] = useState([]); + const [customModel, setCustomModel] = useState(''); const originInputs = { tag: '', new_tag: null, @@ -183,6 +184,40 @@ const EditTagModal = (props) => { fetchGroups().then(); }, [visible]); + const addCustomModels = () => { + if (customModel.trim() === '') return; + // 使用逗号分隔字符串,然后去除每个模型名称前后的空格 + const modelArray = customModel.split(',').map((model) => model.trim()); + + let localModels = [...inputs.models]; + let localModelOptions = [...modelOptions]; + let hasError = false; + + modelArray.forEach((model) => { + // 检查模型是否已存在,且模型名称非空 + if (model && !localModels.includes(model)) { + localModels.push(model); // 添加到模型列表 + localModelOptions.push({ + // 添加到下拉选项 + key: model, + text: model, + value: model + }); + } else if (model) { + showError('某些模型已存在!'); + hasError = true; + } + }); + + if (hasError) return; // 如果有错误则终止操作 + + // 更新状态值 + setModelOptions(localModelOptions); + setCustomModel(''); + handleInputChange('models', localModels); + }; + + return ( { autoComplete="new-password" optionList={modelOptions} /> + + 填入 + + } + placeholder="输入自定义模型名称" + value={customModel} + onChange={(value) => { + setCustomModel(value.trim()); + }} + />
分组,留空则不更改: