From f07f2c25f4266888ec7d18e4b6d6312c2bdc1af4 Mon Sep 17 00:00:00 2001 From: fengsilin Date: Thu, 14 May 2026 17:28:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(rate-limit):=20=E7=94=A8=E6=88=B7=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E9=99=90=E6=B5=81=E9=85=8D=E7=BD=AE=E6=94=B9=E7=94=A8?= =?UTF-8?q?=E4=B8=8B=E6=8B=89=E9=80=89=E6=8B=A9=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将添加模型限流时的文本输入改为从渠道模型列表中选择, 并自动过滤已配置的模型,提升配置体验和准确性。 --- .../modals/UserModelRateLimitSection.jsx | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/web/src/components/table/users/modals/UserModelRateLimitSection.jsx b/web/src/components/table/users/modals/UserModelRateLimitSection.jsx index 6e169be..fe81b33 100644 --- a/web/src/components/table/users/modals/UserModelRateLimitSection.jsx +++ b/web/src/components/table/users/modals/UserModelRateLimitSection.jsx @@ -1,6 +1,6 @@ import React, { useEffect, useState, useRef } from 'react'; import { useTranslation } from 'react-i18next'; -import { userRateLimitApi, showError, showSuccess } from '../../../../helpers'; +import { API, userRateLimitApi, showError, showSuccess } from '../../../../helpers'; import { Button, Table, @@ -19,6 +19,7 @@ const UserModelRateLimitSection = ({ userId }) => { const [limits, setLimits] = useState([]); const [loading, setLoading] = useState(false); const [addModalVisible, setAddModalVisible] = useState(false); + const [modelOptions, setModelOptions] = useState([]); const formApiRef = useRef(null); const loadLimits = async () => { @@ -42,6 +43,21 @@ const UserModelRateLimitSection = ({ userId }) => { loadLimits(); }, [userId]); + useEffect(() => { + const loadModels = async () => { + try { + const res = await API.get('/api/channel/models'); + const { success, data } = res.data; + if (success && Array.isArray(data)) { + setModelOptions(data.map((m) => ({ label: m.id, value: m.id }))); + } + } catch (e) { + // ignore + } + }; + loadModels(); + }, []); + const saveLimits = async (newLimits) => { try { const res = await userRateLimitApi.set(userId, newLimits); @@ -165,11 +181,16 @@ const UserModelRateLimitSection = ({ userId }) => { getFormApi={(api) => (formApiRef.current = api)} onSubmit={handleAdd} > - !limits.some((l) => l.model === opt.value), + )} + filter + showClear + rules={[{ required: true, message: t('请选择模型') }]} style={{ width: '100%' }} />