Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
merchant-manage-ui
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
ui
merchant-manage-ui
Commits
bd35585f
Commit
bd35585f
authored
Nov 04, 2022
by
武广
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 添加key
parent
7d9070cb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
29 deletions
+39
-29
index.jsx
src/components/CustomTree/index.jsx
+35
-25
index.jsx
src/pages/distributionArea/addArea/index.jsx
+4
-4
No files found.
src/components/CustomTree/index.jsx
View file @
bd35585f
...
@@ -252,35 +252,41 @@ const CustomTree = forwardRef(props => {
...
@@ -252,35 +252,41 @@ const CustomTree = forwardRef(props => {
}
}
};
};
const
initTreeData
=
(
arr
=
[],
level
)
=>
// const initTreeData = (arr = [], values = [], level) =>
arr
.
map
(
item
=>
{
// arr.map(item => {
const
json
=
{
// const valueObj = values.find(val => val.key === item.key) || {};
value
:
item
.
value
||
[],
// console.log('valueObj.children :>> ', valueObj.children);
level
,
// const json = {
visibleChildren
:
false
,
// value: valueObj.children || item.value || [],
checked
:
false
,
// level,
indeterminate
:
false
,
// visibleChildren: false,
label
:
item
[
props
.
labelName
||
'
label
'
],
// checked: false,
key
:
item
[
props
.
keyName
||
'
key
'
],
// indeterminate: false,
isLeaf
:
true
,
// label: item[props.labelName || 'label'],
isLoading
:
false
,
// key: item[props.keyName || 'key'],
};
// isLeaf: true,
getIsChecked
(
item
.
key
,
json
);
// isLoading: false,
if
(
item
.
children
)
{
// };
json
.
children
=
initTreeData
(
item
.
children
,
level
+
1
);
// getIsChecked(item.key, json);
}
// if (item.children) {
return
json
;
// json.children = initTreeData(item.children, valueObj.children, level + 1);
});
// }
// return json;
// });
const
initTreeValue
=
(
arr
=
[],
values
=
[],
parentChecked
)
=>
const
initTreeValue
=
(
arr
=
[],
values
=
[],
parentChecked
,
level
=
1
)
=>
arr
.
forEach
(
item
=>
{
arr
.
forEach
(
item
=>
{
const
valueObj
=
values
.
find
(
val
=>
val
.
key
===
item
.
key
)
||
{};
const
valueObj
=
values
.
find
(
val
=>
val
.
key
===
item
.
key
)
||
{};
item
.
checked
=
item
.
checked
=
(
typeof
parentChecked
===
'
boolean
'
&&
parentChecked
)
||
valueObj
.
checked
||
false
;
(
typeof
parentChecked
===
'
boolean
'
&&
parentChecked
)
||
valueObj
.
checked
||
false
;
item
.
indeterminate
=
valueObj
.
indeterminate
||
false
;
item
.
indeterminate
=
valueObj
.
indeterminate
||
false
;
item
.
value
=
valueObj
.
children
||
[];
item
.
value
=
valueObj
.
children
||
[];
item
.
isLeaf
=
typeof
item
.
isLeaf
===
'
boolean
'
?
item
.
isLeaf
:
true
;
item
.
isLoading
=
false
;
item
.
visibleChildren
=
item
.
visibleChildren
||
false
;
item
.
level
=
level
;
if
(
item
.
children
&&
item
.
children
.
length
)
{
if
(
item
.
children
&&
item
.
children
.
length
)
{
initTreeValue
(
item
.
children
,
valueObj
.
children
,
item
.
checked
);
initTreeValue
(
item
.
children
,
valueObj
.
children
,
item
.
checked
,
level
+
1
);
}
}
});
});
...
@@ -291,8 +297,9 @@ const CustomTree = forwardRef(props => {
...
@@ -291,8 +297,9 @@ const CustomTree = forwardRef(props => {
},
[
props
.
value
]);
},
[
props
.
value
]);
useEffect
(()
=>
{
useEffect
(()
=>
{
const
arr
=
initTreeData
(
props
.
treeData
,
1
);
const
datas
=
[...
props
.
treeData
];
setTreeData
(
arr
);
initTreeValue
(
datas
,
props
.
value
);
setTreeData
(
datas
);
},
[
props
.
treeData
]);
},
[
props
.
treeData
]);
// 委托 - 点击别的地方关闭子层
// 委托 - 点击别的地方关闭子层
...
@@ -318,9 +325,12 @@ const CustomTree = forwardRef(props => {
...
@@ -318,9 +325,12 @@ const CustomTree = forwardRef(props => {
treeData=
{
item
}
treeData=
{
item
}
></
CTreeNode
>
></
CTreeNode
>
{
(
item
.
visibleChildren
&&
childrenList
&&
childrenList
.
length
&&
(
{
(
item
.
visibleChildren
&&
childrenList
&&
childrenList
.
length
&&
(
<
div
className=
{
styles
[
'
tree-children-box
'
]
}
>
<
div
className=
{
styles
[
'
tree-children-box
'
]
}
key=
"childrens"
>
{
childrenList
.
map
(
arr
=>
(
{
childrenList
.
map
(
arr
=>
(
<
div
className=
{
styles
[
'
tree-children-wrapper
'
]
}
>
<
div
className=
{
styles
[
'
tree-children-wrapper
'
]
}
key=
{
`children${arr[0].key}`
}
>
{
renderTreeNodes
(
arr
)
||
''
}
{
renderTreeNodes
(
arr
)
||
''
}
</
div
>
</
div
>
))
}
))
}
...
...
src/pages/distributionArea/addArea/index.jsx
View file @
bd35585f
...
@@ -48,22 +48,22 @@ const AddAreaModal = props => {
...
@@ -48,22 +48,22 @@ const AddAreaModal = props => {
const
handleOk
=
()
=>
{
const
handleOk
=
()
=>
{
validateFields
(
async
(
error
,
fieldsValue
)
=>
{
validateFields
(
async
(
error
,
fieldsValue
)
=>
{
const
newData
=
[];
const
newData
=
[];
const
getValues
=
list
=>
{
const
getValues
=
(
list
,
level
)
=>
{
list
.
forEach
(
itemData
=>
{
list
.
forEach
(
itemData
=>
{
if
(
itemData
.
checked
)
{
if
(
itemData
.
checked
)
{
newData
.
push
({
newData
.
push
({
addressId
:
itemData
.
key
,
addressId
:
itemData
.
key
,
addressLevel
:
itemData
.
level
,
addressLevel
:
itemData
.
level
||
level
,
addressName
:
itemData
.
label
,
addressName
:
itemData
.
label
,
});
});
}
else
if
(
itemData
.
children
&&
itemData
.
children
.
length
)
{
}
else
if
(
itemData
.
children
&&
itemData
.
children
.
length
)
{
getValues
(
itemData
.
children
);
getValues
(
itemData
.
children
,
level
+
1
);
}
}
});
});
};
};
if
(
!
error
)
{
if
(
!
error
)
{
console
.
log
(
'
fieldsValue :>>
'
,
fieldsValue
);
console
.
log
(
'
fieldsValue :>>
'
,
fieldsValue
);
getValues
(
fieldsValue
.
list
);
getValues
(
fieldsValue
.
list
,
1
);
if
(
props
.
templateData
.
status
)
{
if
(
props
.
templateData
.
status
)
{
const
data
=
await
forbiddenAddress
({
const
data
=
await
forbiddenAddress
({
templateId
:
props
.
templateData
.
id
,
templateId
:
props
.
templateData
.
id
,
...
...
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