Your Name 4 년 전
부모
커밋
dc27b06ecc

+ 7
- 1
config/routes.js 파일 보기

@@ -215,7 +215,13 @@ export default [
215 215
                     path: '/system/role',
216 216
                     name: '角色管理',
217 217
                     menuCode: 'system.role',
218
-                    component: '../layouts/BlankLayout',
218
+                    component: './System/Role',
219
+                  },
220
+                  {
221
+                    path: '/system/role/edit',
222
+                    name: '角色编辑',
223
+                    menuCode: 'system.role',
224
+                    component: './System/Role/Edit',
219 225
                   },
220 226
                   {
221 227
                     path: '/system/params',

+ 2
- 0
src/pages/Post/Edit/components/Form.jsx 파일 보기

@@ -37,6 +37,7 @@ export default (props) => {
37 37
       return request('/post', { method: 'post', data })
38 38
         .then((res) => {
39 39
           props.onChange(res);
40
+          notification.success({ message: '操作成功' });
40 41
         })
41 42
         .catch((e) => {
42 43
           notification.error({ message: e.message });
@@ -48,6 +49,7 @@ export default (props) => {
48 49
     return request(`/post/${data.postId}`, { method: 'put', data })
49 50
     .then((res) => {
50 51
       props.onChange(res);
52
+      notification.success({ message: '操作成功' });
51 53
     })
52 54
     .catch((e) => {
53 55
       notification.error({ message: e.message });

+ 42
- 0
src/pages/System/Role/Edit.jsx 파일 보기

@@ -0,0 +1,42 @@
1
+import React, { useState, useEffect } from 'react'
2
+import { PageContainer } from '@ant-design/pro-layout';
3
+import { Button, Card, Divider, notification } from 'antd';
4
+import request from '@/utils/request';
5
+import RoleForm from './components/Form'
6
+
7
+export default (props) => {
8
+  const { id } = props.location.query;
9
+  const [loading, setLoading] = useState(false);
10
+  const [role, setRole] = useState({});
11
+  
12
+  const handleFormChange = (newRole) => {
13
+    setRole(newRole);
14
+  };
15
+  
16
+  useEffect(() => {
17
+    if (id) {
18
+      setLoading(true);
19
+      request(`/role/${id}`)
20
+        .then((res) => {
21
+          setRole(res);
22
+          setLoading(false);
23
+        })
24
+        .catch((e) => {
25
+          setLoading(false);
26
+          notification.error({ message: e.message });
27
+        });
28
+    }
29
+  }, [id]);
30
+
31
+  return (
32
+    <PageContainer>
33
+      <Card style={{ width: '100%' }} loading={loading}>
34
+        <RoleForm role={role} onChange={handleFormChange} />
35
+      </Card>
36
+
37
+      <Card title="授权菜单" style={{ width: '100%', marginTop: '2em' }}>
38
+        
39
+      </Card>
40
+    </PageContainer>
41
+  )
42
+}

+ 57
- 0
src/pages/System/Role/components/Form.jsx 파일 보기

@@ -0,0 +1,57 @@
1
+import React, { useEffect } from 'react';
2
+import ProForm, { ProFormText } from '@ant-design/pro-form';
3
+import request from '@/utils/request';
4
+import { notification, Form } from 'antd';
5
+
6
+export default (props) => {
7
+  const [form] = Form.useForm();
8
+
9
+  const handleSubmit = (values) => {
10
+    const data = {
11
+      ...props.role || {},
12
+      ...values,
13
+    }
14
+
15
+    if (!data.roleId) {
16
+      // 新增
17
+      return request('/role', { method: 'post', data })
18
+        .then((res) => {
19
+          notification.success({ message: '操作成功' });
20
+          props.onChange(res);
21
+        })
22
+        .catch((e) => {
23
+          notification.error({ message: e.message });
24
+          return Promise.reject(e.message);
25
+        });
26
+    }
27
+
28
+    // 编辑
29
+    return request(`/role/${data.roleId}`, { method: 'put', data })
30
+    .then((res) => {
31
+      notification.success({ message: '操作成功' });
32
+      props.onChange(res);
33
+    })
34
+    .catch((e) => {
35
+      notification.error({ message: e.message });
36
+      return Promise.reject(e.message);
37
+    });
38
+  };
39
+
40
+  useEffect(() => {
41
+    if (props.role && props.role.roleId) {
42
+      form.setFieldsValue(props.role);
43
+    }
44
+  }, [props, form]);
45
+
46
+  return (
47
+    <ProForm form={form} onFinish={handleSubmit}>
48
+      <ProFormText
49
+        label="角色名称"
50
+        placeholder="请输入角色名称"
51
+        name="name"
52
+        rules={[{ required: true, message: '请填写角色名称' }]}
53
+      />
54
+      <ProFormText label="创建日期" name="createDate" readonly />
55
+    </ProForm>
56
+  );
57
+};

+ 71
- 0
src/pages/System/Role/index.jsx 파일 보기

@@ -0,0 +1,71 @@
1
+import React, { useRef } from 'react'
2
+import { history } from 'umi';
3
+import { PageContainer } from '@ant-design/pro-layout';
4
+import ProTable from '@ant-design/pro-table';
5
+import { PlusOutlined } from '@ant-design/icons';
6
+import { Button, Popconfirm, notification } from 'antd';
7
+import request, { queryTable } from '@/utils/request';
8
+
9
+export default () => {
10
+  const tableRef = useRef()
11
+
12
+  const handleDelete = (role) => {
13
+    request(`/role/${role.roleId}`, { method: 'delete' } ).then(() => {
14
+      notification.success({ message: '操作成功' })
15
+      tableRef.current.reload()
16
+    }).catch((e) => {
17
+      notification.error({ message: e.message })
18
+    })
19
+  }
20
+
21
+  const handleEdit = (role) => {
22
+    const url = role && role.roleId ? `/system/role/edit?id=${role.roleId}` : '/system/role/edit'
23
+    history.push(url)
24
+  }
25
+
26
+  const columns = [
27
+    {
28
+      title: '名称',
29
+      key: 'name',
30
+      dataIndex: 'name',
31
+    },
32
+    {
33
+      title: '创建时间',
34
+      key: 'createDate',
35
+      dataIndex: 'createDate',
36
+      valueType: 'date',
37
+    },
38
+    {
39
+      title: '操作',
40
+      key: 'option',
41
+      valueType: 'option',
42
+      // 不能操作超级管理员
43
+      render: (_, role) => [
44
+        role.roleId !== '1' && <a key="edit" onClick={() => handleEdit(role)}>修改</a>,
45
+        role.roleId !== '1' && <Popconfirm key="delete" title="确定删除当前角色?" onConfirm={() => handleDelete(role)}>
46
+          <a href="#">删除</a>
47
+        </Popconfirm>,
48
+      ].filter(Boolean)
49
+    },
50
+  ]
51
+  
52
+  const actions = [
53
+    <Button key="button" icon={<PlusOutlined />} type="primary" onClick={handleEdit}>
54
+      新建
55
+    </Button>,
56
+  ];
57
+
58
+  return (
59
+    <PageContainer>
60
+      <ProTable
61
+        actionRef={tableRef}
62
+        columns={columns}
63
+        request={queryTable('/role')}
64
+        rowKey="roleId"
65
+        headerTitle="角色列表"
66
+        search={false}
67
+        toolBarRender={() => actions}
68
+      />
69
+    </PageContainer>
70
+  )
71
+}

+ 6
- 0
src/pages/User/Edit/components/User.jsx 파일 보기

@@ -20,6 +20,12 @@ export default (props) => {
20 20
       })
21 21
     } else {
22 22
       //
23
+      request(`/user/${props.user.userId}`, { method: 'put', data: { ...props.user, ...values} }).then(res => {
24
+        notification.success({ message: '操作成功' })
25
+        props.onChange(res)
26
+      }).catch((e) => {
27
+        notification.error({ message: e.message })
28
+      })
23 29
     }
24 30
   }
25 31
 

+ 12
- 1
src/pages/User/List/index.jsx 파일 보기

@@ -23,6 +23,17 @@ export default () => {
23 23
     history.push(url)
24 24
   }
25 25
 
26
+  const changeStatus = (user) => {
27
+    // 0 变 1, 1 变 0
28
+    const status = user.status ^ 1
29
+    request(`/user/${user.userId}`, { method: 'put', data: { ...user, status } } ).then(() => {
30
+      notification.success({ message: '操作成功' })
31
+      tableRef.current.reload()
32
+    }).catch((e) => {
33
+      notification.error({ message: e.message })
34
+    })
35
+  }
36
+
26 37
   const columns = [
27 38
     {
28 39
       title: '编号',
@@ -67,7 +78,7 @@ export default () => {
67 78
       // 不能操作超级管理员
68 79
       render: (_, user) => [
69 80
         user.userId !== '1' && <a key="edit" onClick={() => handleEdit(user)}>修改</a>,
70
-        user.userId !== '1' && <a key="disable">禁用</a>,
81
+        user.userId !== '1' && <a key="disable" onClick={() => changeStatus(user)}>{user.status === 1 ? '禁用' : '启用'}</a>,
71 82
         user.userId !== '1' && <Popconfirm key="delete" title="确定删除当前人员?" onConfirm={() => handleDelete(user)}>
72 83
           <a href="#">删除</a>
73 84
         </Popconfirm>,