数据获取

权限数据查询及初始化。

  1. *fetchCurrent(_, { call, put }) {
  2. const response = yield call(queryCurrent);
  3. // console.log('------------用户信息-------------')
  4. // console.log(response)
  5. yield put({
  6. type: 'saveCurrentUser',
  7. payload: response,
  8. });
  9. },
  10. saveCurrentUser(state, action) {
  11. let data = action.payload.data;
  12. //保存权限
  13. const permissions = data.role.permissions;
  14. setAuthority( permissions.map((item:any)=>item.id));
  15. // setAuthority(["b845d68a12f34dab88236bd45c8e3f90"])
  16. const permissionButtonList = data.authList.map((authData:any) => { return authData.parent_permission + ':' + authData.permission });
  17. data.authButton = permissionButtonList;
  18. return {
  19. ...state,
  20. currentUser: data || {},
  21. };
  22. },

image.png

功能权限控制

  1. style={{ display: currentUser?.authButton.includes('mycontent:del') ? 'block' : 'none' }}
  2. <Button type="primary" size='small' danger
  3. style={{ display: currentUser?.authButton.includes('mycontent:del') ? 'block' : 'none' }}
  4. onClick={async () => {
  5. Modal.confirm({
  6. title: '删除任务',
  7. content: '确定删除该任务吗?',
  8. okText: '确认',
  9. cancelText: '取消',
  10. onOk: () => {
  11. const success = handleRemoveOne(record);
  12. if (success) {
  13. if (actionRef.current) {
  14. actionRef.current.reload();
  15. }
  16. }
  17. },
  18. });
  19. }}>
  20. 删除
  21. </Button>,