index.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import React from 'react';
  2. import { Table, Avatar } from '@douyinfe/semi-ui';
  3. import * as dateFns from 'date-fns';
  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. export default function App() {
  7. const getData = () => {
  8. const data = [];
  9. for (let i = 0; i < 46; i++) {
  10. const isSemiDesign = i % 2 === 0;
  11. const randomNumber = ((i * 1000) % 19) + 100;
  12. data.push({
  13. key: '' + i,
  14. name: isSemiDesign ? `Semi Design 设计稿${i}.fig` : `Semi D2C 设计稿${i}.fig`,
  15. owner: isSemiDesign ? '姜鹏志' : '郝宣',
  16. size: randomNumber,
  17. updateTime: new Date().valueOf() + randomNumber * DAY,
  18. avatarBg: isSemiDesign ? 'grey' : 'red',
  19. });
  20. }
  21. return data;
  22. };
  23. const data = getData();
  24. const columns = [
  25. {
  26. title: '标题',
  27. dataIndex: 'name',
  28. width: 400,
  29. render: (text, record, index) => {
  30. return (
  31. <div>
  32. <Avatar size="small" shape="square" src={figmaIconUrl} style={{ marginRight: 12 }}></Avatar>
  33. {text}
  34. </div>
  35. );
  36. },
  37. filters: [
  38. {
  39. text: 'Semi Design 设计稿',
  40. value: 'Semi Design 设计稿',
  41. },
  42. {
  43. text: 'Semi D2C 设计稿',
  44. value: 'Semi D2C 设计稿',
  45. },
  46. ],
  47. onFilter: (value, record) => record.name.includes(value),
  48. },
  49. {
  50. title: '大小',
  51. dataIndex: 'size',
  52. sorter: (a, b) => (a.size - b.size > 0 ? 1 : -1),
  53. render: text => `${text} KB`,
  54. },
  55. {
  56. title: '所有者',
  57. dataIndex: 'owner',
  58. render: (text, record, index) => {
  59. return (
  60. <div>
  61. <Avatar size="small" color={record.avatarBg} style={{ marginRight: 4 }}>
  62. {typeof text === 'string' && text.slice(0, 1)}
  63. </Avatar>
  64. {text}
  65. </div>
  66. );
  67. },
  68. },
  69. {
  70. title: '更新日期',
  71. dataIndex: 'updateTime',
  72. sorter: (a, b) => (a.updateTime - b.updateTime > 0 ? 1 : -1),
  73. render: value => {
  74. return dateFns.format(new Date(value), 'yyyy-MM-dd');
  75. },
  76. },
  77. ];
  78. const rowKey = record =>
  79. `${record.owner && record.owner.toLowerCase()}-${record.name && record.name.toLowerCase()}`;
  80. return (
  81. <div style={{ padding: '20px 0px' }}>
  82. <Table
  83. dataSource={data}
  84. rowKey={rowKey}
  85. groupBy={'size'}
  86. columns={columns}
  87. renderGroupSection={groupKey => <strong>根据文件大小分组 {groupKey} KB</strong>}
  88. onGroupedRow={(group, index) => {
  89. return {
  90. className: 'test-group',
  91. onClick: e => {
  92. console.log(`Grouped row clicked: `, group, index);
  93. },
  94. };
  95. }}
  96. clickGroupedRowToExpand // if you want to click the entire row to expand
  97. scroll={{ y: 480 }}
  98. />
  99. </div>
  100. );
  101. }
  102. App.parameters = {
  103. chromatic: {
  104. disableSnapshot: true,
  105. },
  106. };