Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CivManage
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ReactWeb5
CivManage
Commits
7b1a217c
Commit
7b1a217c
authored
Nov 20, 2020
by
Maofei94
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of g.civnet.cn:test/maintenance
parents
a1fd5035
fb53a2a2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
9 deletions
+51
-9
ItemCard.jsx
src/components/CheckGroup/ItemCard.jsx
+41
-5
index.jsx
src/components/CheckGroup/index.jsx
+10
-4
No files found.
src/components/CheckGroup/ItemCard.jsx
View file @
7b1a217c
...
...
@@ -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
}
/>
));
...
...
src/components/CheckGroup/index.jsx
View file @
7b1a217c
...
...
@@ -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`
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment