From 14283385467676ef10bbec65ec1fe145d0d73ee6 Mon Sep 17 00:00:00 2001 From: HynoR <20227709+HynoR@users.noreply.github.com> Date: Wed, 1 Oct 2025 18:40:02 +0800 Subject: [PATCH] feat: Enhance SettingsChats edit interface --- web/src/pages/Setting/Chat/SettingsChats.jsx | 69 +++++++++++++++++--- 1 file changed, 61 insertions(+), 8 deletions(-) diff --git a/web/src/pages/Setting/Chat/SettingsChats.jsx b/web/src/pages/Setting/Chat/SettingsChats.jsx index 368a66f5b..01591c782 100644 --- a/web/src/pages/Setting/Chat/SettingsChats.jsx +++ b/web/src/pages/Setting/Chat/SettingsChats.jsx @@ -36,6 +36,7 @@ import { IconEdit, IconDelete, IconSearch, + IconSaveStroked, } from '@douyinfe/semi-icons'; import { compareObjects, @@ -55,7 +56,7 @@ export default function SettingsChats(props) { }); const refForm = useRef(); const [inputsRow, setInputsRow] = useState(inputs); - const [editMode, setEditMode] = useState('json'); + const [editMode, setEditMode] = useState('visual'); const [chatConfigs, setChatConfigs] = useState([]); const [modalVisible, setModalVisible] = useState(false); const [editingConfig, setEditingConfig] = useState(null); @@ -167,7 +168,9 @@ export default function SettingsChats(props) { } setInputs(currentInputs); setInputsRow(structuredClone(currentInputs)); - refForm.current.setValues(currentInputs); + if (refForm.current) { + refForm.current.setValues(currentInputs); + } // 同步到可视化配置 const configs = jsonToConfigs(currentInputs.Chats || '[]'); @@ -220,6 +223,18 @@ export default function SettingsChats(props) { modalFormRef.current .validate() .then((values) => { + // 检查名称是否重复 + const isDuplicate = chatConfigs.some( + (config) => + config.name === values.name && + (!isEdit || config.id !== editingConfig.id) + ); + + if (isDuplicate) { + showError(t('聊天应用名称已存在,请使用其他名称')); + return; + } + if (isEdit) { const newConfigs = chatConfigs.map((config) => config.id === editingConfig.id @@ -263,6 +278,28 @@ export default function SettingsChats(props) { config.name.toLowerCase().includes(searchText.toLowerCase()), ); + const highlightKeywords = (text) => { + if (!text) return text; + + const parts = text.split(/(\{address\}|\{key\})/g); + return parts.map((part, index) => { + if (part === '{address}') { + return ( + + {part} + + ); + } else if (part === '{key}') { + return ( + + {part} + + ); + } + return part; + }); + }; + const columns = [ { title: t('聊天应用名称'), @@ -275,7 +312,9 @@ export default function SettingsChats(props) { dataIndex: 'url', key: 'url', render: (text) => ( -