123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- 'use client'
- import Pagination, { type Props as PaginationProps } from '@/app/components/base/pagination'
- import type { FC } from 'react'
- import { useState } from 'react'
- import Button from '@/app/components/base/button'
- import cn from '@/utils/classnames'
- import { delIntent } from '@/service/common'
- import Confirm from '@/app/components/base/confirm'
- import DetailModal from './detail-modal'
- import useTimestamp from '@/hooks/use-timestamp'
- import { useTranslation } from 'react-i18next'
- type PageListProps = {
- list: []
- pagination: PaginationProps
- onUpdate: () => void
- }
- const IntentPageList: FC<PageListProps> = ({
- list = [],
- pagination,
- onUpdate,
- }) => {
- const { t } = useTranslation()
- const { formatTime } = useTimestamp()
- const [showConfirmDelete, setShowConfirmDelete] = useState(false)
- const [row, setRow] = useState<any>({})
- const handleDel = async () => {
- try {
- await delIntent({
- url: `/intentions/${row.id}`,
- body: {},
- })
- setShowConfirmDelete(false)
- onUpdate()
- }
- catch (e) { }
- }
- const [detailModalVisible, setDetailModalVisible] = useState(false)
- const [transfer, setTransfer] = useState<any>({
- mode: 'add',
- row: {},
- })
- return (
- <>
- <div className='relative flex h-full w-full flex-col'>
- <div className='relative grow overflow-x-auto'>
- <table className={'mt-3 w-full min-w-[700px] max-w-full border-collapse border-0 text-sm'}>
- <thead className="h-8 border-b border-divider-subtle text-xs font-medium uppercase leading-8 text-text-tertiary">
- <tr>
- <td>意图类型</td>
- <td>意图名称</td>
- <td>语料数量</td>
- <td>关键词数量</td>
- <td>创建时间</td>
- <td className="w-[120px] text-center">操作</td>
- </tr>
- </thead>
- <tbody className="text-text-secondary">
- {list.map((item: any, index) => (
- <tr
- key={item.id}
- className={'h-8 border-b border-divider-subtle hover:bg-background-default-hover'}
- >
- <td>{item.type_name}</td>
- <td>{item.name}</td>
- <td>{item.corpus_count}</td>
- <td>{item.keywords_count}</td>
- <td>{formatTime(item.created_at, t('datasetHitTesting.dateTimeFormat') as string)}</td>
- <td className="flex justify-center gap-2">
- <Button variant='ghost-accent' size='small' className={cn('shrink-0')} onClick={() => {
- setTransfer({
- mode: 'edit',
- row: JSON.parse(JSON.stringify(item)),
- })
- setDetailModalVisible(true)
- }}>
- 编辑
- </Button>
- <Button variant='ghost' size='small' className={cn('shrink-0 text-red-600')} onClick={() => {
- setRow(item)
- setShowConfirmDelete(true)
- }}>
- 刪除
- </Button>
- </td>
- </tr>
- ))}
- </tbody>
- </table>
- </div>
- {/* Show Pagination only if the total is more than the limit */}
- {pagination.total && (
- <Pagination
- {...pagination}
- className='w-full shrink-0 px-0 pb-0'
- />
- )}
- </div>
- {showConfirmDelete && (
- <Confirm
- title="删除确认"
- content={`请确认是否删除${row.name}?`}
- isShow={showConfirmDelete}
- onConfirm={handleDel}
- onCancel={() => setShowConfirmDelete(false)}
- />
- )}
- {
- detailModalVisible && (
- <DetailModal
- transfer={transfer}
- onCancel={() => {
- setDetailModalVisible(false)
- onUpdate()
- }}
- onSend={() => {
- setDetailModalVisible(false)
- onUpdate()
- }}
- />
- )
- }
- </>
- )
- }
- export default IntentPageList
|