import React, { useState, useCallback } from 'react'; import { Box, IconButton, Flex, Button, Modal, ModalOverlay, ModalContent, ModalHeader, ModalCloseButton, Input, Textarea } from '@chakra-ui/react'; import { useForm, useFieldArray } from 'react-hook-form'; import { postModelDataInput } from '@/api/model'; import { useToast } from '@/hooks/useToast'; import { DeleteIcon } from '@chakra-ui/icons'; import { customAlphabet } from 'nanoid'; const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 12); type FormData = { text: string; q: { val: string }[] }; const InputDataModal = ({ onClose, onSuccess, modelId }: { onClose: () => void; onSuccess: () => void; modelId: string; }) => { const [importing, setImporting] = useState(false); const { toast } = useToast(); const { register, handleSubmit, control } = useForm({ defaultValues: { text: '', q: [{ val: '' }] } }); const { fields: inputQ, append: appendQ, remove: removeQ } = useFieldArray({ control, name: 'q' }); const sureImportData = useCallback( async (e: FormData) => { setImporting(true); try { await postModelDataInput({ modelId: modelId, data: [ { text: e.text, q: e.q.map((item) => ({ id: nanoid(), text: item.val })) } ] }); toast({ title: '导入数据成功,需要一段时间训练', status: 'success' }); onClose(); onSuccess(); } catch (err) { console.log(err); } setImporting(false); }, [modelId, onClose, onSuccess, toast] ); return ( 手动导入 知识点: