import * as React from 'react'; import { Modal, Spin, Form, Input, Select, message } from 'antd'; import { apis, CreateOrModifyKnowledgeLibApiParams } from '@/apis'; const FormItem = Form.Item; const { Option } = Select; const { TextArea } = Input; interface Props { id: string, open: boolean, onClickConfirm: (id: string, data: CreateOrModifyKnowledgeLibApiParams) => Promise, onClickCancel: () => void, }; const InfoModal: React.FC = (props: Props) => { const { id, open, onClickConfirm, onClickCancel } = props; const [form] = Form.useForm(); const [loading, setLoading] = React.useState(false); type EmbeddingList = { label: string, value: string, }[]; type AppTypeList = { label: string, value: string, children: { label: string, value: string, }[], }[]; const [embeddingList, setEmbeddingList] = React.useState([]); const [appVisibleList, setAppVisibleList] = React.useState([]); // 是否公开 const getTitle = () => { if (id) { return '修改知识库'; } else { return '创建知识库'; } }; // 获取向量化模型列表 const fetchEmbeddingList = async () => { try { const res = await apis.fetchEmbeddingList(); const list = res.data.list.map((item: any) => { return { label: item.name, value: item.id, } }); setEmbeddingList(list); } catch (error: any) { console.error(error); } } // 获取知识库详情 const fetchDetail = async () => { try { const res = await apis.fetchTakaiKnowledgeLibDetail(props.id); const { name, embeddingId, description,visible } = res.data; form.setFieldsValue({ name: name, embeddingId: embeddingId, description: description, visible: visible, // 是否公开 }); } catch (error: any) { message.error(error.msg); } }; // 获取是否公开类型 const fetchAppVisible = async (id: string) => { try { const res = await apis.fetchTakaiAppTypeList('app_visible'); console.log('res.data', res.data) const list = res.data.map((item: any) => { return { label: item.dictLabel, value: item.dictValue, } }); setAppVisibleList(list); if (!id) { form.setFieldsValue({ visible: list[0]?.value }); } } catch (error: any) { console.error(error); } } const init = async () => { setLoading(true); // await fetchEmbeddingList(); if (props.id) { await fetchDetail(); } await fetchAppVisible(props.id); setLoading(false); }; React.useEffect(() => { init(); }, []); // 点击确定 const handleClickConfirm = () => { form.validateFields().then(async (values) => { const data = { ...values }; await onClickConfirm(props.id, data); }).catch((error) => { console.error(error); }); }; return (
{ getTitle() === '创建知识库' && } { getTitle() === '修改知识库' && }