From 787152468c154b2ca8d158d1201fe343272dc22c Mon Sep 17 00:00:00 2001 From: sd0ric4 <1286518974@qq.com> Date: Thu, 27 Mar 2025 14:42:09 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8F=90=E5=8F=96=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0=E6=A1=86=E5=92=8C=E8=A1=A8=E5=8D=95=E9=A1=B9=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E7=BB=84=E4=BB=B6=EF=BC=8C=E7=AE=80=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/chat/components/AIResponseBox.tsx | 1 - .../chat/components/Form/FormComponents.tsx | 302 ++++++++++-------- 2 files changed, 165 insertions(+), 138 deletions(-) diff --git a/projects/app/src/components/core/chat/components/AIResponseBox.tsx b/projects/app/src/components/core/chat/components/AIResponseBox.tsx index 98f2dbcda..aa04a7288 100644 --- a/projects/app/src/components/core/chat/components/AIResponseBox.tsx +++ b/projects/app/src/components/core/chat/components/AIResponseBox.tsx @@ -291,7 +291,6 @@ const getResponseRenderer = ( return null; }; -// AI响应框主组件 const AIResponseBox = React.memo(function AIResponseBox({ value, isLastResponseValue, diff --git a/projects/app/src/components/core/chat/components/Form/FormComponents.tsx b/projects/app/src/components/core/chat/components/Form/FormComponents.tsx index 0a328408d..bafec0562 100644 --- a/projects/app/src/components/core/chat/components/Form/FormComponents.tsx +++ b/projects/app/src/components/core/chat/components/Form/FormComponents.tsx @@ -27,6 +27,41 @@ export type SelectOptionsComponentPropsType = { variant?: string; }; +const DescriptionBox = React.memo(function DescriptionBox({ + description +}: { + description?: string; +}) { + if (!description) return null; + + return ( + + + + ); +}); + +const inputBaseStyle = { + bg: 'white', + borderWidth: '1px', + borderColor: 'gray.300', + _hover: { borderColor: 'gray.400' }, + _focus: { + borderColor: 'primary.500', + boxShadow: '0 0 0 1px var(--chakra-colors-primary-500)' + }, + borderRadius: 'md' +}; + export const SelectOptionsComponent = React.memo(function SelectOptionsComponent({ options = [], description, @@ -37,20 +72,7 @@ export const SelectOptionsComponent = React.memo(function SelectOptionsComponent }: SelectOptionsComponentPropsType) { return ( - {description && ( - - - - )} + {options.map((option: SelectOptionType) => { const selected = option.value === selectedValue; @@ -118,12 +140,133 @@ export type FormInputComponentProps = { onSubmit?: (data: Record) => void; isDisabled?: boolean; defaultValues?: Record; - submitButtonText?: 'common:Submit' | string; // 使用联合类型指定特定的i18n键名 + submitButtonText?: 'common:Submit' | string; showSubmitButton?: boolean; submitButtonIcon?: IconNameType; isCompact?: boolean; }; +// 表单项标签组件 +const FormItemLabel = React.memo(function FormItemLabel({ + label, + required, + description +}: { + label: string; + required?: boolean; + description?: string; +}) { + return ( + + + {label} + + {description && } + + ); +}); + +// 渲染不同类型的表单输入项 +const renderFormInput = ( + input: FormItemType, + register: any, + control: any, + setValue: any, + isDisabled: boolean +) => { + const { type, label, required, maxLength, min, max, defaultValue, list } = input; + + switch (type) { + case FlowNodeInputTypeEnum.input: + return ( + + ); + + case FlowNodeInputTypeEnum.textarea: + return ( +