Commit 7b1a217c authored by Maofei94's avatar Maofei94

Merge branch 'master' of g.civnet.cn:test/maintenance

parents a1fd5035 fb53a2a2
......@@ -5,7 +5,14 @@ import styles from './itemCard.less';
import { checkChildrenByCondition, checkIsGroup, getId } from '.';
const ListCardItem = props => {
const { searchWord, item, valueList, updateValueList, ouid } = props;
const {
searchWord,
item,
valueList,
updateValueList,
ouid,
changedItem,
} = props;
// id
const id = getId(item);
......@@ -18,21 +25,50 @@ const ListCardItem = props => {
const [childrenKeys, setChildrenKeys] = useState([]);
useEffect(() => {
if (isGroup) {
const keys = checkChildrenByCondition(item, c => getId(c), 'map').flat();
const keys = item.children
.map(child => checkChildrenByCondition(child, c => getId(c), 'map'))
.flat(Infinity);
setChildrenKeys(keys);
} else {
//
}
}, [item]);
useEffect(() => {
// 子节点勾选状态变化时
if (
isGroup &&
changedItem.item !== item &&
!checkIsGroup(changedItem.item) &&
childrenKeys.includes(getId(changedItem.item))
) {
if (changedItem.value && childrenKeys.every(c => valueList.includes(c))) {
// 全选
updateValueList([id], [id]);
setIndeterminate(false);
} else if (childrenKeys.some(c => valueList.includes(c))) {
// 半选
// eslint-disable-next-line no-unused-expressions
valueList.includes(id) && updateValueList([], [id]);
setIndeterminate(true);
} else {
// 零选
// eslint-disable-next-line no-unused-expressions
valueList.includes(id) && updateValueList([], [id]);
setIndeterminate(false);
}
}
}, [changedItem.item, changedItem.value]);
// 勾选事件处理
const handleChecked = e => {
const { checked: v } = e.target;
if (isGroup) {
const result = [...childrenKeys, id];
updateValueList(v ? result : [], result);
updateValueList(v ? result : [], result, { item, value: v });
setIndeterminate(false);
} else {
updateValueList(v ? [id] : [], [id]);
updateValueList(v ? [id] : [], [id], { item, value: v });
}
};
......@@ -41,11 +77,11 @@ const ListCardItem = props => {
item.children.map((c, i) => (
<ListCardItem
item={c}
itemid={i}
key={`item${i}key`}
updateValueList={updateValueList}
valueList={valueList}
ouid={ouid}
changedItem={changedItem}
searchWord={searchWord}
/>
));
......
......@@ -14,7 +14,10 @@ export const checkChildrenByCondition = (item, fn, tag = 'every') => {
if (!checkIsGroup(item)) {
return fn(item);
}
return item.children[tag](t => checkChildrenByCondition(t, fn, tag));
return [
getId(item),
...item.children[tag](t => checkChildrenByCondition(t, fn, tag)),
];
};
const ListCard = props => {
......@@ -30,22 +33,24 @@ const ListCard = props => {
loading,
} = props;
const [valueList, setValueList] = useState([]);
const [changedItem, setChangedItem] = useState({ item: {} });
useEffect(() => {
setValueList(checkList);
}, [dataList, loading]);
const updateValueList = (checkedKeys, childrenKeys) => {
const updateValueList = (checkedKeys, childrenKeys, sourceItem) => {
// eslint-disable-next-line no-console
console.time('updateValueList:');
// console.time('updateValueList:');
const removekeys = _.difference(childrenKeys, checkedKeys);
let result = _.uniq(_.union(checkedKeys, valueList));
_.remove(result, v => removekeys.includes(v));
setValueList(result);
if (sourceItem) setChangedItem(sourceItem);
// eslint-disable-next-line no-unused-expressions
onChange && onChange(result);
// eslint-disable-next-line no-console
console.timeEnd('updateValueList:');
// console.timeEnd('updateValueList:');
};
return (
......@@ -72,6 +77,7 @@ const ListCard = props => {
<ListCardItem
item={item}
ouid={ouid}
changedItem={changedItem}
updateValueList={updateValueList}
valueList={valueList}
key={`item${index}key`}
......
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