Your Name 2 anos atrás
pai
commit
f64d0735cd

+ 98
- 0
src/pages/org/components/Form.jsx Ver arquivo

@@ -0,0 +1,98 @@
1
+import React from 'react';
2
+import { Button, Card, Form, Input, Select } from 'antd';
3
+import useBool from '@/utils/hooks/useBool';
4
+import { postSysOrg, putSysOrg, getSysOrgById } from "@/service/sysorg";
5
+import { formItemLayout, tailFormItemLayout } from '@/utils/form';
6
+
7
+export default (props) => {
8
+  const { org, list, parentId, onChange } = props;
9
+
10
+  const [submiting, startSubmit, cancelSubmit] = useBool();
11
+  const [form] = Form.useForm();
12
+  
13
+  const onFinish = (values) => {
14
+    startSubmit();
15
+    if (org?.orgId) {
16
+      // 修改
17
+      putSysOrg(org.orgId, values).then((res) => {
18
+        cancelSubmit();
19
+        onChange(res);
20
+      }).catch(() => {
21
+        cancelSubmit();
22
+      });
23
+    } else {
24
+      // 新增
25
+      postSysOrg(values).then((res) => {
26
+        cancelSubmit();
27
+        onChange(res);
28
+      }).catch(() => {
29
+        cancelSubmit();
30
+      });
31
+    }
32
+  }
33
+
34
+  React.useEffect(() => {
35
+    if (org) {
36
+      form.setFieldsValue(org);
37
+    } else {
38
+      form.resetFields();
39
+      form.setFieldValue('orgPId', parentId);
40
+    }
41
+
42
+    console.log(org, parentId);
43
+  }, [org, parentId]);
44
+
45
+  return (
46
+    <Form onFinish={onFinish} form={form} {...formItemLayout} style={{width: '800px'}}>
47
+      <Form.Item
48
+        name="name"
49
+        label="机构名称"
50
+        rules={[
51
+          {required: true, message: '请填写机构名称'}
52
+        ]}
53
+      >
54
+        <Input />
55
+      </Form.Item>
56
+      <Form.Item
57
+        name="orgPId"
58
+        label="上级单位"
59
+      >
60
+        <Select>
61
+          {
62
+            (list || []).map(x => (
63
+              <Select.Option key={x.orgId}>
64
+                {x.name}
65
+              </Select.Option>
66
+            ))
67
+          }
68
+        </Select>
69
+      </Form.Item>
70
+
71
+      <Form.Item
72
+        name="sortNo"
73
+        label="排序"
74
+      >
75
+        <Input />
76
+      </Form.Item>
77
+
78
+
79
+      <Form.Item
80
+        name="status"
81
+        label="状态"
82
+      >
83
+        <Select
84
+          style={{ width: '100%' }}
85
+          placeholder="请选择状态"
86
+        >
87
+          <Option value={0}>不正常</Option>
88
+          <Option value={1}>正常</Option>
89
+        </Select>
90
+      </Form.Item>
91
+      <Form.Item {...tailFormItemLayout}>
92
+        <Button loading={submiting} type="primary" htmlType="submit">
93
+          保存
94
+        </Button>
95
+      </Form.Item>
96
+    </Form>
97
+  )
98
+}

+ 0
- 131
src/pages/org/edit/index.jsx Ver arquivo

@@ -1,131 +0,0 @@
1
-import React, { useEffect, useState } from 'react';
2
-import { Button, Card, Form, Input, Select } from 'antd';
3
-import useBool from '@/utils/hooks/useBool';
4
-import { postSysOrg, putSysOrg, getSysOrgById } from "@/service/sysorg";
5
-import { useSearchParams, useNavigate } from 'react-router-dom';
6
-
7
-const formItemLayout = {
8
-  labelCol: {
9
-    xs: { span: 24 },
10
-    sm: { span: 8 },
11
-  },
12
-  wrapperCol: {
13
-    xs: { span: 24 },
14
-    sm: { span: 16 },
15
-  },
16
-};
17
-const tailFormItemLayout = {
18
-  wrapperCol: {
19
-    xs: {
20
-      span: 24,
21
-      offset: 0,
22
-    },
23
-    sm: {
24
-      span: 16,
25
-      offset: 8,
26
-    },
27
-  },
28
-};
29
-
30
-const { Option } = Select;
31
-
32
-export default (props) => {
33
-
34
-  const [loading, startLoading, cancelLoading] = useBool();
35
-  const [submiting, startSubmit, cancelSubmit] = useBool();
36
-  const [form] = Form.useForm();
37
-  const navigate = useNavigate();
38
-  const [searchParams, setSearchParams] = useSearchParams();
39
-  const id = searchParams.get("id");
40
-
41
-  useEffect(() => {
42
-    if (id) {
43
-      getSysOrgById(id).then((res) => {
44
-        form.setFieldsValue(res);
45
-        // setDate(res);
46
-      });
47
-    }
48
-  }, [id]);
49
-
50
-  const onFinish = (values) => {
51
-    startSubmit();
52
-    if (id) {
53
-      // 修改
54
-      putSysOrg(id, values).then((res) => {
55
-        navigate(-1);
56
-      }).catch(() => {
57
-        cancelSubmit();
58
-      });
59
-    } else {
60
-      // 新增
61
-      postSysOrg(values).then((res) => {
62
-        navigate(-1);
63
-      }).catch(() => {
64
-        cancelSubmit();
65
-      });
66
-    }
67
-  }
68
-
69
-
70
-  return (
71
-    <Card loading={loading}>
72
-      <Form onFinish={onFinish} form={form} {...formItemLayout} scrollToFirstError style={{ maxWidth: '1000px' }}>
73
-        <Form.Item
74
-          name="orgCode"
75
-          label="机构编码"
76
-        >
77
-          <Input />
78
-        </Form.Item>
79
-        <Form.Item
80
-          name="name"
81
-          label="机构名称"
82
-        >
83
-          <Input />
84
-        </Form.Item>
85
-        <Form.Item
86
-          name="orgPId"
87
-          label="上级单位"
88
-        >
89
-          <Input />
90
-        </Form.Item>
91
-
92
-        <Form.Item
93
-          name="sortNo"
94
-          label="排序"
95
-        >
96
-          <Input />
97
-        </Form.Item>
98
-
99
-
100
-        <Form.Item
101
-          name="status"
102
-          label="状态"
103
-        >
104
-          <Select
105
-            style={{ width: '100%' }}
106
-            placeholder="请选择状态"
107
-          >
108
-            <Option key={0}>不正常</Option>
109
-            <Option key={1}>正常</Option>
110
-          </Select>
111
-        </Form.Item>
112
-        <Form.Item
113
-          name="createUser"
114
-          label="创建人"
115
-        >
116
-          <Input />
117
-        </Form.Item>
118
-        <Form.Item {...tailFormItemLayout}>
119
-          <Button loading={submiting} type="primary" htmlType="submit">
120
-            保存
121
-          </Button>
122
-          <Button style={{ marginLeft: '2em' }} onClick={() => navigate(-1)}>
123
-            返回
124
-          </Button>
125
-        </Form.Item>
126
-      </Form>
127
-    </Card>
128
-  )
129
-}
130
-
131
-

+ 116
- 0
src/pages/org/index.jsx Ver arquivo

@@ -0,0 +1,116 @@
1
+import React from 'react';
2
+import {
3
+  PlusOutlined,
4
+  DeleteOutlined,
5
+} from '@ant-design/icons';
6
+import { Button, Card, Row, Col, Tree, Tooltip, Popconfirm } from "antd";
7
+import Page from '@/components/Page';
8
+import { getSysOrg, deleteSysOrg } from "@/service/sysorg";
9
+import { arr2Tree } from '@/utils/array';
10
+import useBool from '@/utils/hooks/useBool';
11
+import Form from './components/Form';
12
+
13
+export default (props) => {
14
+
15
+  const [loading, startLoading, stopLoading] = useBool();
16
+  const [list, setList] = React.useState([]);
17
+  const [current, setCurrernt] = React.useState();
18
+  const [parentId, setParentId] = React.useState('-1');
19
+
20
+  const [parentList, treeData] = React.useMemo(() => {
21
+    const plist = [{orgId: '-1', name: '根节点'}].concat(list);
22
+    const [tree] = arr2Tree((list || []).map(x => ({
23
+      title: x.name,
24
+      key: x.orgId,
25
+      parentId: x.orgPId,
26
+      raw: x,
27
+    })));
28
+
29
+    return [plist, tree];
30
+  }, [list])
31
+
32
+  const changeCurrent = (org) => {
33
+    setCurrernt(org);
34
+    setParentId(org?.orgPId || '-1');
35
+  }
36
+
37
+  const onSelect = (selectedKeys, e) => {
38
+    changeCurrent(e.node.raw)
39
+  }
40
+
41
+  const onClick = (org) => {
42
+    changeCurrent(org);
43
+  }
44
+
45
+  const onAdd = (parent = '-1') => {
46
+    setParentId(parent);
47
+    setCurrernt();
48
+  }
49
+
50
+  const onDelete = (org) => {
51
+    deleteSysOrg(org.orgId).then(() => {
52
+      setList(list.filter(x => x.orgId !== org.orgId))
53
+    });
54
+  }
55
+
56
+  const queryList = React.useCallback(() => {
57
+    getSysOrg({pageSize: 500}).then(res => {
58
+      setList(res.records || []);
59
+      changeCurrent();
60
+    });
61
+  }, []);
62
+
63
+  const onFormChange = () => {
64
+    // 重新查一次数据
65
+    queryList();
66
+  }
67
+
68
+  React.useEffect(() => {
69
+    queryList();
70
+  }, []);
71
+
72
+  return (
73
+    <Page>
74
+      <Row gutter={24}>
75
+        <Col span={8}>
76
+          <Card
77
+            title="单位"
78
+            onSelect={onSelect}
79
+            extra={<Button type='link' onClick={() => onAdd()}>新增</Button>}
80
+          >
81
+            <Tree
82
+              blockNode
83
+              treeData={treeData}
84
+              // onSelect={onSelect}
85
+              titleRender={(node) => (
86
+                <div style={{display: 'flex'}} onClick={e => e.stopPropagation()}>
87
+                  <div style={{lineHeight: '32px', flex: 1}} onClick={() => onClick(node.raw)}>
88
+                    {node.title}
89
+                  </div>
90
+                  <div style={{width: '80px', flex: 'none'}}>
91
+                    <Tooltip title="新增子节点">
92
+                      <Button type='link' icon={<PlusOutlined />} onClick={() => onAdd(node.raw.orgId)}></Button>
93
+                    </Tooltip>
94
+                    <Tooltip title="删除节点">
95
+                      <Popconfirm
96
+                        title="确认进行删除操作?"
97
+                        onConfirm={() => onDelete(node.raw)}
98
+                      >
99
+                        <Button type='link' danger icon={<DeleteOutlined />}></Button>
100
+                      </Popconfirm>
101
+                    </Tooltip>
102
+                  </div>
103
+                </div>
104
+              )}
105
+            />
106
+          </Card>
107
+        </Col>
108
+        <Col span={16}>
109
+          <Card>
110
+            <Form org={current} parentId={parentId} list={parentList} onChange={onFormChange} />
111
+          </Card>
112
+        </Col>
113
+      </Row>
114
+    </Page>
115
+  )
116
+}

+ 0
- 120
src/pages/org/list/index.jsx Ver arquivo

@@ -1,120 +0,0 @@
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 { getSysOrg, deleteSysOrg } from "@/service/sysorg";
7
-
8
-const querySysOrgList = queryTable(getSysOrg);
9
-
10
-export default (props) => {
11
-  const actionRef = React.useRef();
12
-  const navigate = useNavigate();
13
-
14
-  // const updateStatus = (user) => {
15
-  //   const status = user.status === 1 ? 0 : 1;
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
-      deleteSysOrg(id).then((res) => {
29
-        actionRef.current.reload();
30
-      });
31
-    }
32
-  };
33
-
34
-  const columns = [
35
-    {
36
-      title: "机构名称",
37
-      dataIndex: "name",
38
-    },
39
-    {
40
-      title: "上级单位",
41
-      dataIndex: "orgPId",
42
-    },
43
-
44
-    {
45
-      title: "状态",
46
-      dataIndex: "status",
47
-      valueEnum: {
48
-        1: {
49
-          text: "正常",
50
-          status: "Processing",
51
-        },
52
-        0: {
53
-          text: "禁用",
54
-          status: "Error",
55
-        },
56
-      },
57
-    },
58
-    {
59
-      title: "操作",
60
-      valueType: "option",
61
-      width: 200,
62
-      render: (_, record) => [
63
-        // <Button
64
-        //   key={1}
65
-        //   style={{ padding: 0 }}
66
-        //   type="link"
67
-        //   onClick={() => {
68
-        //     updateStatus(record);
69
-        //   }}
70
-        // >
71
-        //   {record.status === 1 ? "禁用" : "启用"}
72
-        // </Button>,
73
-        <Button
74
-          key={2}
75
-          style={{ padding: 0 }}
76
-          type="link"
77
-          onClick={() => {
78
-            console.log(record, "]]");
79
-            navigate(`/system/org/edit?id=${record.orgId}`);
80
-          }}
81
-        >
82
-          编辑
83
-        </Button>,
84
-        <Popconfirm
85
-          key={3}
86
-          title="您是否确认删除 ?"
87
-          onConfirm={() => handleDelete(record.orgId)}
88
-          okText="确定"
89
-          cancelText="取消"
90
-        >
91
-          {/* manualPush */}
92
-          <Button style={{ padding: 0 }} type="link">
93
-            删除
94
-          </Button>
95
-        </Popconfirm>,
96
-      ],
97
-    },
98
-  ];
99
-
100
-  return (
101
-    <ProTable
102
-      actionRef={actionRef}
103
-      rowKey="orgId"
104
-      search={false}
105
-      toolBarRender={() => [
106
-        <Button
107
-          key="1"
108
-          type="primary"
109
-          onClick={() => {
110
-            navigate("/system/org/edit");
111
-          }}
112
-        >
113
-          新增
114
-        </Button>,
115
-      ]}
116
-      request={querySysOrgList}
117
-      columns={columns}
118
-    />
119
-  );
120
-};

+ 2
- 8
src/pages/position/edit/index.jsx Ver arquivo

@@ -120,16 +120,10 @@ export default (props) => {
120 120
             style={{ width: '100%' }}
121 121
             placeholder="请选择状态"
122 122
           >
123
-            <Option key={0}>不正常</Option>
124
-            <Option key={1}>正常</Option>
123
+            <Option value={0}>不正常</Option>
124
+            <Option value={1}>正常</Option>
125 125
           </Select>
126 126
         </Form.Item>
127
-        <Form.Item
128
-          name="createUser"
129
-          label="创建人"
130
-        >
131
-          <Input />
132
-        </Form.Item>
133 127
         <Form.Item {...tailFormItemLayout}>
134 128
           <Button loading={submiting} type="primary" htmlType="submit">
135 129
             保存

+ 0
- 12
src/pages/position/list/index.jsx Ver arquivo

@@ -32,18 +32,10 @@ export default (props) => {
32 32
   };
33 33
 
34 34
   const columns = [
35
-    {
36
-      title: "岗位ID",
37
-      dataIndex: "positionId",
38
-    },
39 35
     {
40 36
       title: "岗位名称",
41 37
       dataIndex: "name",
42 38
     },
43
-    {
44
-      title: "上级岗位",
45
-      dataIndex: "positionPId",
46
-    },
47 39
     {
48 40
       title: "所属单位",
49 41
       dataIndex: "orgId",
@@ -67,10 +59,6 @@ export default (props) => {
67 59
         },
68 60
       },
69 61
     },
70
-    {
71
-      title: "创建人",
72
-      dataIndex: "createUser",
73
-    },
74 62
     {
75 63
       title: "操作",
76 64
       valueType: "option",

+ 3
- 13
src/routes/routes.jsx Ver arquivo

@@ -17,13 +17,13 @@ import User from '@/pages/user/index';
17 17
 import UserEdit from '@/pages/user/Edit';
18 18
 import CheckList from '@/pages/check';
19 19
 import CheckEdit from '@/pages/check/Edit';
20
+import OrgList from "@/pages/org/index";
20 21
 
21 22
 import Index from '@/pages/index';
22 23
 import Home from "@/pages/sample/home";
23 24
 import BasicForm from '@/pages/sample/form';
24 25
 import BasicTable from '@/pages/sample/table';
25
-import OrgList from "@/pages/org/list";
26
-import OrgEdit from "@/pages/org/edit";
26
+
27 27
 import PositionList from "@/pages/position/list";
28 28
 import PositionEdit from "@/pages/position/edit";
29 29
 import LocTypeList from "@/pages/locType/list";
@@ -87,7 +87,7 @@ export const authRoutes = [
87 87
         },
88 88
       },
89 89
       {
90
-        path: "org/list",
90
+        path: "org",
91 91
         element: <OrgList />,
92 92
         meta: {
93 93
           title: '机构管理',
@@ -95,16 +95,6 @@ export const authRoutes = [
95 95
           // permission: 'form',
96 96
         },
97 97
       },
98
-      {
99
-        path: "org/edit",
100
-        element: <OrgEdit />,
101
-        meta: {
102
-          hideInMenu: true,
103
-          title: '机构管理编辑',
104
-          // icon: <AppstoreOutlined />,
105
-          // permission: 'form',
106
-        },
107
-      },
108 98
       {
109 99
         path: "position/list",
110 100
         element: <PositionList />,

+ 1
- 1
src/utils/hooks/useBool.js Ver arquivo

@@ -1,6 +1,6 @@
1 1
 import React from "react";
2 2
 
3
-export default function useLoading(initial = false) {
3
+export default function useBool(initial = false) {
4 4
   const [loading, setLoading] = React.useState(initial);
5 5
   const loadingRef = React.useRef();
6 6
   loadingRef.current = loading;