'use client' import List from './list' import React, { useEffect, useRef, 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 { fetchCorpus, fetchIntent } from '@/service/common' import DetailModal from './detail-modal' import { Cascader as AntdCascader } from 'antd' const CorpusIndex = () => { const [intentCascader, setIntentCascader] = useState([]) useEffect(() => { fetchIntent({ url: '/intentions', params: { page: 1, limit: 99999, }, }).then((res: any) => { const map = new Map() res.data.forEach((v: any) => { if (map.has(v.type_id)) { const parent = map.get(v.type_id) parent.children.push(v) map.set(v.type_id, parent) } else { map.set(v.type_id, { id: v.type_id, name: v.type_name, children: [v], }) } }) setIntentCascader(Array.from(map.values())) }) }, []) const [page, setPage] = useState(0) const [limit, setLimit] = useState(10) const [question, setQuestion] = useState('') const [intentName, setIntentName] = useState('') const [intentValue, setIntentValue] = useState([]) const query = useRef({}) const [list, setList] = useState([]) const [total, setTotal] = useState(0) const handlePage = () => { const params: any = { page: page + 1, limit, } if (query.current.question) params.question_search = query.current.question if (query.current.intentName) params.intention_id = query.current.intentName fetchCorpus({ url: '/intentions/corpus', params, }).then((res: any) => { setList(res.data) setTotal(res.total) }) } const [refresh, setRefresh] = useState(false) const handleSearch = (reset = false) => { setRefresh(true) setPage(0) if (reset) { setQuestion('') setIntentName('') setIntentValue([]) query.current = {} } else { query.current = { question, intentName, } } handlePage() setRefresh(false) } useEffect(() => { if (!refresh) handlePage() }, [page, limit]) const [detailModalVisible, setDetailModalVisible] = useState(false) const [transfer, setTransfer] = useState({ mode: 'add', row: {}, }) return ( <>
标准问题 setQuestion(e.target.value)} onClear={() => setQuestion('')} />
意图名称
{ setIntentValue(val) setIntentName(val?.[val.length - 1] || '') }} placeholder="请选择" fieldNames={{ label: 'name', value: 'id' }} showSearch={true} />
handleSearch(false)} pagination={{ total, limit, onLimitChange: setLimit, current: page, onChange: setPage, }} />
{ detailModalVisible && ( { setDetailModalVisible(false) handleSearch() }} onSend={() => { setDetailModalVisible(false) handleSearch() }} onRefresh={(id: string) => { setTransfer({ mode: 'edit', row: { id }, }) }} /> ) } ) } export default CorpusIndex