Commit cf20c7b5 authored by 张烨's avatar 张烨

fix: 回显

parent edd403c8
...@@ -35,7 +35,7 @@ const ListCardItem = props => { ...@@ -35,7 +35,7 @@ const ListCardItem = props => {
// id // id
const id = getId(rest); const id = getId(rest);
// 当前checkbox为分组时有用,是否部分选中 // 当前checkbox为分组时有用,是否部分选中
const [indeterminate, setIndeterminate] = useState(false); const [indeterminate, setIndeterminate] = useState(true);
// 用来收集子节点的值 // 用来收集子节点的值
const [childValues, setChildValues] = useState({}); const [childValues, setChildValues] = useState({});
...@@ -72,14 +72,24 @@ const ListCardItem = props => { ...@@ -72,14 +72,24 @@ const ListCardItem = props => {
// 勾选事件处理 // 勾选事件处理
const handleChecked = e => { const handleChecked = e => {
const { checked: v } = e.target; const { checked: v } = e.target;
setChecked(v); if (isGroup) {
setIndeterminate(false); if (indeterminate) {
setChecked(true);
} else {
setChecked(v);
}
setIndeterminate(false);
} else {
setChecked(v);
}
// setIndeterminate(false);
if (!isCurrentGroup) { if (!isCurrentGroup) {
getValueCallback(v ? [id] : [], itemid); getValueCallback(v ? [id] : [], itemid);
} }
}; };
const handleChildValueCallback = (arr, childIndex) => { const handleChildValueCallback = (arr, childIndex) => {
const isInitFlag = !!childValues[childIndex];
// 进这里的都是分组,组长统计并处理自己的状态: 全选,部分选,零选 // 进这里的都是分组,组长统计并处理自己的状态: 全选,部分选,零选
// 拿到所有勾选的子节点 // 拿到所有勾选的子节点
childValues[childIndex] = arr; childValues[childIndex] = arr;
...@@ -99,7 +109,7 @@ const ListCardItem = props => { ...@@ -99,7 +109,7 @@ const ListCardItem = props => {
'some', 'some',
); );
setIndeterminate(!isAllchecked && isSomeChecked); setIndeterminate(!isAllchecked && isSomeChecked);
setChecked(isAllchecked); setChecked(isSomeChecked);
// eslint-disable-next-line no-unused-expressions // eslint-disable-next-line no-unused-expressions
getValueCallback && getValueCallback([...childValArr, id], itemid); getValueCallback && getValueCallback([...childValArr, id], itemid);
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment