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
04d7ab35
Commit
04d7ab35
authored
Nov 17, 2020
by
张烨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 选择数据回显
parent
bb3e1de2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
20 deletions
+20
-20
ItemCard.jsx
src/components/CheckGroup/ItemCard.jsx
+19
-19
index.jsx
src/components/CheckGroup/index.jsx
+1
-1
No files found.
src/components/CheckGroup/ItemCard.jsx
View file @
04d7ab35
...
...
@@ -9,10 +9,10 @@ const CheckGroup = Checkbox.Group;
const
getId
=
item
=>
item
.
userID
||
item
.
roleID
||
item
.
stationID
||
item
.
id
;
const
i
sGroup
=
node
=>
[
'widgetGroup'
].
includes
(
node
?.
type
||
node
);
const
checkI
sGroup
=
node
=>
[
'widgetGroup'
].
includes
(
node
?.
type
||
node
);
const
checkChildrenByCondition
=
(
item
,
fn
,
tag
=
'every'
)
=>
{
if
(
!
i
sGroup
(
item
))
{
if
(
!
checkI
sGroup
(
item
))
{
return
fn
(
item
);
}
return
item
.
children
[
tag
](
t
=>
checkChildrenByCondition
(
t
,
fn
,
tag
));
...
...
@@ -43,27 +43,29 @@ const ListCardItem = props => {
const
isMapWedgt
=
type
===
'widgetUIPage'
;
// 当前组件是否是分组id
const
isCurrentGroup
=
isGroup
(
type
);
const
isGroup
=
checkIsGroup
(
type
);
const
[
groupChecked
,
setGroupChecked
]
=
useState
(
false
);
// 当前组件是否勾选
const
[
checked
,
setChecked
]
=
useState
(
isChecked
);
useEffect
(()
=>
{
// const all = children.every(u => checkAllChildrenChecked(u));
if
(
is
Current
Group
)
{
if
(
isGroup
)
{
// setIndeterminate(!all && children.some(u => checkSomeChildrenChecked(u)));
}
else
{
setIndeterminate
(
false
);
// 初始进来报告自己的值
getValueCallback
(
isChecked
?
[
id
]
:
[],
itemid
);
setIndeterminate
(
false
);
}
},
[]);
// 监听父级是否勾选,如果父级勾选 则需要吧自己设置勾选状态并回传值
useEffect
(()
=>
{
if
(
allChecked
!==
checked
&&
!
groupIndeterminate
)
{
if
(
!
isGroup
)
{
setChecked
(
allChecked
);
if
(
!
isCurrentGroup
)
{
setIndeterminate
(
false
);
getValueCallback
(
allChecked
?
[
id
]
:
[],
itemid
);
}
}
...
...
@@ -74,25 +76,23 @@ const ListCardItem = props => {
const
{
checked
:
v
}
=
e
.
target
;
if
(
isGroup
)
{
if
(
indeterminate
)
{
setChecked
(
true
);
set
Group
Checked
(
true
);
}
else
{
setChecked
(
v
);
set
Group
Checked
(
v
);
}
setIndeterminate
(
false
);
}
else
{
setChecked
(
v
);
}
// setIndeterminate(false);
if
(
!
isCurrentGroup
)
{
if
(
!
isGroup
)
{
getValueCallback
(
v
?
[
id
]
:
[],
itemid
);
}
};
const
handleChildValueCallback
=
(
arr
,
childIndex
)
=>
{
const
isInitFlag
=
!!
childValues
[
childIndex
];
// 进这里的都是分组,组长统计并处理自己的状态: 全选,部分选,零选
// 拿到所有勾选的子节点
childValues
[
childIndex
]
=
arr
;
childValues
[
childIndex
]
=
arr
.
flat
()
;
const
childValArr
=
Object
.
values
(
childValues
).
flat
();
// 保存组员状态
setChildValues
({
...
childValues
});
...
...
@@ -109,7 +109,7 @@ const ListCardItem = props => {
'some'
,
);
setIndeterminate
(
!
isAllchecked
&&
isSomeChecked
);
setChecked
(
isSomeChecked
);
set
Group
Checked
(
isSomeChecked
);
// eslint-disable-next-line no-unused-expressions
getValueCallback
&&
getValueCallback
([...
childValArr
,
id
],
itemid
);
};
...
...
@@ -120,7 +120,7 @@ const ListCardItem = props => {
<
ListCardItem
{
...
c
}
itemid=
{
i
}
allChecked=
{
c
hecked
}
allChecked=
{
groupC
hecked
}
groupIndeterminate=
{
indeterminate
}
key=
{
`item${i}key`
}
getValueCallback=
{
handleChildValueCallback
}
...
...
@@ -132,14 +132,14 @@ const ListCardItem = props => {
<>
<
div
className=
{
classnames
({
[
styles
.
divBox
]:
is
Current
Group
,
[
styles
.
divSingle
]:
!
is
Current
Group
,
[
styles
.
divBox
]:
isGroup
,
[
styles
.
divSingle
]:
!
isGroup
,
})
}
>
<
div
className=
{
styles
.
topCheckbox
}
>
<
Checkbox
indeterminate=
{
i
ndeterminat
e
}
checked=
{
checked
}
indeterminate=
{
i
sGroup
?
indeterminate
:
fals
e
}
checked=
{
isGroup
?
groupChecked
:
checked
}
onChange=
{
handleChecked
}
>
{
isMapWedgt
?
(
...
...
@@ -152,7 +152,7 @@ const ListCardItem = props => {
)
:
(
<
span
className=
{
classnames
({
[
styles
.
boldLabel
]:
is
Current
Group
,
[
styles
.
boldLabel
]:
isGroup
,
[
styles
.
isSearch
]:
searchWord
&&
text
.
includes
(
searchWord
),
})
}
>
...
...
src/components/CheckGroup/index.jsx
View file @
04d7ab35
...
...
@@ -43,7 +43,6 @@ const ListCard = props => {
_dc
:
new
Date
().
getTime
(),
})
.
then
(
res
=>
{
setLoading
(
false
);
const
list
=
[];
// eslint-disable-next-line no-unused-expressions
res
.
success
&&
...
...
@@ -51,6 +50,7 @@ const ListCard = props => {
list
.
push
({
...
defaultConfig
,
...
item
});
});
setdataList
(
list
);
setLoading
(
false
);
})
.
catch
(
err
=>
{
console
.
error
(
err
);
...
...
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