'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, RiPriceTagLine, RiRefreshLine, RiSearchLine } from '@remixicon/react' import Button from '@/app/components/base/button' import useSWR from 'swr' import { fetchIntent, fetchIntentType } from '@/service/common' import { SimpleSelect } from '@/app/components/base/select' import DetailModal from './detail-modal' import TypeModal from './type-modal' const CorpusIndex = () => { const [page, setPage] = useState(0) const [limit, setLimit] = useState(10) const [intentName, setIntentName] = useState('') // the input value const [intentType, setIntentType] = useState('') // the input value const { data: dataOptionsIntentType, mutate: mutateOptionsIntentType }: any = useSWR( { url: '/intentions/types', params: { page: 1, limit: 1000, }, }, fetchIntentType, ) const optionsIntentType: any = dataOptionsIntentType?.data.map((v: any) => ({ name: v.name, value: v.id })) || [] const query = useRef({}) const [list, setList] = useState([]) const [total, setTotal] = useState(0) const handlePage = () => { const params: any = { page: page + 1, limit, } if (query.current.intentType) params.type_id = query.current.intentType if (query.current.intentName) params.name_search = query.current.intentName fetchIntent({ url: '/intentions', 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) { setIntentName('') setIntentType('') query.current = {} } else { query.current = { intentType, intentName, } } handlePage() setRefresh(false) } useEffect(() => { if (!refresh) handlePage() }, [page, limit]) const [detailModalVisible, setDetailModalVisible] = useState(false) const [transfer, setTransfer] = useState({ mode: 'add', row: {}, }) const [showIntentTypeModalVisible, setShowIntentTypeModalVisible] = useState(false) return ( <>
意图类型
{ setIntentType(i.value) }} items={optionsIntentType} allowSearch={false} placeholder="请选择意图类型" />
意图名称 setIntentName(e.target.value)} onClear={() => setIntentName('')} />
handleSearch(false)} pagination={{ total, limit, onLimitChange: setLimit, current: page, onChange: setPage, }} />
{ detailModalVisible && ( setDetailModalVisible(false)} onSend={() => { setDetailModalVisible(false) handleSearch() }} /> ) } { showIntentTypeModalVisible && ( { mutateOptionsIntentType() setShowIntentTypeModalVisible(false) }} /> ) } ) } export default CorpusIndex