index.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import React from "react";
  2. import { Table, Avatar } from "@douyinfe/semi-ui";
  3. import { IconMore } from "@douyinfe/semi-icons";
  4. export default function App() {
  5. const columns = [
  6. {
  7. title: "标题",
  8. dataIndex: "name",
  9. width: 400,
  10. render: (text, record, index) => {
  11. return (
  12. <div>
  13. <Avatar
  14. size="small"
  15. shape="square"
  16. src={record.nameIconSrc}
  17. style={{ marginRight: 12 }}
  18. ></Avatar>
  19. {text}
  20. </div>
  21. );
  22. }
  23. },
  24. {
  25. title: "大小",
  26. dataIndex: "size"
  27. },
  28. {
  29. title: "所有者",
  30. dataIndex: "owner",
  31. render: (text, record, index) => {
  32. return (
  33. <div>
  34. <Avatar
  35. size="small"
  36. color={record.avatarBg}
  37. style={{ marginRight: 4 }}
  38. >
  39. {typeof text === "string" && text.slice(0, 1)}
  40. </Avatar>
  41. {text}
  42. </div>
  43. );
  44. }
  45. },
  46. {
  47. title: "更新日期",
  48. dataIndex: "updateTime"
  49. },
  50. {
  51. title: "",
  52. dataIndex: "operate",
  53. render: () => {
  54. return <IconMore />;
  55. }
  56. }
  57. ];
  58. const data = [
  59. {
  60. key: "1",
  61. name: "Semi Design 设计稿.fig",
  62. nameIconSrc:
  63. "https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png",
  64. size: "2M",
  65. owner: "姜鹏志",
  66. updateTime: "2020-02-02 05:13",
  67. avatarBg: "grey"
  68. },
  69. {
  70. key: "2",
  71. name: "Semi Design 分享演示文稿",
  72. nameIconSrc:
  73. "https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png",
  74. size: "2M",
  75. owner: "郝宣",
  76. updateTime: "2020-01-17 05:31",
  77. avatarBg: "red"
  78. },
  79. {
  80. key: "3",
  81. name: "设计文档",
  82. nameIconSrc:
  83. "https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png",
  84. size: "34KB",
  85. owner: "Zoey Edwards",
  86. updateTime: "2020-01-26 11:01",
  87. avatarBg: "light-blue"
  88. },
  89. {
  90. key: "4",
  91. name: "Semi D2C 设计稿.fig",
  92. nameIconSrc:
  93. "https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png",
  94. size: "2M",
  95. owner: "姜鹏志",
  96. updateTime: "2020-02-02 05:13",
  97. avatarBg: "grey"
  98. },
  99. {
  100. key: "5",
  101. name: "Semi D2C 分享演示文稿",
  102. nameIconSrc:
  103. "https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png",
  104. size: "2M",
  105. owner: "郝宣",
  106. updateTime: "2020-01-17 05:31",
  107. avatarBg: "red"
  108. },
  109. {
  110. key: "6",
  111. name: "Semi D2C 设计文档",
  112. nameIconSrc:
  113. "https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png",
  114. size: "34KB",
  115. owner: "Zoey Edwards",
  116. updateTime: "2020-01-26 11:01",
  117. avatarBg: "light-blue"
  118. }
  119. ];
  120. const handleRow = (record, index) => {
  121. // 给偶数行设置斑马纹
  122. if (index % 2 === 0) {
  123. return {
  124. style: {
  125. background: "red"
  126. }
  127. };
  128. } else {
  129. return {};
  130. }
  131. };
  132. const rowSelection = {
  133. fixed: true
  134. // onCell: (record, index) => {
  135. // if (index % 2 === 0) {
  136. // return {
  137. // style: {
  138. // background: "red"
  139. // }
  140. // };
  141. // } else {
  142. // return {};
  143. // }
  144. // }
  145. };
  146. return (
  147. <Table
  148. rowSelection={rowSelection}
  149. columns={columns}
  150. dataSource={data}
  151. onRow={handleRow}
  152. pagination={false}
  153. />
  154. );
  155. }