index.jsx 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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(`InformationList/InformationListEdit`);
  21. };
  22. const handleDelete = (e) => {
  23. deleteNote(e.noteId).then((res) => {
  24. message.success('删除成功');
  25. actionRef.current.reload();
  26. });
  27. };
  28. const actions = () => [
  29. <Button key="add" type="primary" icon={<PlusOutlined />} onClick={() => gotoDetail()}>
  30. 新增
  31. </Button>,
  32. ];
  33. const columns = [
  34. {
  35. title: '分类名',
  36. key: 'typeName',
  37. dataIndex: 'typeName',
  38. search: false,
  39. },
  40. {
  41. title: '资讯标题',
  42. dataIndex: 'title',
  43. key: 'title',
  44. search: false,
  45. },
  46. {
  47. title: '封面',
  48. key: 'thumb',
  49. dataIndex: 'thumb',
  50. search: false,
  51. render: (t) => <img src={t} alt="" width={110} />,
  52. },
  53. {
  54. title: (
  55. <>
  56. 创建时间
  57. <Tooltip placement="top">
  58. <QuestionCircleOutlined style={{ marginLeft: 4 }} />
  59. </Tooltip>
  60. </>
  61. ),
  62. // hideInTable: true,
  63. search: false,
  64. key: 'createdAt',
  65. dataIndex: 'createdAt',
  66. valueType: 'date',
  67. // render: (t) => formatterTime(t),
  68. sorter: (a, b) => a.createdAt - b.createdAt, //时间排序
  69. },
  70. {
  71. title: '状态',
  72. dataIndex: 'status',
  73. // initialValue: 'all',
  74. key: 'status',
  75. valueEnum: {
  76. 0: { text: '已发布', status: 'Success' },
  77. 1: { text: '未发布', status: 'Error' },
  78. },
  79. },
  80. {
  81. title: '操作',
  82. valueType: 'option',
  83. key: 'option',
  84. ellipsis: true,
  85. width: 200,
  86. render: (_, record) => [
  87. <Link key={2} to={`InformationList/InformationListEdit`}>
  88. 编辑
  89. </Link>,
  90. <Popconfirm
  91. key={3}
  92. title="您是否确认删除 ?"
  93. onConfirm={() => handleDelete(record)}
  94. okText="确定"
  95. cancelText="取消"
  96. >
  97. <a href="#">删除</a>
  98. </Popconfirm>,
  99. ],
  100. },
  101. ];
  102. return (
  103. <PageHeaderWrapper>
  104. <ProTable
  105. dataSource={dataSource}
  106. columns={columns}
  107. // request={getNoteList} 请求
  108. // rowKey="noteId"
  109. search={false}
  110. options={false}
  111. toolBarRender={actions}
  112. actionRef={actionRef}
  113. />
  114. </PageHeaderWrapper>
  115. );
  116. };