瀏覽代碼

feat(BindUser): add Org BindUser

Lind 4 年之前
父節點
當前提交
01edfd3acf

+ 39 - 20
src/components/BindUser/Bound.tsx

@@ -19,24 +19,43 @@ const Bound = observer(() => {
     return () => listener.unsubscribe();
   });
 
-  const handleUnBindData = () => {
-    const {
-      dimension: { id, type },
-    } = BindModel;
-    service.unBindData(BindModel.unBindUsers, type!, id!).subscribe({
-      next: async () => {
-        message.success('解绑成功');
-      },
-      error: async () => {
-        message.error('操作失败');
-      },
-      complete: () => {
-        // 通知右侧组建刷新
-        Store.set(SystemConst.BIND_USER_STATE, 'true');
-        actionRef.current?.reload();
-        BindModel.unBindUsers = [];
-      },
-    });
+  const handleUnBindResult = {
+    next: async () => {
+      message.success('解绑成功');
+    },
+    error: async () => {
+      message.error('操作失败');
+    },
+    complete: () => {
+      // 通知右侧组建刷新
+      Store.set(SystemConst.BIND_USER_STATE, 'true');
+      actionRef.current?.reload();
+      BindModel.unBindUsers = [];
+    },
+  };
+  const {
+    dimension: { id, type },
+  } = BindModel;
+  const handleRoleUnBind = () => {
+    service.unBindRole(BindModel.unBindUsers, type!, id!).subscribe(handleUnBindResult);
+  };
+
+  const handleOrgUnBind = () => {
+    service.unBindOrg(BindModel.unBindUsers, id!).subscribe(handleUnBindResult);
+  };
+
+  const handleUnbind = async () => {
+    const bindType = BindModel.dimension.type;
+    switch (bindType) {
+      case 'role':
+        handleRoleUnBind();
+        break;
+      case 'org':
+        handleOrgUnBind();
+        break;
+      default:
+        message.error('解绑类型数据错误');
+    }
   };
 
   return (
@@ -62,7 +81,7 @@ const Bound = observer(() => {
         )}
         tableAlertOptionRender={() => (
           <Space size={16}>
-            <a onClick={handleUnBindData}>批量解绑</a>
+            <a onClick={handleUnbind}>批量解绑</a>
           </Space>
         )}
         actionRef={actionRef}
@@ -72,7 +91,7 @@ const Bound = observer(() => {
         }}
         request={async (params) => service.query(params)}
         defaultParams={{
-          'id$in-dimension$role': BindModel.dimension.id,
+          [`id$in-dimension$${BindModel.dimension.type}`]: BindModel.dimension.id,
         }}
         toolBarRender={() => [
           <Button

+ 40 - 13
src/components/BindUser/Unbound.tsx

@@ -19,7 +19,29 @@ const Unbound = observer(() => {
     return () => listener.unsubscribe();
   });
 
-  const handleBindData = () => {
+  const handleBindResult = {
+    next: () => message.success('绑定成功'),
+    error: async () => {
+      message.success('绑定失败');
+    },
+    complete: () => {
+      // 通知左侧组件刷新
+      Store.set(SystemConst.BIND_USER_STATE, 'true');
+      actionRef.current?.reload();
+      BindModel.bindUsers = [];
+    },
+  };
+
+  const handleOrgBind = () => {
+    service
+      .saveOrgBind(
+        BindModel.bindUsers.map((item) => item.userId),
+        BindModel.dimension.id!,
+      )
+      .subscribe(handleBindResult);
+  };
+
+  const handleRoleBind = () => {
     const data = BindModel.bindUsers.map(
       (item) =>
         ({
@@ -29,16 +51,21 @@ const Unbound = observer(() => {
           dimensionName: BindModel.dimension.name,
         } as BindDataItem),
     );
-    service.saveBindData(data).subscribe({
-      next: () => message.success('绑定成功'),
-      error: () => {},
-      complete: () => {
-        // 通知左侧组件刷新
-        Store.set(SystemConst.BIND_USER_STATE, 'true');
-        actionRef.current?.reload();
-        BindModel.bindUsers = [];
-      },
-    });
+    service.saveRoleBind(data).subscribe(handleBindResult);
+  };
+
+  const handleBind = async () => {
+    const bindType = BindModel.dimension.type;
+    switch (bindType) {
+      case 'role':
+        handleRoleBind();
+        break;
+      case 'org':
+        handleOrgBind();
+        break;
+      default:
+        message.error('绑定类型数据错误');
+    }
   };
 
   return (
@@ -76,7 +103,7 @@ const Unbound = observer(() => {
         )}
         tableAlertOptionRender={() => (
           <Space size={16}>
-            <a onClick={handleBindData}>批量绑定</a>
+            <a onClick={handleBind}>批量绑定</a>
           </Space>
         )}
         size="small"
@@ -86,7 +113,7 @@ const Unbound = observer(() => {
         }}
         request={async (params) => service.query(params)}
         defaultParams={{
-          'id$in-dimension$role$not': BindModel.dimension.id,
+          [`id$in-dimension$${BindModel.dimension.type}$not`]: BindModel.dimension.id,
         }}
       />
     </Card>

+ 2 - 0
src/components/BindUser/model.ts

@@ -10,10 +10,12 @@ export const BindModel = model<{
     name?: string;
     type?: string;
   };
+  queryUserTerms: string;
 }>({
   visible: false,
   bind: false,
   bindUsers: [],
   unBindUsers: [],
   dimension: {},
+  queryUserTerms: '',
 });

+ 22 - 2
src/components/BindUser/service.ts

@@ -14,7 +14,7 @@ class Service extends BaseService<UserItem> {
       ),
     );
 
-  public saveBindData = (data: BindDataItem[]) =>
+  public saveRoleBind = (data: BindDataItem[]) =>
     defer(() =>
       from(
         request(`/${SystemConst.API_BASE}/dimension-user`, {
@@ -24,7 +24,7 @@ class Service extends BaseService<UserItem> {
       ),
     );
 
-  public unBindData = (data: string[], dimensionType: string, dimensionId: string) =>
+  public unBindRole = (data: string[], dimensionType: string, dimensionId: string) =>
     defer(() =>
       from(
         request(
@@ -36,6 +36,26 @@ class Service extends BaseService<UserItem> {
         ),
       ),
     );
+
+  public saveOrgBind = (data: string[], orgId: string) =>
+    defer(() =>
+      from(
+        request(`/${SystemConst.API_BASE}/organization/${orgId}/users/_bind`, {
+          method: 'POST',
+          data,
+        }),
+      ),
+    );
+
+  public unBindOrg = (data: string[], orgId: string) =>
+    defer(() =>
+      from(
+        request(`/${SystemConst.API_BASE}/organization/${orgId}/users/_unbind`, {
+          method: 'POST',
+          data,
+        }),
+      ),
+    );
 }
 
 export default Service;

+ 24 - 10
src/pages/system/Org/index.tsx

@@ -1,7 +1,7 @@
 import { PageContainer } from '@ant-design/pro-layout';
 import OrganizationChart from '@dabeng/react-orgchart';
 import styles from './index.less';
-import { Drawer, Menu, message } from 'antd';
+import { Drawer, Menu, message, Modal } from 'antd';
 import NodeTemplate from '@/pages/system/Org/NodeTemplate';
 import { model } from '@formily/reactive';
 import { observer } from '@formily/react';
@@ -13,6 +13,8 @@ import Save from '@/pages/system/Org/Save';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import autzModel from '@/components/Authorization/autz';
 import Authorization from '@/components/Authorization';
+import { BindModel } from '@/components/BindUser/model';
+import BindUser from '@/components/BindUser';
 
 const obs = model<ObsModel>({
   edit: false,
@@ -101,8 +103,7 @@ const Org = observer(() => {
       <Menu>
         <Menu.Item>
           <a
-            target="_blank"
-            rel="noopener noreferrer"
+            key="edit"
             onClick={() => {
               // setParentId(null);
               // setCurrent(nodeData);
@@ -116,7 +117,7 @@ const Org = observer(() => {
           </a>
         </Menu.Item>
         <Menu.Item>
-          <a target="_blank" rel="noopener noreferrer" onClick={() => obs.addNext(nodeData)}>
+          <a key="addNext" onClick={() => obs.addNext(nodeData)}>
             {intl.formatMessage({
               id: 'pages.system.org.option.add',
               defaultMessage: '添加下级',
@@ -125,8 +126,7 @@ const Org = observer(() => {
         </Menu.Item>
         <Menu.Item>
           <a
-            target="_blank"
-            rel="noopener noreferrer"
+            key="autz"
             onClick={() => {
               autzModel.autzTarget.id = nodeData.id;
               autzModel.autzTarget.name = nodeData.name;
@@ -141,11 +141,14 @@ const Org = observer(() => {
         </Menu.Item>
         <Menu.Item>
           <a
-            target="_blank"
-            rel="noopener noreferrer"
+            key="bindUser"
             onClick={() => {
-              // setCurrent(nodeData);
-              // setUserVisible(true);
+              BindModel.dimension = {
+                id: nodeData.id,
+                name: nodeData.name,
+                type: 'org',
+              };
+              BindModel.visible = true;
             }}
           >
             {intl.formatMessage({
@@ -177,6 +180,17 @@ const Org = observer(() => {
         />
       </div>
       <Save obs={obs} />
+      <Modal
+        visible={BindModel.visible}
+        closable={false}
+        onCancel={() => {
+          BindModel.visible = false;
+          BindModel.bind = false;
+        }}
+        width={BindModel.bind ? '90vw' : '60vw'}
+      >
+        <BindUser />
+      </Modal>
       <Drawer
         title="授权"
         width="50vw"