Commit a82438ab authored by 皮倩雯's avatar 皮倩雯

fix: '修复树组件无法展开问题'

parent d24c26b7
Pipeline #74003 passed with stages
......@@ -18,6 +18,7 @@ const TreeSelect = (props, ref) => {
const [visible, setVisible] = useState(false);
const [expandedKeys, setExpandedKeys] = useState([]);
const { TreeNode } = TreeSelect;
const [keepKey, setKeepKey] = useState([]);
useEffect(() => {
getMenu();
}, []);
......@@ -50,7 +51,8 @@ const TreeSelect = (props, ref) => {
setMenuWebList(str);
setWebList(str.children);
let aa = getKey(str.children);
setExpandedKeys(aa[0]);
setKeepKey(aa);
setExpandedKeys([...aa]);
} else {
notification.error({
message: '提示',
......@@ -69,7 +71,7 @@ const TreeSelect = (props, ref) => {
val = '';
}
if (val !== '') {
let newTree = menuWebList.children.map(item => mapTree1(item, val));
let newTree = menuWebList.children.map(item => mapTree(item, val));
let filter = filterTree(newTree);
let newData = filterTreeParent(filter);
let arr = [];
......@@ -80,33 +82,28 @@ const TreeSelect = (props, ref) => {
});
setWebList(arr);
let aa = getKey(arr);
setExpandedKeys(aa[0]);
setExpandedKeys([...aa]);
} else {
setWebList(menuWebList.children);
let aa = getKey(menuWebList.children);
setExpandedKeys(aa[0]);
setExpandedKeys([...keepKey]);
}
};
const getKey = (users, allKeys = []) => {
users.forEach(v => {
let name = v.menuID || v.key;
name && allKeys.push(name);
if (Array.isArray(v.children)) {
v.children.forEach(s => {
let str = s.menuID || s.key;
allKeys.push(str);
});
if (v.children.length > 0) {
name && allKeys.push(name);
}
if (Array.isArray(v.children)) {
if (v.children.length > 0) {
return getKey(v.children, allKeys);
}
});
return [allKeys];
return allKeys;
};
const mapTree1 = (val, word) => {
const mapTree = (val, word) => {
const obj = { ...val };
const hasChild = obj.children.length > 0;
let status = '';
......@@ -125,7 +122,7 @@ const TreeSelect = (props, ref) => {
pageUrl: obj.pageUrl,
product: obj.product,
show: status,
children: hasChild ? obj.children.map(i => mapTree1(i, word)) : [],
children: hasChild ? obj.children.map(i => mapTree(i, word)) : [],
};
};
......@@ -204,7 +201,7 @@ const TreeSelect = (props, ref) => {
expandedKeys={expandedKeys}
autoExpandParent
onSelect={onSelect}
treeData={webList.map(val => mapTree1(val))}
treeData={webList && webList.map(val => mapTree(val))}
style={{ width: '100%' }}
/>
{Object.keys(webList).length === 0 ? <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} /> : null}
......
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