123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { getRegulationList, deleteRegulation } from '@/services/regulation';
  2. import { PageContainer, ProTable } from '@ant-design/pro-components';
  3. import { useRef, useState, useEffect } from 'react';
  4. import { useNavigate } from 'react-router-dom';
  5. import { queryTable } from '@/utils/request';
  6. import { Button, message, Popconfirm } from 'antd';
  7. const RegulationList = (props) => {
  8. const actionRef = useRef();
  9. const navigate = useNavigate();
  10. useEffect(() => {
  11. actionRef.current.reload();
  12. });
  13. const handleDelete = (id) => {
  14. if (id) {
  15. deleteRegulation(id).then((res) => {
  16. message.success('删除成功');
  17. actionRef.current.reload();
  18. });
  19. }
  20. };
  21. const columns = [
  22. {
  23. title: 'id',
  24. dataIndex: 'id',
  25. width: 200,
  26. search: false,
  27. },
  28. {
  29. title: '标题',
  30. dataIndex: 'title',
  31. width: 200,
  32. search: true,
  33. },
  34. {
  35. title: '内容',
  36. dataIndex: 'detail',
  37. width: 200,
  38. search: false,
  39. },
  40. {
  41. title: '发布人',
  42. dataIndex: 'create_person',
  43. width: 200,
  44. search: false,
  45. },
  46. {
  47. title: '发布时间',
  48. dataIndex: 'create_date',
  49. width: 200,
  50. search: false,
  51. },
  52. {
  53. title: '操作',
  54. valueType: 'option',
  55. width: 200,
  56. render: (_, record) => [
  57. <Button
  58. key={2}
  59. style={{ padding: 0 }}
  60. type="link"
  61. onClick={() => {
  62. console.log(record, ']]');
  63. navigate(`/cms/regulation/add?id=${record.id}`);
  64. }}
  65. >
  66. 编辑
  67. </Button>,
  68. <Popconfirm
  69. key={3}
  70. title="您是否确认删除 ?"
  71. onConfirm={() => handleDelete(record.id)}
  72. okText="确定"
  73. cancelText="取消"
  74. >
  75. {/* manualPush */}
  76. <Button style={{ padding: 0 }} type="link">
  77. 删除
  78. </Button>
  79. </Popconfirm>,
  80. ],
  81. },
  82. ];
  83. return (
  84. <PageContainer>
  85. <ProTable
  86. search={true}
  87. actionRef={actionRef}
  88. rowKey="id"
  89. toolBarRender={() => [
  90. <Button
  91. key="2"
  92. type="primary"
  93. onClick={() => {
  94. navigate('/cms/regulation/add');
  95. }}
  96. >
  97. 新增
  98. </Button>,
  99. ]}
  100. request={queryTable(getRegulationList)}
  101. columns={columns}
  102. />
  103. </PageContainer>
  104. );
  105. }
  106. export default RegulationList;