Parcourir la source

fix: 调整角色列表请求位置

outaozhen il y a 3 ans
Parent
commit
a2654eb077

+ 7 - 27
src/pages/Permission/Role/components/RoleLeftMenu/index.tsx

@@ -1,9 +1,4 @@
-import {
-  addRoleMenu,
-  delRoleMenu,
-  fetchRoleListByMenu,
-  updateRoleMenu
-} from '@/services/permission'
+import { addRoleMenu, delRoleMenu, updateRoleMenu } from '@/services/permission'
 import {
   DeleteOutlined,
   FormOutlined,
@@ -17,29 +12,13 @@ import { useRequest } from 'umi'
 import './index.less'
 const { DirectoryTree } = Tree
 
-const RoleLeftMenu = ({ onSelect }) => {
+const RoleLeftMenu = ({ onSelect, menuRoles, onReloadStaff }) => {
   const [state, setState] = useState({
     value: ''
   })
-  const [menuRoles, setMenuRoles] = useState<API.MenuRoleItem[]>([])
-  const { run: tryFetchRoleListByMenu } = useRequest(() => fetchRoleListByMenu(), {
-    manual: true,
-    onSuccess: result => {
-      setMenuRoles(
-        result.map(item => ({
-          key: item.ID,
-          title: item.name,
-          roleType: item.roleType
-        }))
-      )
-      result?.length && onSelect?.(result[0]?.ID)
-    }
-  })
   const { run: tryAddRole } = useRequest((params: API.CreateRoleParams) => addRoleMenu(params), {
     manual: true,
-    onSuccess: () => {
-      tryFetchRoleListByMenu()
-    }
+    onSuccess: () => {}
   })
   const onChangeName = value => {
     setState({ ...state, name: value })
@@ -50,7 +29,7 @@ const RoleLeftMenu = ({ onSelect }) => {
       manual: true,
       onSuccess: () => {
         message.success('修改成功')
-        tryFetchRoleListByMenu()
+        onReloadStaff()
       }
     }
   )
@@ -58,7 +37,7 @@ const RoleLeftMenu = ({ onSelect }) => {
     manual: true,
     onSuccess: () => {
       message.success('删除成功')
-      tryFetchRoleListByMenu()
+      onReloadStaff()
     }
   })
   function renderTreeNode(tree) {
@@ -104,7 +83,7 @@ const RoleLeftMenu = ({ onSelect }) => {
     })
   }
   useEffect(() => {
-    tryFetchRoleListByMenu()
+    onReloadStaff()
   }, [])
 
   return (
@@ -144,6 +123,7 @@ const RoleLeftMenu = ({ onSelect }) => {
             <DirectoryTree
               defaultSelectedKeys={[menuRoles[0]?.key]}
               onSelect={(keys, node) => onSelect(keys[0], node.node.roleType)}
+              // onSelect={(keys, node) => console.log(keys)}
               showIcon={false}
               treeData={renderTreeNode(menuRoles)}
             />

+ 26 - 26
src/pages/Permission/Role/components/SetPermission/index.tsx

@@ -175,31 +175,31 @@ const SetPermission = ({ ID, roleType = 'system' }) => {
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'accessBa1')}
                     checked={state.frontPermission.includes('accessBa1')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     查看项目
                   </Checkbox>
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'addBa1')}
                     checked={state.frontPermission.includes('addBa1')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     新建项目
                   </Checkbox>
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'editBa1')}
                     checked={state.frontPermission.includes('editBa1')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     编辑项目
                   </Checkbox>
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'bindBa1')}
                     checked={state.frontPermission.includes('bindBa1')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     绑定角色
                   </Checkbox>
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'deployBa1')}
                     checked={state.frontPermission.includes('deployBa1')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     流程配置
                   </Checkbox>
                 </div>
@@ -210,19 +210,19 @@ const SetPermission = ({ ID, roleType = 'system' }) => {
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'accessBa2')}
                     checked={state.frontPermission.includes('accessBa2')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     查看流程
                   </Checkbox>
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'addBa2')}
                     checked={state.frontPermission.includes('addBa2')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     新建流程
                   </Checkbox>
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'editBa2')}
                     checked={state.frontPermission.includes('editBa2')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     编辑流程
                   </Checkbox>
                 </div>
@@ -233,19 +233,19 @@ const SetPermission = ({ ID, roleType = 'system' }) => {
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'accessBa3')}
                     checked={state.frontPermission.includes('accessBa3')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     查看创建人
                   </Checkbox>
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'addBa3')}
                     checked={state.frontPermission.includes('addBa3')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     新建创建人
                   </Checkbox>
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'deleteBa3')}
                     checked={state.frontPermission.includes('deleteBa3')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     删除创建人
                   </Checkbox>
                 </div>
@@ -260,31 +260,31 @@ const SetPermission = ({ ID, roleType = 'system' }) => {
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'accessBa4')}
                     checked={state.frontPermission.includes('accessBa4')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     查看单位
                   </Checkbox>
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'addBa4')}
                     checked={state.frontPermission.includes('addBa4')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     新建单位
                   </Checkbox>
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'staff')}
                     checked={state.frontPermission.includes('staff')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     人员管理
                   </Checkbox>
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'organizational')}
                     checked={state.frontPermission.includes('organizational')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     组织管理
                   </Checkbox>
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'deploy')}
                     checked={state.frontPermission.includes('deploy')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     单位设置
                   </Checkbox>
                 </div>
@@ -295,13 +295,13 @@ const SetPermission = ({ ID, roleType = 'system' }) => {
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'accessBa5')}
                     checked={state.frontPermission.includes('accessBa5')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     查看人员
                   </Checkbox>
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'editBa5')}
                     checked={state.frontPermission.includes('editBa5')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     编辑人员
                   </Checkbox>
                 </div>
@@ -316,13 +316,13 @@ const SetPermission = ({ ID, roleType = 'system' }) => {
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'accessBa6')}
                     checked={state.frontPermission.includes('accessBa6')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     查看信息
                   </Checkbox>
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'editBa6')}
                     checked={state.frontPermission.includes('editBa6')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     编辑信息
                   </Checkbox>
                 </div>
@@ -333,13 +333,13 @@ const SetPermission = ({ ID, roleType = 'system' }) => {
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'accessBa7')}
                     checked={state.frontPermission.includes('accessBa7')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     查看信息
                   </Checkbox>
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'editBa7')}
                     checked={state.frontPermission.includes('editBa7')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     编辑信息
                   </Checkbox>
                 </div>
@@ -350,13 +350,13 @@ const SetPermission = ({ ID, roleType = 'system' }) => {
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'accessBa8')}
                     checked={state.frontPermission.includes('accessBa8')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     查看信息
                   </Checkbox>
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'editBa8')}
                     checked={state.frontPermission.includes('editBa8')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     编辑信息
                   </Checkbox>
                 </div>
@@ -371,13 +371,13 @@ const SetPermission = ({ ID, roleType = 'system' }) => {
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'accessBa9')}
                     checked={state.frontPermission.includes('accessBa9')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     查看信息
                   </Checkbox>
                   <Checkbox
                     onChange={e => handleBackOnchange(e.target.checked, 'editBa9')}
                     checked={state.frontPermission.includes('editBa9')}
-                    disabled={roleType !== 'system' ? false : true}>
+                    disabled={true}>
                     编辑信息
                   </Checkbox>
                 </div>

+ 21 - 1
src/pages/Permission/Role/index.tsx

@@ -1,4 +1,5 @@
 import {
+  fetchRoleListByMenu,
   // fetchRoleListByMenu,
   fetchRoleListByRoleId,
   UnLinkRoleAccountItem
@@ -21,6 +22,7 @@ const Role = () => {
     roleStaff: [],
     activeKey: ''
   })
+  const [menuRoles, setMenuRoles] = useState<API.MenuRoleItem[]>([])
   const { run: tryGetRoleStaffList } = useRequest(
     (roleID: string) => fetchRoleListByRoleId({ roleID }),
     {
@@ -46,6 +48,20 @@ const Role = () => {
     tryGetRoleStaffList(currentRoleID)
   }
 
+  const { run: tryFetchRoleListByMenu } = useRequest(() => fetchRoleListByMenu(), {
+    manual: true,
+    onSuccess: result => {
+      setMenuRoles(
+        result.map(item => ({
+          key: item.ID,
+          title: item.name,
+          roleType: item.roleType
+        }))
+      )
+      result?.length && onSelect?.(result[0]?.ID)
+    }
+  })
+
   const columns: ColumnsType<API.MenuByRoleIdItem> = [
     {
       title: '账号',
@@ -83,7 +99,11 @@ const Role = () => {
   return (
     <PageContainer title={false}>
       <div className="h-full w-full flex flex-row">
-        <RoleLeftMenu onSelect={onSelect} />
+        <RoleLeftMenu
+          onSelect={onSelect}
+          menuRoles={menuRoles}
+          onReloadStaff={() => tryFetchRoleListByMenu()}
+        />
         <div className="w-6/7 ml-8 bg-white p-4 rounded-20px relative">
           <div className="absolute right-4 top-4 z-100">
             {state.currentRoleID && (