From d0fb54fbfeacec009d9266ad7e3fdafc081a2ee5 Mon Sep 17 00:00:00 2001 From: t0ng7u Date: Fri, 8 Aug 2025 04:48:18 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(web):=20add=20model=20prefill?= =?UTF-8?q?=20group=20quick-add=20buttons=20to=20channel=20models=20select?= =?UTF-8?q?or?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added support to fetch and render “model prefill groups” in `EditChannelModal.jsx` - Users can now click a group button to instantly merge that group’s models into the models Select - Mirrors the prefill-group UX used for tags/endpoints in `EditModelModal.jsx` Details - UI/UX: - Renders one button per model group inside the models field’s extra actions - Clicking a button merges its items into the selected models (trimmed, deduplicated), updating immediately - Non-destructive and works alongside existing actions (fill related/all models, fetch upstream, clear, copy) - API: - GET `/api/prefill_group?type=model` - Handles `items` as either an array or a JSON string array for robustness - If request fails or returns no groups, buttons are simply not shown - i18n: - Reuses existing i18n; group names come from backend and are displayed as-is - Performance: - Simple set merge; negligible overhead - Backward compatibility: - No changes required on the backend or elsewhere; feature is additive - Testing (manual): 1) Open channel modal (new or edit) and navigate to the Models section 2) Confirm model group buttons render when groups are configured 3) Click a group button → models Select updates with merged models (no duplicates) 4) Verify other actions (fill related/all, fetch upstream, clear, copy) still work 5) Close/reopen modal → state resets as expected Implementation - `web/src/components/table/channels/modals/EditChannelModal.jsx` - Added `modelGroups` state and `fetchModelGroups()` (GET `/api/prefill_group?type=model`) - Invoked `fetchModelGroups()` when the modal opens - Rendered group buttons in the models Select `extraText`, merging group items into current selection Chore - Verified no new linter errors were introduced. --- .../channels/modals/EditChannelModal.jsx | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/web/src/components/table/channels/modals/EditChannelModal.jsx b/web/src/components/table/channels/modals/EditChannelModal.jsx index a971b094..40aedcbf 100644 --- a/web/src/components/table/channels/modals/EditChannelModal.jsx +++ b/web/src/components/table/channels/modals/EditChannelModal.jsx @@ -142,6 +142,7 @@ const EditChannelModal = (props) => { const [groupOptions, setGroupOptions] = useState([]); const [basicModels, setBasicModels] = useState([]); const [fullModels, setFullModels] = useState([]); + const [modelGroups, setModelGroups] = useState([]); const [customModel, setCustomModel] = useState(''); const [modalImageUrl, setModalImageUrl] = useState(''); const [isModalOpenurl, setIsModalOpenurl] = useState(false); @@ -477,6 +478,17 @@ const EditChannelModal = (props) => { } }; + const fetchModelGroups = async () => { + try { + const res = await API.get('/api/prefill_group?type=model'); + if (res?.data?.success) { + setModelGroups(res.data.data || []); + } + } catch (error) { + // ignore + } + }; + useEffect(() => { const modelMap = new Map(); @@ -549,6 +561,7 @@ const EditChannelModal = (props) => { } else { formApiRef.current?.setValues(getInitValues()); } + fetchModelGroups(); // 重置手动输入模式状态 setUseManualInput(false); } else { @@ -1478,6 +1491,32 @@ const EditChannelModal = (props) => { > {t('复制所有模型')} + {modelGroups && modelGroups.length > 0 && modelGroups.map(group => ( + + ))} )} />