diff --git a/src/pages/knowledge/components/CreateGeneralForm.tsx b/src/pages/knowledge/components/CreateGeneralForm.tsx new file mode 100644 index 0000000..bf5e45f --- /dev/null +++ b/src/pages/knowledge/components/CreateGeneralForm.tsx @@ -0,0 +1,131 @@ +import React from 'react'; +import { useFormContext, Controller, type UseFormReturn } from 'react-hook-form'; +import { Box, Typography, TextField, Grid, Button } from '@mui/material'; +import { useTranslation } from 'react-i18next'; +import { EmbeddingModelItem } from '../configuration'; +import { PageRankItem } from '../configuration/common-items'; + +interface CreateGeneralFormProps { + form?: UseFormReturn; + onSubmit?: (data: any) => void; + isSubmitting?: boolean; + onCancel?: () => void; + submitButtonText?: string; + cancelButtonText?: string; +} + +function CreateGeneralForm({ + form: propForm, + onSubmit, + isSubmitting, + onCancel, + submitButtonText, + cancelButtonText, +}: CreateGeneralFormProps = {}) { + const { t } = useTranslation(); + + const defaultSubmitButtonText = submitButtonText || t('common.save'); + const defaultCancelButtonText = cancelButtonText || t('common.cancel'); + + // 优先使用props传递的form,否则使用FormProvider的context + let contextForm: UseFormReturn | null = null; + try { + contextForm = useFormContext(); + } catch (error) { + contextForm = null; + } + + const form = propForm || contextForm; + + if (!form) { + console.error('CreateGeneralForm: No form context found. Component must be used within a FormProvider or receive a form prop.'); + return ( + + + {t('form.configurationError')} + + + ); + } + + const { control } = form; + + return ( + + + {t('knowledge.basicInfo')} + + + + {/* 表单字段(去除 avatar / permission / TagsItem) */} + + + + ( + + )} + /> + + + + ( + + )} + /> + + + + + + + + + + + {/* 表单操作按钮 - 仅在有onSubmit回调时显示 */} + {onSubmit && ( + + {onCancel && ( + + )} + + + )} + + ); +} + +export default CreateGeneralForm; \ No newline at end of file diff --git a/src/pages/knowledge/components/CreateKnowledgeDialog.tsx b/src/pages/knowledge/components/CreateKnowledgeDialog.tsx index c971e2f..da1ee57 100644 --- a/src/pages/knowledge/components/CreateKnowledgeDialog.tsx +++ b/src/pages/knowledge/components/CreateKnowledgeDialog.tsx @@ -10,7 +10,7 @@ import { } from '@mui/material'; import { useTranslation } from 'react-i18next'; import { useForm, FormProvider } from 'react-hook-form'; -import GeneralForm from './GeneralForm'; +import CreateGeneralForm from './CreateGeneralForm'; import { RadioFormField } from '@/components/FormField'; import { ChunkMethodItem, PipelineSelectorItem } from '../configuration'; import { DocumentParserType, ParseType } from '@/constants/knowledge'; @@ -91,8 +91,8 @@ function CreateKnowledgeDialog({ open, onClose, onSuccess }: CreateKnowledgeDial {t('knowledgeList.createKnowledgeBase')} - {/* 基础信息表单(名称、描述、权限、头像、嵌入模型、Pagerank 等) */} - + {/* 基础信息表单(去除 avatar / permission / TagsItem,其余保持一致) */} +