DesignPic_20250812160702.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import React, { useState } from 'react'
  2. import { Button, Table, Input } from '@alifd/next';
  3. export default function DesignPic() {
  4. // 添加状态管理表格数据
  5. const [tableData, setTableData] = useState(() => {
  6. const result = [];
  7. for (let i = 0; i < 5; i++) {
  8. result.push({
  9. title: { name: `Quotation for 1PCS Nano ${3 + i}.0 controller compatible` },
  10. id: 100306660940 + i,
  11. time: 2e3 + i,
  12. // 添加名称和标签字段
  13. picName: '',
  14. picLabel: ''
  15. });
  16. }
  17. return result;
  18. });
  19. const pic_render = (value: any, index: number, record: any) => {
  20. return (
  21. <img className='size-20' src={record.url} alt={record.title} />
  22. );
  23. }
  24. // 修改图片名称渲染函数
  25. const name_render = (value: any, index: number, record: any) => {
  26. return <>
  27. <Input.TextArea
  28. value={record.picName}
  29. onChange={(value) => handleNameChange(value, index)}
  30. composition
  31. placeholder={'请输入图片名称'}
  32. />
  33. </>
  34. };
  35. // 修改图片标签渲染函数
  36. const label_render = (value: any, index: number, record: any) => {
  37. return <>
  38. <Input.TextArea
  39. value={record.picLabel}
  40. onChange={(value) => handleLabelChange(value, index)}
  41. composition
  42. placeholder={'请输入图片标签'}
  43. />
  44. </>
  45. };
  46. // 添加名称变化处理函数
  47. const handleNameChange = (value: string, index: number) => {
  48. const newData = [...tableData];
  49. newData[index].picName = value;
  50. setTableData(newData);
  51. };
  52. // 添加标签变化处理函数
  53. const handleLabelChange = (value: string, index: number) => {
  54. const newData = [...tableData];
  55. newData[index].picLabel = value;
  56. setTableData(newData);
  57. };
  58. const option_render = (value: any, index: number, record: any) => {
  59. return (
  60. <a className='text-red-600'>
  61. 删除
  62. </a>
  63. );
  64. };
  65. return (
  66. <div className='w-3xl h-fit'>
  67. <Button>按钮</Button>
  68. <Table dataSource={tableData}>
  69. <Table.Column title="图片" cell={pic_render} />
  70. <Table.Column title="图片名称" cell={name_render} />
  71. <Table.Column title="图片标签" cell={label_render} />
  72. <Table.Column title="操作" cell={option_render} />
  73. </Table>
  74. </div>
  75. )
  76. }