onRow.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import React from 'react';
  2. import { Table, Switch } from '../../../../index';
  3. class App extends React.Component {
  4. constructor(props) {
  5. super(props);
  6. this.state = {
  7. value: false,
  8. };
  9. this.columns = [
  10. {
  11. title: '需求标题',
  12. dataIndex: 'featureTitle',
  13. },
  14. {
  15. title: '文档',
  16. dataIndex: 'doc',
  17. },
  18. {
  19. title: '需求状态',
  20. dataIndex: 'featureStatus',
  21. },
  22. {
  23. title: '优先级',
  24. dataIndex: 'priority',
  25. },
  26. {
  27. title: 'PM',
  28. dataIndex: 'pm',
  29. },
  30. {
  31. title: '产品线',
  32. dataIndex: 'productLine',
  33. },
  34. {
  35. title: '前端',
  36. dataIndex: 'fe',
  37. },
  38. {
  39. title: '服务端',
  40. dataIndex: 'server',
  41. },
  42. {
  43. title: '创建时间',
  44. dataIndex: 'createTime',
  45. },
  46. {
  47. title: '完成时间',
  48. dataIndex: 'completeTime',
  49. },
  50. {
  51. title: '操作',
  52. dataIndex: 'operate',
  53. render: (text, record) => <Switch onChange={value => this.setState({ value })} />
  54. },
  55. ];
  56. this.data = Array.from(
  57. {
  58. length: 12,
  59. },
  60. (_, key) => {
  61. const rowRandom = Math.round(Math.random() * 1000);
  62. const prioritySet = ['P0', 'P1', 'P2'];
  63. const priority = prioritySet[Math.round(Math.random() * 2)];
  64. const featureStatusSet = ['待埋点', '开始', '待需详评', '测试', '已完成'];
  65. const featureStatus = featureStatusSet[Math.round(Math.random() * 4)];
  66. const doc = 'https://semi.design';
  67. const createTime = new Date().valueOf();
  68. return ({
  69. key,
  70. featureTitle: `需求-${rowRandom}`,
  71. doc,
  72. featureStatus,
  73. priority,
  74. pm: 'Li',
  75. productLine: 'Hotsoon',
  76. fe: '石嘉',
  77. server: 'ZhuYi',
  78. createTime,
  79. completeTime: createTime + rowRandom,
  80. operate: '',
  81. });
  82. }
  83. );
  84. this.onRow = (record, index) => {
  85. console.log('render row', index);
  86. return ({
  87. onClick: () => console.log('click row', record),
  88. });
  89. };
  90. this.scroll = { y: 300 };
  91. }
  92. render() {
  93. const { value } = this.state;
  94. return (
  95. <>
  96. <div>{`switch value: ${value}`}</div>
  97. <Table
  98. title={`数据条数:${this.data.length}`}
  99. rowSelection
  100. columns={this.columns}
  101. dataSource={this.data}
  102. onRow={this.onRow}
  103. scroll={this.scroll}
  104. />
  105. </>
  106. );
  107. }
  108. }
  109. export default App;