diff --git a/web/client/src/sections/humanAffairs/containers/employeeAuth.jsx b/web/client/src/sections/humanAffairs/containers/employeeAuth.jsx index e387d27..2e42ad0 100644 --- a/web/client/src/sections/humanAffairs/containers/employeeAuth.jsx +++ b/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)); } } @@ -265,28 +315,17 @@ 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 = [] 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 +339,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 })) } }