diff --git a/web/client/src/sections/quanju/containers/footer/operation/left.js b/web/client/src/sections/quanju/containers/footer/operation/left.js index 92e69c9a..7e7e9f81 100644 --- a/web/client/src/sections/quanju/containers/footer/operation/left.js +++ b/web/client/src/sections/quanju/containers/footer/operation/left.js @@ -10,6 +10,7 @@ const Left = (props) => { const [treeData, setTreeData] = useState([]) const [treeDataList, setTreeDataList] = useState([]) const [expandedKeys, setExpandedKeys] = useState([]); + const [searchValue, setSearchValue] = useState(''); const [autoExpandParent, setAutoExpandParent] = useState(true); const onExpand = (newExpandedKeys) => { @@ -20,6 +21,7 @@ const Left = (props) => { useEffect(() => { const { dispatch } = props dispatch(getBusTierList()) + }, []) const { busTier } = props const style = { height: "97%", marginTop: "3%" } @@ -35,10 +37,45 @@ const Left = (props) => { setSearchValue(value); setAutoExpandParent(true); }; + const loop = (treeData) => + treeData.map((item) => { + const index = item.title.indexOf(searchValue); + const beforeStr = item.title.substr(0, index); + const afterStr = item.title.substr(index + searchValue.length); + const title = + index > -1 ? ( + + {beforeStr} + {searchValue} + {afterStr} + + ) : ( + {item.title} + ); + if (item.children && item.children.length > 0) { + const children = loop(item.children); + return { + ...item, + title: index > -1 || children.length ? title : null, + children: children.length ? children : undefined + }; + } + return index > -1 + ? { + ...item, + title + } + : { + ...item, + title: null + }; + }) + .filter((item) => !!item.title); useEffect(() => { let busTierList = [] let busTierOpen = [] let dataList = [] + busTier && busTier.data && busTier.data.forEach((e, index) => { if (index == 0) { busTierOpen.push(e.name) @@ -115,8 +152,8 @@ const Left = (props) => { onExpand={onExpand} expandedKeys={expandedKeys} autoExpandParent={autoExpandParent} - treeData={treeData} - /> :
暂无数据
+ treeData={loop(treeData)} + /> :
暂无数据
}