From 6ad8a1517f5237a066fa51c4042760bfb110c742 Mon Sep 17 00:00:00 2001 From: sp mac bookpro 2605 Date: Fri, 29 May 2026 14:05:12 +0800 Subject: [PATCH] refactor(agent-editor): use dropdown checkbox model picker --- src/pages/AgentEditor.tsx | 90 ++++++++++++++++++++++++++++----------- src/styles.css | 47 ++++++++++++++++++++ 2 files changed, 111 insertions(+), 26 deletions(-) diff --git a/src/pages/AgentEditor.tsx b/src/pages/AgentEditor.tsx index cd4efee..adbfbc9 100644 --- a/src/pages/AgentEditor.tsx +++ b/src/pages/AgentEditor.tsx @@ -1,5 +1,5 @@ import { useEffect, useRef, useState } from 'react'; -import { Button, Form, Input, InputNumber, Modal, Upload, App as AntApp, List, Popconfirm, Tag, Switch, Select, Collapse, Checkbox } from 'antd'; +import { Button, Form, Input, InputNumber, Modal, Upload, App as AntApp, List, Popconfirm, Tag, Switch, Select, Collapse, Checkbox, Dropdown } from 'antd'; import type { UploadFile } from 'antd/es/upload/interface'; import { useNavigate, useParams } from 'react-router-dom'; import { Agent, AgentAPI, ImageAPI, KnowledgeStatus, SkillType, Team, TeamAPI, AiModel, ModelAPI } from '../api'; @@ -7,7 +7,7 @@ import { DEFAULT_RH_40X40_GRAY } from '../constants'; import SkillEditor from '../components/SkillEditor'; import McpPanel from '../components/McpPanel'; import ChatPreview from '../components/ChatPreview'; -import { ArrowLeftOutlined, SaveOutlined, FileTextOutlined, RocketOutlined, ToolOutlined, DatabaseOutlined, SettingOutlined, UploadOutlined } from '@ant-design/icons'; +import { ArrowLeftOutlined, SaveOutlined, FileTextOutlined, RocketOutlined, ToolOutlined, DatabaseOutlined, SettingOutlined, UploadOutlined, DownOutlined } from '@ant-design/icons'; const STATUS_TAG: Record = { pending: { color: 'default', text: '待处理' }, @@ -35,6 +35,67 @@ const parseModelSelections = (value?: string | string[]) => .map((item) => item.trim()) .filter(Boolean); +function ModelCheckboxDropdown({ + value = [], + onChange, + models, +}: { + value?: string[]; + onChange?: (value: string[]) => void; + models: AiModel[]; +}) { + const [open, setOpen] = useState(false); + const summary = value.length ? `${value.length} 个已选` : '选择模型'; + + return ( + ( +
e.stopPropagation()}> + onChange?.(checked.map((item) => String(item)))} + className="agent-model-checkbox-group" + > + {models.map((m) => { + const inputPrice = 2 * m.model_ratio; + const outputPrice = inputPrice * m.completion_ratio; + return ( + +
+
+ {m.model_name} + {m.model_name} +
+
+ 输入: ${inputPrice.toFixed(2)}/M + 输出: ${outputPrice.toFixed(2)}/M +
+
+
+ ); + })} +
+
+ )} + > + +
+ ); +} + export default function AgentEditor() { const { id } = useParams(); const isNew = !id; @@ -493,30 +554,7 @@ export default function AgentEditor() { Array.isArray(value) ? value.map((item) => String(item).trim()).filter(Boolean).join(', ') : '' } > - - {models.map((m) => { - const inputPrice = 2 * m.model_ratio; - const outputPrice = inputPrice * m.completion_ratio; - return ( - -
-
- {m.model_name} - {m.model_name} -
-
- 输入: ${inputPrice.toFixed(2)}/M - 输出: ${outputPrice.toFixed(2)}/M -
-
-
- ); - })} -
+