您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

csv-downloader.tsx 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import {
  5. useCSVDownloader,
  6. } from 'react-papaparse'
  7. import { useTranslation } from 'react-i18next'
  8. import { useContext } from 'use-context-selector'
  9. import { Download02 as DownloadIcon } from '@/app/components/base/icons/src/vender/solid/general'
  10. import I18n from '@/context/i18n'
  11. const CSV_TEMPLATE_QA_EN = [
  12. ['question', 'answer'],
  13. ['question1', 'answer1'],
  14. ['question2', 'answer2'],
  15. ]
  16. const CSV_TEMPLATE_QA_CN = [
  17. ['问题', '答案'],
  18. ['问题 1', '答案 1'],
  19. ['问题 2', '答案 2'],
  20. ]
  21. const CSVDownload: FC = () => {
  22. const { t } = useTranslation()
  23. const { locale } = useContext(I18n)
  24. const { CSVDownloader, Type } = useCSVDownloader()
  25. const getTemplate = () => {
  26. if (locale === 'en')
  27. return CSV_TEMPLATE_QA_EN
  28. return CSV_TEMPLATE_QA_CN
  29. }
  30. return (
  31. <div className='mt-6'>
  32. <div className='text-sm text-gray-900 font-medium'>{t('share.generation.csvStructureTitle')}</div>
  33. <div className='mt-2 max-h-[500px] overflow-auto'>
  34. <table className='table-fixed w-full border-separate border-spacing-0 border border-gray-200 rounded-lg text-xs'>
  35. <thead className='text-gray-500'>
  36. <tr>
  37. <td className='h-9 pl-3 pr-2 border-b border-gray-200'>{t('appAnnotation.batchModal.question')}</td>
  38. <td className='h-9 pl-3 pr-2 border-b border-gray-200'>{t('appAnnotation.batchModal.answer')}</td>
  39. </tr>
  40. </thead>
  41. <tbody className='text-gray-700'>
  42. <tr>
  43. <td className='h-9 pl-3 pr-2 border-b border-gray-100 text-[13px]'>{t('appAnnotation.batchModal.question')} 1</td>
  44. <td className='h-9 pl-3 pr-2 border-b border-gray-100 text-[13px]'>{t('appAnnotation.batchModal.answer')} 1</td>
  45. </tr>
  46. <tr>
  47. <td className='h-9 pl-3 pr-2 text-[13px]'>{t('appAnnotation.batchModal.question')} 2</td>
  48. <td className='h-9 pl-3 pr-2 text-[13px]'>{t('appAnnotation.batchModal.answer')} 2</td>
  49. </tr>
  50. </tbody>
  51. </table>
  52. </div>
  53. <CSVDownloader
  54. className="block mt-2 cursor-pointer"
  55. type={Type.Link}
  56. filename={'template'}
  57. bom={true}
  58. data={getTemplate()}
  59. >
  60. <div className='flex items-center h-[18px] space-x-1 text-[#155EEF] text-xs font-medium'>
  61. <DownloadIcon className='w-3 h-3 mr-1' />
  62. {t('appAnnotation.batchModal.template')}
  63. </div>
  64. </CSVDownloader>
  65. </div>
  66. )
  67. }
  68. export default React.memo(CSVDownload)