index.jsx 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { deleteMonitor, getMonitorList, updataMonitor, addMonitor } from '@/services/api/monitor';
  2. import { queryTable } from '@/utils/request';
  3. import { PageContainer, ProTable } from '@ant-design/pro-components';
  4. import { history } from '@umijs/max';
  5. import { Button, message, Popconfirm } from 'antd';
  6. import { useRef, useState } from 'react';
  7. import EditForm from './edit'
  8. const List = (props) => {
  9. console.log(props, '===');
  10. const [visible, setVisible] = useState(false);
  11. const [current, setCurrent] = useState({});
  12. const [activeKey, setActiveKey] = useState('');
  13. const actionRef = useRef();
  14. const updata = (row) => {
  15. if (row.id) {
  16. updataMonitor(row.id, { status: row.status === '1' ? '2' : '1' }).then((res) => {
  17. message.success('修改成功');
  18. actionRef.current.reload();
  19. });
  20. }
  21. };
  22. const onSubmit = (values) => {
  23. if (!Object.prototype.hasOwnProperty.call(values, 'id')) {
  24. addMonitor(values).then((res) => {
  25. setCurrent(res);
  26. setVisible(false);
  27. message.success('操作成功');
  28. actionRef.current.reload();
  29. })
  30. } else {
  31. updataMonitor(values.id, values).then((res) => {
  32. setVisible(false);
  33. message.success('操作成功');
  34. actionRef.current.reload();
  35. });
  36. }
  37. }
  38. const handleDelete = (id) => {
  39. if (id) {
  40. deleteMonitor(id).then((res) => {
  41. message.success('删除成功');
  42. actionRef.current.reload();
  43. });
  44. }
  45. };
  46. const columns = [
  47. {
  48. title: 'id',
  49. dataIndex: 'id',
  50. },
  51. {
  52. title: '监控',
  53. dataIndex: 'title',
  54. },
  55. {
  56. title: '地址',
  57. dataIndex: 'url',
  58. },
  59. {
  60. title: '状态',
  61. dataIndex: 'status',
  62. valueEnum: {
  63. 1: {
  64. text: '上架',
  65. status: 'Processing',
  66. },
  67. 2: {
  68. text: '下架',
  69. status: 'Error',
  70. },
  71. },
  72. },
  73. {
  74. title: '操作',
  75. valueType: 'option',
  76. width: 200,
  77. render: (_, record) => [
  78. <Button
  79. key={1}
  80. style={{ padding: 0 }}
  81. type="link"
  82. onClick={() => {
  83. updata(record);
  84. }}
  85. >
  86. {record.status === '1' ? '下架' : '上架'}
  87. </Button>,
  88. <Button
  89. key={2}
  90. style={{ padding: 0 }}
  91. type="link"
  92. onClick={() => {
  93. setCurrent(record);
  94. setVisible(true);
  95. }}
  96. >
  97. 编辑
  98. </Button>,
  99. <Popconfirm
  100. key={3}
  101. title="您是否确认删除 ?"
  102. onConfirm={() => handleDelete(record.id)}
  103. okText="确定"
  104. cancelText="取消"
  105. >
  106. {/* manualPush */}
  107. <Button style={{ padding: 0 }} type="link">
  108. 删除
  109. </Button>
  110. </Popconfirm>,
  111. ],
  112. },
  113. ];
  114. return (
  115. <PageContainer>
  116. <EditForm
  117. visible={visible}
  118. dataSource={current}
  119. onCancel={() => setVisible(false)}
  120. onSubmit={onSubmit}
  121. />
  122. <ProTable
  123. // headerTitle={'中高风险地区库'}
  124. search={false}
  125. actionRef={actionRef}
  126. rowKey="id"
  127. toolBarRender={() => [
  128. <Button
  129. key="2"
  130. type="primary"
  131. onClick={() => { setCurrent({}); setVisible(true); }}
  132. >
  133. 新增
  134. </Button>,
  135. ]}
  136. // search={false}
  137. request={queryTable(getMonitorList)}
  138. columns={columns}
  139. />
  140. </PageContainer>
  141. );
  142. };
  143. export default List;