lisenzhou 2 yıl önce
ebeveyn
işleme
26f59e1372
1 değiştirilmiş dosya ile 59 ekleme ve 38 silme
  1. 59
    38
      src/pages/user/index.jsx

+ 59
- 38
src/pages/user/index.jsx Dosyayı Görüntüle

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