Ver código fonte

fix(user): fix userPermission

lind 4 anos atrás
pai
commit
60bd197597

+ 15 - 5
src/pages/system/User/Save/index.tsx

@@ -20,7 +20,8 @@ import type { ISchema } from '@formily/json-schema';
 import { action } from '@formily/reactive';
 import type { Response } from '@/utils/typings';
 import { service } from '@/pages/system/User';
-import { Modal } from '@/components';
+import { Modal, PermissionButton } from '@/components';
+import usePermissions from '@/hooks/permission';
 
 interface Props {
   model: 'add' | 'edit' | 'query';
@@ -32,6 +33,9 @@ const Save = (props: Props) => {
   const { model } = props;
   const intl = useIntl();
 
+  const { permission: deptPermission } = usePermissions('system/Department');
+  const { permission: rolePermission } = usePermissions('system/Role');
+
   const [data, setData] = useState<Partial<UserItem>>(props.data);
 
   const getRole = () => service.queryRoleList();
@@ -291,7 +295,10 @@ const Save = (props: Props) => {
             'x-decorator-props': {
               gridSpan: 1,
               addonAfter: (
-                <a
+                <PermissionButton
+                  type="link"
+                  style={{ padding: 0 }}
+                  isPermission={rolePermission.add}
                   onClick={() => {
                     const tab: any = window.open(`${origin}/#/system/role?save=true`);
                     tab!.onTabSaveSuccess = (value: any) => {
@@ -305,7 +312,7 @@ const Save = (props: Props) => {
                   }}
                 >
                   <PlusOutlined />
-                </a>
+                </PermissionButton>
               ),
             },
           },
@@ -329,7 +336,10 @@ const Save = (props: Props) => {
             'x-decorator-props': {
               gridSpan: 1,
               addonAfter: (
-                <a
+                <PermissionButton
+                  type="link"
+                  style={{ padding: 0 }}
+                  isPermission={deptPermission.add}
                   onClick={() => {
                     const tab: any = window.open(`${origin}/#/system/department?save=true`);
                     tab!.onTabSaveSuccess = (value: any) => {
@@ -347,7 +357,7 @@ const Save = (props: Props) => {
                   }}
                 >
                   <PlusOutlined />
-                </a>
+                </PermissionButton>
               ),
             },
             'x-reactions': ['{{useAsyncDataSource(getOrg)}}'],

+ 18 - 14
src/pages/system/User/index.tsx

@@ -16,6 +16,8 @@ import { useRef, useState } from 'react';
 import Save from './Save';
 import { observer } from '@formily/react';
 import { getButtonPermission } from '@/utils/menu';
+import { PermissionButton } from '@/components';
+import usePermissions from '@/hooks/permission';
 
 export const service = new Service('user');
 
@@ -23,6 +25,7 @@ const User = observer(() => {
   const intl = useIntl();
   const actionRef = useRef<ActionType>();
 
+  const { permission: userPermission } = usePermissions('system/User');
   const [model, setMode] = useState<'add' | 'edit' | 'query'>('query');
   const [current, setCurrent] = useState<Partial<UserItem>>({});
   const edit = async (record: UserItem) => {
@@ -164,23 +167,24 @@ const User = observer(() => {
             </Tooltip>
           </Popconfirm>
         </Button>,
-        <Button
+        <PermissionButton
           type="link"
+          key="delete"
           style={{ padding: 0 }}
-          disabled={record.status === 1 || getButtonPermission('system/User', 'delete')}
+          isPermission={userPermission.delete}
+          disabled={record.status === 1}
+          tooltip={{ title: record.status === 0 ? '删除' : '请先禁用该用户,再删除。' }}
         >
-          <Tooltip title={record.status === 0 ? '删除' : '请先禁用该用户,再删除。'} key="delete">
-            <Popconfirm
-              onConfirm={async () => {
-                await service.remove(record.id);
-                actionRef.current?.reload();
-              }}
-              title="确认删除?"
-            >
-              <DeleteOutlined />
-            </Popconfirm>
-          </Tooltip>
-        </Button>,
+          <Popconfirm
+            onConfirm={async () => {
+              await service.remove(record.id);
+              actionRef.current?.reload();
+            }}
+            title="确认删除?"
+          >
+            <DeleteOutlined />
+          </Popconfirm>
+        </PermissionButton>,
       ],
     },
   ];

+ 6 - 3
src/utils/menu/router.ts

@@ -5,7 +5,7 @@ export enum MENUS_CODE {
   'Analysis/DeviceMessage' = 'Analysis/DeviceMessage',
   'Analysis/Jvm' = 'Analysis/Jvm',
   'Analysis/MessageChart' = 'Analysis/MessageChart',
-  Analysis = 'Analysis',
+  'Analysis' = 'Analysis',
   'cloud/Aliyun' = 'cloud/Aliyun',
   'cloud/Ctwing' = 'cloud/Ctwing',
   'cloud/DuerOS' = 'cloud/DuerOS',
@@ -39,7 +39,7 @@ export enum MENUS_CODE {
   'link/Protocol' = 'link/Protocol',
   'link/Type' = 'link/Type',
   'link/AccessConfig' = 'link/AccessConfig',
-  Log = 'Log',
+  'Log' = 'Log',
   'media/Cascade' = 'media/Cascade',
   'media/Cascade/Save' = 'media/Cascade/Save',
   'media/Cascade/Channel' = 'media/Cascade/Channel',
@@ -121,7 +121,10 @@ export enum BUTTON_PERMISSION_ENUM {
   'sync' = 'sync',
 }
 
-export type BUTTON_PERMISSION = keyof typeof BUTTON_PERMISSION_ENUM | string;
+// 调试按钮、通知记录、批量导出、批量导入、选择通道、推送、分配资产、绑定用户对应的ID是啥
+export type CUSTOM_BUTTON = 'debug' | 'log' | 'channel' | 'assert' | 'bind-user';
+
+export type BUTTON_PERMISSION = keyof typeof BUTTON_PERMISSION_ENUM | string | CUSTOM_BUTTON;
 
 export const getDetailNameByCode = {
   'system/Menu/Detail': '菜单详情',