KnowledgeDrawer.tsx 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import * as React from 'react';
  2. import { Drawer, Form, Input, Select, Button, Space, Divider, message, Radio } from 'antd';
  3. import { Database, Scissors, Text, AlignLeft } from 'lucide-react';
  4. import './KnowledgeDrawer.scss';
  5. interface KnowledgeDrawerProps {
  6. open: boolean;
  7. onClose: () => void;
  8. form: any;
  9. onSubmit: (values: any) => void;
  10. editingData?: any;
  11. }
  12. const KnowledgeDrawer: React.FC<KnowledgeDrawerProps> = ({
  13. open,
  14. onClose,
  15. form,
  16. onSubmit,
  17. editingData,
  18. }) => {
  19. const [splittingType, setSplittingType] = React.useState('1');
  20. React.useEffect(() => {
  21. if (editingData && open) {
  22. form.setFieldsValue(editingData);
  23. setSplittingType(editingData.splittingType || '1');
  24. } else {
  25. form.resetFields();
  26. setSplittingType('1');
  27. }
  28. }, [editingData, open, form]);
  29. const handleSubmit = async () => {
  30. try {
  31. const values = await form.validateFields();
  32. onSubmit(values);
  33. } catch (error) {
  34. console.error('验证失败:', error);
  35. }
  36. };
  37. return (
  38. <Drawer
  39. title={editingData ? '编辑知识库' : '创建知识库'}
  40. placement="right"
  41. width={720}
  42. open={open}
  43. onClose={onClose}
  44. className='knowledge-drawer'
  45. destroyOnClose
  46. extra={
  47. <Space>
  48. <Button onClick={onClose}>取消</Button>
  49. <Button type="primary" onClick={handleSubmit}>
  50. {editingData ? '保存' : '创建'}
  51. </Button>
  52. </Space>
  53. }
  54. >
  55. <div className='drawer-form-container'>
  56. {/* 基本信息 */}
  57. <div className='icon-select-section'>
  58. <div className='section-icon'>
  59. <Database size={24} />
  60. </div>
  61. <div className='section-info'>
  62. <div className='section-title'>基本信息</div>
  63. <div className='section-desc'>填写知识库的基本信息</div>
  64. </div>
  65. </div>
  66. <Form form={form} layout='vertical' autoComplete="off">
  67. <Form.Item
  68. label='知识库名称'
  69. name='name'
  70. rules={[{ required: true, message: '请输入知识库名称' }]}
  71. extra='尽量概括知识库的主要内容'
  72. >
  73. <Input placeholder="请输入知识库名称" maxLength={50} showCount />
  74. </Form.Item>
  75. <Form.Item
  76. label='知识库描述'
  77. name='description'
  78. rules={[{ required: true, message: '请输入知识库描述' }]}
  79. extra='描述知识库的文件内容和用途'
  80. >
  81. <Input.TextArea
  82. showCount
  83. maxLength={500}
  84. placeholder="请输入知识库描述"
  85. rows={4}
  86. />
  87. </Form.Item>
  88. <Form.Item
  89. label='知识库分类'
  90. name='standardClassification'
  91. rules={[{ required: true, message: '请选择知识库分类' }]}
  92. extra='选择知识库的实际分类'
  93. >
  94. <Select placeholder='请选择分类'>
  95. <Select.Option value='0'>公文类</Select.Option>
  96. <Select.Option value='1'>法律类</Select.Option>
  97. <Select.Option value='2'>政策类</Select.Option>
  98. </Select>
  99. </Form.Item>
  100. </Form>
  101. <Divider className='section-divider'>切片设置</Divider>
  102. <div className='icon-select-section'>
  103. <div className='section-icon'>
  104. <Scissors size={24} />
  105. </div>
  106. <div className='section-info'>
  107. <div className='section-title'>切片设置</div>
  108. <div className='section-desc'>配置文档切片的规则和方式</div>
  109. </div>
  110. </div>
  111. <Form form={form} layout='vertical' autoComplete="off">
  112. <Form.Item
  113. label='切片方式'
  114. name='splittingType'
  115. rules={[{ required: true, message: '请选择切片方式' }]}
  116. extra='选择文档的切片方式'
  117. >
  118. <Radio.Group
  119. buttonStyle="solid"
  120. className='splitting-radio'
  121. onChange={(e) => setSplittingType(e.target.value)}
  122. >
  123. <Radio.Button value='1'>
  124. <Text size={16} style={{ marginRight: 4 }} />
  125. 按段落
  126. </Radio.Button>
  127. <Radio.Button value='2'>
  128. <AlignLeft size={16} style={{ marginRight: 4 }} />
  129. 按章节
  130. </Radio.Button>
  131. </Radio.Group>
  132. </Form.Item>
  133. {splittingType === '1' && (
  134. <Form.Item
  135. label='段落长度'
  136. name='paragraphLength'
  137. extra='每个段落的最大字符数'
  138. >
  139. <Select placeholder='请选择段落长度'>
  140. <Select.Option value='500'>500 字</Select.Option>
  141. <Select.Option value='1000'>1000 字</Select.Option>
  142. <Select.Option value='2000'>2000 字</Select.Option>
  143. </Select>
  144. </Form.Item>
  145. )}
  146. {splittingType === '2' && (
  147. <Form.Item
  148. label='章节识别'
  149. name='chapterRecognition'
  150. extra='自动识别文档的章节结构'
  151. >
  152. <Radio.Group>
  153. <Radio value='auto'>自动识别</Radio>
  154. <Radio value='manual'>手动指定</Radio>
  155. </Radio.Group>
  156. </Form.Item>
  157. )}
  158. </Form>
  159. </div>
  160. </Drawer>
  161. );
  162. };
  163. export default KnowledgeDrawer;