headerMerge.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import React, { useMemo } from 'react';
  2. import { Table, Avatar } from '@douyinfe/semi-ui';
  3. import { IconMore } from '@douyinfe/semi-icons';
  4. const DAY = 24 * 60 * 60 * 1000;
  5. const figmaIconUrl = 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png';
  6. const columns = [
  7. {
  8. title: '基本信息',
  9. fixed: 'left',
  10. children: [
  11. {
  12. title: '标题',
  13. dataIndex: 'name',
  14. width: 300,
  15. fixed: true,
  16. render: (text, record, index) => {
  17. return (
  18. <span>
  19. <Avatar size="small" shape="square" src={figmaIconUrl} style={{ marginRight: 12 }}></Avatar>
  20. {text}
  21. </span>
  22. );
  23. },
  24. filters: [
  25. {
  26. text: 'Semi Design 设计稿',
  27. value: 'Semi Design 设计稿',
  28. },
  29. {
  30. text: 'Semi Pro 设计稿',
  31. value: 'Semi Pro 设计稿',
  32. },
  33. ],
  34. onFilter: (value, record) => record.name.includes(value),
  35. },
  36. {
  37. title: '大小',
  38. dataIndex: 'size',
  39. width: 100,
  40. fixed: true,
  41. sorter: (a, b) => a.size - b.size > 0 ? 1 : -1,
  42. render: (text) => `${text} KB`
  43. },
  44. ]
  45. },
  46. {
  47. title: '其他信息',
  48. children: [
  49. {
  50. title: '所有者',
  51. dataIndex: 'owner',
  52. render: (text, record, index) => {
  53. return (
  54. <div>
  55. <Avatar size="small" color={record.avatarBg} style={{ marginRight: 4 }}>{typeof text === 'string' && text.slice(0, 1)}</Avatar>
  56. {text}
  57. </div>
  58. );
  59. }
  60. },
  61. {
  62. title: '更新日期',
  63. dataIndex: 'updateTime',
  64. sorter: (a, b) => a.updateTime - b.updateTime > 0 ? 1 : -1,
  65. render: (value) => {
  66. return dateFns.format(new Date(value), 'yyyy-MM-dd');
  67. }
  68. }
  69. ]
  70. },
  71. {
  72. title: '更多',
  73. fixed: 'right',
  74. width: 100,
  75. align: 'center',
  76. dataIndex: 'operate',
  77. render: () => {
  78. return <IconMore />;
  79. }
  80. },
  81. ];
  82. const getData = (total) => {
  83. const data = [];
  84. for (let i = 0; i < total; i++) {
  85. const isSemiDesign = i % 2 === 0;
  86. const randomNumber = (i * 1000) % 199;
  87. data.push({
  88. key: '' + i,
  89. name: isSemiDesign ? `Semi Design 设计稿${i}.fig` : `Semi Pro 设计稿${i}.fig`,
  90. owner: isSemiDesign ? '姜鹏志' : '郝宣',
  91. size: randomNumber,
  92. updateTime: new Date().valueOf() + randomNumber * DAY,
  93. avatarBg: isSemiDesign ? 'grey' : 'red'
  94. });
  95. }
  96. return data;
  97. };
  98. function Demo() {
  99. const data = useMemo(() => {
  100. const _data = getData(46);
  101. return _data;
  102. }, []);
  103. return (
  104. <Table
  105. rowSelection={{ fixed: true }}
  106. expandedRowRender={record => <article>{record.name}</article>}
  107. dataSource={data}
  108. scroll={{ y: 400 }}
  109. onChange={(...args) => console.log(...args)}
  110. columns={columns}
  111. />
  112. );
  113. }
  114. render(Demo);