'use client' import List from './list' import React, { useEffect, useState } from 'react' import Input from '@/app/components/base/input' import cn from '@/utils/classnames' import { RiAddLine, RiRefreshLine, RiSearchLine } from '@remixicon/react' import Button from '@/app/components/base/button' import useSWR from 'swr' import { fetchCorpus, fetchIntentName, fetchIntentType } from '@/service/common' import { SimpleSelect } from '@/app/components/base/select' import DetailModal from './detail-modal' const CorpusIndex = () => { const [page, setPage] = React.useState(0) const [limit, setLimit] = useState(10) const [question, setQuestion] = useState('') // the input value const [intentType, setIntentType] = useState('') // the input value const { data: dataOptionsIntentType }: any = useSWR( { url: '/xxx', params: { page: 1, limit: 1000, }, }, fetchIntentType, ) const optionsIntentType: any = dataOptionsIntentType?.data.map((v: any) => ({ name: v.name, value: v.id })) || [] const [intentName, setIntentName] = useState('') // the input value const { data: dataOptionsIntentName }: any = useSWR( { url: '/xxx', params: { page: 1, limit: 1000, intentType, }, }, fetchIntentName, ) const optionsIntentName: any = dataOptionsIntentName?.data.map((v: any) => ({ name: v.name, value: v.id })) || [] const [query, setQuery] = useState({}) const { data, mutate }: any = useSWR( { url: '/xxx', params: { page: page + 1, limit, ...query, }, }, fetchCorpus, ) const list: any = data?.data || [] const total = data?.total || 0 const handleSearch = (reset = false) => { if (reset) { setQuestion('') setIntentName('') setIntentType('') } const params: any = {} if (question) params.question = question if (intentType) params.intentType = intentType if (intentName) params.intentName = intentName setQuery(params) setPage(0) } useEffect(() => { mutate() }, [page, limit]) const [detailModalVisible, setDetailModalVisible] = useState(false) const [transfer, setTransfer] = useState({ mode: 'add', row: {}, }) return ( <>
标准问题 setQuestion(e.target.value)} onClear={() => setQuestion('')} />
意图名称
{ setIntentType(i.value) setIntentName('') }} items={optionsIntentType} allowSearch={false} placeholder="请选择意图类型" /> { setIntentName(i.value) }} items={optionsIntentName} allowSearch={false} placeholder="请选择意图名称" disabled={!intentType} />
{ detailModalVisible && ( setDetailModalVisible(false)} onSend={() => { setDetailModalVisible(false) mutate() }} /> ) } ) } export default CorpusIndex