EditAction 编辑列

image.png

  1. import { Divider, Popconfirm, message } from 'antd';
  2. import { Link } from 'react-rotuer-dom';
  3. function ActionGroup({value, onDelete, onUpdate}) {
  4. const { id } = value;
  5. return (
  6. <>
  7. <a href={null} onClick={() => onUpdate(id)} rel="noopener noreferrer">
  8. 编辑
  9. </a>
  10. <Divider type="vertical" />
  11. <Popconfirm
  12. title="删除后数据将无法恢复,请谨慎操作!"
  13. overlayStyle={{ width: 220 }}
  14. onConfirm={() => onDelete(id)}
  15. >
  16. <a href={null}>删除</a>
  17. </Popconfirm>
  18. <Divider type="vertical" />
  19. <Link to={`/detail/${id}`}>详情</Link>
  20. </>
  21. );
  22. }
  23. export default ActionGroup

MoreAction 下拉列

下拉参考 ProTable
https://procomponents.ant.design/components/table?current=1&pageSize=5
image.png
image.png

MoreAction.jsx

  1. import { memo } from 'react';
  2. import { array } from 'prop-types';
  3. import { Menu, Dropdown } from 'antd';
  4. import { EllipsisOutlined } from '@ant-design/icons';
  5. import equal from 'fast-deep-equal';
  6. const { Item } = Menu;
  7. MoreAction.propTypes = {
  8. data: array.isRequired,
  9. };
  10. function MoreAction({ data }) {
  11. const listData = data.filter(it => !it.more);
  12. const menuData = data.filter(it => it.more);
  13. const menu = (
  14. <Menu>
  15. {menuData.map((it, i) => <Item key={i}>{it}</Item>)}
  16. </Menu>
  17. );
  18. return (
  19. <>
  20. {listData}
  21. <Dropdown overlay={menu} className="ml8">
  22. <a rel="noopener noreferrer">
  23. <EllipsisOutlined />
  24. </a>
  25. </Dropdown>
  26. </>
  27. );
  28. }
  29. function propsEqual({ data }, props) {
  30. return equal(data, props.data);
  31. }
  32. export default memo(MoreAction, propsEqual);

columns

  1. const columns = [
  2. {
  3. title: '应用名称',
  4. dataIndex: 'name',
  5. },
  6. {
  7. title: '容器数量',
  8. dataIndex: 'total',
  9. align: 'right',
  10. sorter: (a, b) => a.total - b.total,
  11. },
  12. {
  13. title: '操作',
  14. key: 'option',
  15. width: 120,
  16. valueType: 'option',
  17. render: renderAction,
  18. },
  19. ];
  20. function renderAction(_, {id, name}) {
  21. const actionData = [
  22. <Link key="link" to={`/edit/${id}`}>编辑</Link>,
  23. <a key="warn">报警</a>,
  24. <Popconfirm
  25. key="copy"
  26. title={`确定要拷贝 ${name}`}
  27. onConfirm={() => onCopy(id)}
  28. >
  29. <a rel="noopener noreferrer">拷贝</a>
  30. </Popconfirm>,
  31. <Popconfirm
  32. key="delete"
  33. title={`确定要删除 ${name}`}
  34. onConfirm={() => onDelete(id)}
  35. >
  36. <a rel="noopener noreferrer">删除</a>
  37. </Popconfirm>,
  38. ];
  39. return <MoreAction dataSource={actionData} />
  40. }
  41. function onDelete(id) {}
  42. function onCopy(id) {}