list.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. 'use client'
  2. import Pagination, { type Props as PaginationProps } from '@/app/components/base/pagination'
  3. import type { FC } from 'react'
  4. import { useState } from 'react'
  5. import Button from '@/app/components/base/button'
  6. import cn from '@/utils/classnames'
  7. import { delCorpus } from '@/service/common'
  8. import Confirm from '@/app/components/base/confirm'
  9. import DetailModal from './detail-modal'
  10. type PageListProps = {
  11. list: []
  12. pagination: PaginationProps
  13. onUpdate: () => void
  14. }
  15. const IntentPageList: FC<PageListProps> = ({
  16. list = [],
  17. pagination,
  18. onUpdate,
  19. }) => {
  20. const [showConfirmDelete, setShowConfirmDelete] = useState(false)
  21. const [row, setRow] = useState<any>({})
  22. const handleDel = async () => {
  23. try {
  24. await delCorpus({
  25. url: `/tags/${row.id}`,
  26. body: {},
  27. })
  28. setShowConfirmDelete(false)
  29. onUpdate()
  30. }
  31. catch (e) { }
  32. }
  33. const [detailModalVisible, setDetailModalVisible] = useState(false)
  34. const [transfer, setTransfer] = useState<any>({
  35. mode: 'add',
  36. row: {},
  37. })
  38. return (
  39. <>
  40. <div className='relative flex h-full w-full flex-col'>
  41. <div className='relative grow overflow-x-auto'>
  42. <table className={'mt-3 w-full min-w-[700px] max-w-full border-collapse border-0 text-sm'}>
  43. <thead className="h-8 border-b border-divider-subtle text-xs font-medium uppercase leading-8 text-text-tertiary">
  44. <tr>
  45. <td>意图类型</td>
  46. <td>意图名称</td>
  47. <td>语料数量</td>
  48. <td>关键词数量</td>
  49. <td>创建时间</td>
  50. <td className="w-[120px] text-center">操作</td>
  51. </tr>
  52. </thead>
  53. <tbody className="text-text-secondary">
  54. {list.map((item: any, index) => (
  55. <tr
  56. key={item.id}
  57. className={'h-8 border-b border-divider-subtle hover:bg-background-default-hover'}
  58. >
  59. <td>1</td>
  60. <td>2</td>
  61. <td>3</td>
  62. <td>4</td>
  63. <td>2025-02-02 22:44:33</td>
  64. <td className="flex justify-center gap-2">
  65. <Button variant='ghost-accent' size='small' className={cn('shrink-0')} onClick={() => {
  66. setTransfer({
  67. mode: 'edit',
  68. row: JSON.parse(JSON.stringify(item)),
  69. })
  70. setDetailModalVisible(true)
  71. }}>
  72. 编辑
  73. </Button>
  74. <Button variant='ghost' size='small' className={cn('shrink-0 text-red-600')} onClick={() => {
  75. setRow(item)
  76. setShowConfirmDelete(true)
  77. }}>
  78. 刪除
  79. </Button>
  80. </td>
  81. </tr>
  82. ))}
  83. </tbody>
  84. </table>
  85. </div>
  86. {/* Show Pagination only if the total is more than the limit */}
  87. {pagination.total && (
  88. <Pagination
  89. {...pagination}
  90. className='w-full shrink-0 px-0 pb-0'
  91. />
  92. )}
  93. </div>
  94. {showConfirmDelete && (
  95. <Confirm
  96. title="删除确认"
  97. content={`请确认是否删除${row.name}?`}
  98. isShow={showConfirmDelete}
  99. onConfirm={handleDel}
  100. onCancel={() => setShowConfirmDelete(false)}
  101. />
  102. )}
  103. {
  104. detailModalVisible && (
  105. <DetailModal
  106. transfer={transfer}
  107. onCancel={() => setDetailModalVisible(false)}
  108. onSend={() => {
  109. setDetailModalVisible(false)
  110. onUpdate()
  111. }}
  112. />
  113. )
  114. }
  115. </>
  116. )
  117. }
  118. export default IntentPageList