Compare commits

...

2 Commits

  1. 7
      api/app/lib/controllers/roleResource/index.js
  2. 114
      web/client/src/sections/humanAffairs/containers/employeeAuth.jsx

7
api/app/lib/controllers/roleResource/index.js

@ -8,7 +8,12 @@ async function get(ctx) {
const { id } = ctx.request.query
let roleResourceList = await models.RoleResource.findAndCountAll({
order: [['id', 'desc']],
where: { roleId: id }
where: { roleId: id },
include: [{
model: models.Role,
attributes: ['id', 'dataRange'],
}],
distinct: true
});
ctx.status = 200
ctx.body = roleResourceList;

114
web/client/src/sections/humanAffairs/containers/employeeAuth.jsx

@ -145,20 +145,46 @@ const EmployeeAuth = (props) => {
return { two, checkedList };
}
const onChangeAll = (value) => {
// if (value.target.checked) {
// setAllChecked(true);
// let values = getValues();
// if (!Alltwo)
// Alltwo = values.two;
// if (!AllCheckedList)
// AllCheckedList = values.checkedList;
// setTwo(values.two);
// setCheckedList(values.checkedList);
// } else {
// setAllChecked(false);
// setTwo({})
// setCheckedList([]);
// }
if (value.target.checked) {
setAllChecked(true);
let values = getValues();
if (!Alltwo)
Alltwo = values.two;
if (!AllCheckedList)
AllCheckedList = values.checkedList;
setTwo(values.two);
setCheckedList(values.checkedList);
} else {
setAllChecked(false);
setTwo({})
setCheckedList([]);
}
}
const getResourceIdAll = () => {
let resourceIdAll = [];
if (!Alltwo) {
const values = getValues();
resourceIdAll = Object.keys(values.two);
resourceIdAll = [...values.checkedList, ...resourceIdAll];
resourceIdAll = resourceIdAll.sort((a, b) => (a - b));
} else {
resourceIdAll = [...AllCheckedList, ...Alltwo];
resourceIdAll = resourceIdAll.sort((a, b) => (a - b));
}
return resourceIdAll;
}
const getResourceIds = (two, checkedList) => {
let resourceIds = [];
for (let item in two) {
if (two[item]) {
resourceIds.push(parseInt(item));
}
}
resourceIds = [...(new Set([...checkedList, ...resourceIds]))];
resourceIds = resourceIds.sort((a, b) => (a - b));
return resourceIds;
}
const onChangeOne = (value, recod) => {
let twos = two
@ -179,7 +205,15 @@ const EmployeeAuth = (props) => {
twos[value.target.value] = true
setTwo(twos)
setCheckedList([...checkedList, ...selList])
const resourceIdAll = getResourceIdAll();
const resourceIds = getResourceIds(twos, [...checkedList, ...selList])
if (resourceIds.toString() === resourceIdAll.toString()) {
setAllChecked(true);
} else {
setAllChecked(false);
}
} else {
setAllChecked(false);
twos[value.target.value] = false
setCheckedList(getDiffer(checkedList, selList));
setTwo(twos)
@ -202,7 +236,15 @@ const EmployeeAuth = (props) => {
twos[value.target.value] = true
twos[recod.id] = true
setTwo(two)
const resourceIdAll = getResourceIdAll();
const resourceIds = getResourceIds(two, [...checkedList, ...selList])
if (resourceIds.toString() === resourceIdAll.toString()) {
setAllChecked(true);
} else {
setAllChecked(false);
}
} else {
setAllChecked(false);
setCheckedList(getDiffer(checkedList, selList));
twos[value.target.value] = false
setTwo(two)
@ -222,7 +264,15 @@ const EmployeeAuth = (props) => {
twos[twosid] = true
twos[recod.id] = true
setTwo(twos)
const resourceIdAll = getResourceIdAll();
const resourceIds = getResourceIds(twos, [...checkedList, ...check])
if (resourceIds.toString() === resourceIdAll.toString()) {
setAllChecked(true);
} else {
setAllChecked(false);
}
} else {
setAllChecked(false);
setCheckedList(getDiffer(checkedList, check));
}
}
@ -245,6 +295,10 @@ const EmployeeAuth = (props) => {
dispatch(actions.humanAffairs.delRole(data)).then(e => {
if (e.success) {
getRoleList()
setAllChecked(false);
setTwo({})
setCheckedList([]);
setDataRange(1);
}
})
}
@ -265,28 +319,18 @@ const EmployeeAuth = (props) => {
two[e.resId] = true
return e.resId
})
// let resourceIdAll = [];
// if (!Alltwo) {
// const values = getValues();
// resourceIdAll = Object.values(values.two);
// resourceIdAll = [...values.checkedList, ...resourceIdAll];
// resourceIdAll.sort();
// } else {
// resourceIdAll = [...AllCheckedList, ...Alltwo];
// resourceIdAll.sort();
// }
// let resourceIds = []
setDataRange(res.payload.data.rows[0].role.dataRange || 1);
setCheckedList(checkList)
setTwo(two)
// resourceIdAll = [...checkList, ...two];
// resourceIds.sort();
// if (resourceIds.toString() === resourceIdAll.toString()) {
// setAllChecked(true);
// } else {
// setAllChecked(false);
// }
const resourceIdAll = getResourceIdAll();
const resourceIds = getResourceIds(two, checkList);
if (resourceIds.toString() === resourceIdAll.toString()) {
setAllChecked(true);
} else {
setAllChecked(false);
}
} else {
// setAllChecked(false);
setAllChecked(false);
setCheckedList([])
setTwo(two)
}
@ -300,10 +344,12 @@ const EmployeeAuth = (props) => {
resourceId.push(parseInt(item));
}
}
resourceId = [...resourceId]
resourceId = [...checkedList, ...resourceId]
if (roleId == undefined || resourceId.length == 0) {
Toast.error('请选择角色和权限!')
} else {
resourceId = [...(new Set(resourceId))];
resourceId = resourceId.sort((a, b) => (a - b));
dispatch(actions.humanAffairs.addRoleResource({ roleId, resourceId, dataRange }))
}
}

Loading…
Cancel
Save