Parcourir la source

feat(user): user role/department

Lind il y a 3 ans
Parent
commit
f4c65b9dfa

+ 4 - 1
src/components/BaseCrud/save/index.tsx

@@ -104,8 +104,11 @@ const Save = <T extends Record<string, any>>(props: Props<T>) => {
         values.template,
       );
     }
-    await service.update(values);
+    const response = await service.update(values);
 
+    if (response.status === 200) {
+      Store.set(SystemConst.BASE_UPDATE_DATA, response.result);
+    }
     message.success(
       intl.formatMessage({
         id: 'pages.data.option.success',

+ 8 - 2
src/pages/system/Department/index.tsx

@@ -2,7 +2,7 @@
 import { PageContainer } from '@ant-design/pro-layout';
 import ProTable from '@jetlinks/pro-table';
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
-import { useRef, useState } from 'react';
+import { useEffect, useRef, useState } from 'react';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import { Button, message, Popconfirm, Tooltip, Card, Divider } from 'antd';
 import {
@@ -18,7 +18,7 @@ import type { ISchema } from '@formily/json-schema';
 import type { DepartmentItem } from '@/pages/system/Department/typings';
 import { observer } from '@formily/react';
 import { model } from '@formily/reactive';
-import { Link } from 'umi';
+import { Link, useLocation } from 'umi';
 import Save from './save';
 import SearchComponent from '@/components/SearchComponent';
 
@@ -182,6 +182,12 @@ export default observer(() => {
     },
   };
 
+  const location = useLocation();
+  useEffect(() => {
+    if ((location as any).query?.save === 'true') {
+      State.visible = true;
+    }
+  }, []);
   return (
     <PageContainer>
       <Card>

+ 4 - 0
src/pages/system/Department/save.tsx

@@ -90,6 +90,10 @@ const Save = <T extends object>(props: SaveModalProps<T>) => {
     if (response.status === 200) {
       message.success('操作成功!');
       modalClose(true);
+      if ((window as any).onTabSaveSuccess) {
+        (window as any).onTabSaveSuccess(response.result);
+        setTimeout(() => window.close(), 300);
+      }
     } else {
       message.error('操作成功!');
     }

+ 20 - 2
src/pages/system/Role/index.tsx

@@ -1,5 +1,5 @@
 import { PageContainer } from '@ant-design/pro-layout';
-import React, { useRef } from 'react';
+import React, { useEffect, useRef } from 'react';
 import { EditOutlined, MinusOutlined } from '@ant-design/icons';
 import { message, Popconfirm, Tooltip } from 'antd';
 import type { ProColumns, ActionType } from '@jetlinks/pro-table';
@@ -11,7 +11,10 @@ import { observer } from '@formily/react';
 // import Authorization from '@/components/Authorization';
 // import { BindModel } from '@/components/BindUser/model';
 // import BindUser from '@/components/BindUser';
-import { Link } from 'umi';
+import { Link, useLocation } from 'umi';
+import { Store } from 'jetlinks-store';
+import SystemConst from '@/utils/const';
+import { CurdModel } from '@/components/BaseCrud/model';
 
 export const service = new BaseService<RoleItem>('role');
 
@@ -158,6 +161,21 @@ const Role: React.FC = observer(() => {
       },
     },
   };
+
+  const location = useLocation();
+
+  useEffect(() => {
+    if ((location as any).query?.save === 'true') {
+      CurdModel.add();
+    }
+    const subscription = Store.subscribe(SystemConst.BASE_UPDATE_DATA, (data) => {
+      if ((window as any).onTabSaveSuccess) {
+        (window as any).onTabSaveSuccess(data);
+        setTimeout(() => window.close(), 300);
+      }
+    });
+    return () => subscription.unsubscribe();
+  }, []);
   return (
     <PageContainer>
       <BaseCrud<RoleItem>

+ 21 - 13
src/pages/system/User/Save/index.tsx

@@ -177,19 +177,15 @@ const Save = (props: Props) => {
         'x-decorator-props': {
           addonAfter: (
             <a
-              // href={`${origin}/#/system/role`}
-              // target='_blank'
-              // rel='noreferrer'
               onClick={() => {
-                // const test = window.open(`${origin}/#/system/role`);
-                // test!.onSuccess1 = (data: any) => {
-                //   form.setFieldState('role', state => {
-                //     state.dataSource = [...testEnum, { label: '测试数据A', value: 'testA' }];
-                //   });
-                // console.log(JSON.stringify(data));
-                // testEnum.push({label:'测试数据A',value:'testA'});
-                // setTestEnum([...testEnum, { label: '测试数据A', value: 'testA' }]);
-                // };
+                const tab: any = window.open(`${origin}/#/system/role?save=true`);
+                tab!.onTabSaveSuccess = (value: any) => {
+                  form.setFieldState('roleIdList', (state) => {
+                    state.dataSource = state.dataSource?.concat([
+                      { label: value.name, value: value.id },
+                    ]);
+                  });
+                };
               }}
             >
               <PlusOutlined />
@@ -207,7 +203,19 @@ const Save = (props: Props) => {
         },
         'x-decorator-props': {
           addonAfter: (
-            <a>
+            <a
+              onClick={() => {
+                const tab: any = window.open(`${origin}/#/system/department?save=true`);
+                tab!.onTabSaveSuccess = (value: any) => {
+                  form.setFieldState('orgIdList', (state) => {
+                    console.log(value, 'value');
+                    state.dataSource = state.dataSource?.concat([
+                      { label: value.name, value: value.id },
+                    ]);
+                  });
+                };
+              }}
+            >
               <PlusOutlined />
             </a>
           ),

+ 0 - 2
src/typings.d.ts

@@ -22,5 +22,3 @@ declare module 'bizcharts-plugin-slider';
 declare let ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: 'site' | undefined;
 
 declare const REACT_APP_ENV: 'test' | 'dev' | 'pre' | false;
-
-declare module '@dabeng/react-orgchart';

+ 3 - 2
src/utils/BaseService.ts

@@ -31,12 +31,13 @@ class BaseService<T> implements IBaseService<T> {
     return request(`${this.uri}/${id}`, { method: 'DELETE' });
   }
 
-  save(data: T): Promise<unknown> {
+  save(data: Partial<T>): Promise<unknown> {
     return request(this.uri, { data, method: 'POST' });
   }
 
   update(data: Partial<T>): Promise<any> {
-    return request(this.uri, { data, method: 'PATCH' });
+    // @ts-ignore
+    return data.id ? request(this.uri, { data, method: 'PATCH' }) : this.save(data);
   }
 
   detail(id: string): Promise<any> {

+ 2 - 0
src/utils/const.ts

@@ -13,6 +13,8 @@ class SystemConst {
 
   static BASE_CURD_MODEL = 'BASE_CURD_MODEL';
 
+  static BASE_UPDATE_DATA = 'BASE_UPDATE_DATA';
+
   static GLOBAL_WEBSOCKET = 'GLOBAL-WEBSOCKET';
 
   static BIND_USER_STATE = 'false';