123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { history, Link } from 'umi';
  2. import { useRef } from 'react';
  3. import { Button, Modal, message, Popconfirm, Tooltip } from 'antd';
  4. import { PlusOutlined, QuestionCircleOutlined } from '@ant-design/icons';
  5. import { PageHeaderWrapper } from '@ant-design/pro-layout';
  6. import ProTable, { TableDropdown } from '@ant-design/pro-table';
  7. export default (props) => {
  8. const dataSource = [
  9. {
  10. id: 9,
  11. key: '1',
  12. name: '胡彦斌',
  13. age: 32,
  14. zz: '西湖区湖底公园1号',
  15. },
  16. ];
  17. // 测试内容👆-------------------------
  18. const actionRef = useRef();
  19. const gotoDetail = (id) => {
  20. history.push(`InformationClassification/InformationClassificationEdit`);
  21. };
  22. const handleDelete = (e) => {
  23. deleteNote(e.noteId).then((res) => {
  24. message.success('删除成功');
  25. actionRef.current.reload();
  26. });
  27. };
  28. const handleOK = (record, data) => {
  29. const titleCourse = record.status
  30. ? '您确定要禁用该用户吗? 禁用后该用户不能在后台登陆!'
  31. : '您确定要启用该用户吗? 启用后该用户将允许在后台登陆!';
  32. Modal.confirm({
  33. title: titleCourse,
  34. okText: '确认',
  35. cancelText: '取消',
  36. onOk() {
  37. publishNote(record.noteId, record.status ? 'off' : 'on').then((res) => {
  38. message.success('操作成功');
  39. actionRef.current.reload();
  40. });
  41. },
  42. });
  43. };
  44. const actions = () => [
  45. <Button key="add" type="primary" icon={<PlusOutlined />} onClick={() => gotoDetail()}>
  46. 新增
  47. </Button>,
  48. ];
  49. const columns = [
  50. {
  51. title: '分类名',
  52. dataIndex: 'name',
  53. key: 'name',
  54. search: false,
  55. },
  56. {
  57. title: (
  58. <>
  59. 创建时间
  60. <Tooltip placement="top">
  61. <QuestionCircleOutlined style={{ marginLeft: 4 }} />
  62. </Tooltip>
  63. </>
  64. ),
  65. // hideInTable: true,
  66. search: false,
  67. key: 'createdAt',
  68. dataIndex: 'createdAt',
  69. valueType: 'date',
  70. // render: (t) => formatterTime(t),
  71. sorter: (a, b) => a.createdAt - b.createdAt, //时间排序
  72. },
  73. {
  74. title: '操作',
  75. valueType: 'option',
  76. key: 'option',
  77. ellipsis: true,
  78. width: 200,
  79. render: (_, record) => [
  80. <Link key={2} to={`InformationClassification/InformationClassificationEdit`}>
  81. 编辑
  82. </Link>,
  83. <Popconfirm
  84. key={3}
  85. title="您是否确认删除 ?"
  86. onConfirm={() => handleDelete(record)}
  87. okText="确定"
  88. cancelText="取消"
  89. >
  90. <a href="#">删除</a>
  91. </Popconfirm>,
  92. ],
  93. },
  94. ];
  95. return (
  96. <PageHeaderWrapper>
  97. <ProTable
  98. dataSource={dataSource}
  99. columns={columns}
  100. // request={getNoteList} 请求
  101. // rowKey="noteId"
  102. search={false}
  103. options={false}
  104. toolBarRender={actions}
  105. actionRef={actionRef}
  106. />
  107. </PageHeaderWrapper>
  108. );
  109. };