123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import React from "react";
  2. import { useNavigate } from "react-router-dom";
  3. import { queryTable } from "@/utils/request";
  4. import { ProTable } from "@ant-design/pro-components";
  5. import { Button, message, Popconfirm } from "antd";
  6. import { getUserList, updateUserStatus,deleteUser } from "@/services/user";
  7. const queryUserList = queryTable(getUserList);
  8. export default (props) => {
  9. const actionRef = React.useRef();
  10. const navigate = useNavigate();
  11. const updateStatus = (user) => {
  12. const status = user.status === 1 ? 0 : 1;
  13. const hide = message.loading("请稍候...", 0);
  14. updateUserStatus(user.id, status)
  15. .then((res) => {
  16. hide();
  17. actionRef.current.reload();
  18. })
  19. .catch(() => {
  20. hide();
  21. });
  22. };
  23. const handleDelete = (id) => {
  24. if (id) {
  25. deleteUser(id).then((res) => {
  26. actionRef.current.reload();
  27. });
  28. }
  29. };
  30. const columns = [
  31. {
  32. title: "id",
  33. dataIndex: "id",
  34. search: false,
  35. },
  36. {
  37. title: "姓名",
  38. dataIndex: "name",
  39. },
  40. {
  41. title: "部门",
  42. dataIndex: "dept",
  43. },
  44. {
  45. title: "手机号",
  46. dataIndex: "phone",
  47. },
  48. {
  49. title: "账号",
  50. dataIndex: "loginName",
  51. search: false,
  52. },
  53. {
  54. title: "状态",
  55. dataIndex: "status",
  56. search: false,
  57. valueEnum: {
  58. 1: {
  59. text: "正常",
  60. status: "Processing",
  61. },
  62. 0: {
  63. text: "禁用",
  64. status: "Error",
  65. },
  66. },
  67. },
  68. {
  69. title: "操作",
  70. valueType: "option",
  71. width: 200,
  72. render: (_, record) => [
  73. <Button
  74. key={1}
  75. style={{ padding: 0 }}
  76. type="link"
  77. onClick={() => {
  78. updateStatus(record);
  79. }}
  80. >
  81. {record.status === 1 ? "禁用" : "启用"}
  82. </Button>,
  83. <Button
  84. key={2}
  85. style={{ padding: 0 }}
  86. type="link"
  87. onClick={() => {
  88. console.log(record, "]]");
  89. navigate(`/system/user/edit?id=${record.id}`);
  90. }}
  91. >
  92. 编辑
  93. </Button>,
  94. <Popconfirm
  95. key={3}
  96. title="您是否确认删除 ?"
  97. onConfirm={() => handleDelete(record.id)}
  98. okText="确定"
  99. cancelText="取消"
  100. >
  101. {/* manualPush */}
  102. <Button style={{ padding: 0 }} type="link">
  103. 删除
  104. </Button>
  105. </Popconfirm>,
  106. ],
  107. },
  108. ];
  109. return (
  110. <ProTable
  111. actionRef={actionRef}
  112. rowKey="id"
  113. toolBarRender={() => [
  114. <Button
  115. key="1"
  116. type="primary"
  117. onClick={() => {
  118. navigate("/system/user/edit");
  119. }}
  120. >
  121. 新增
  122. </Button>,
  123. ]}
  124. request={queryUserList}
  125. columns={columns}
  126. />
  127. );
  128. };