|
|
@ -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 ? ( |
|
|
|
<span> |
|
|
|
{beforeStr} |
|
|
|
<span className="site-tree-search-value">{searchValue}</span> |
|
|
|
{afterStr} |
|
|
|
</span> |
|
|
|
) : ( |
|
|
|
<span>{item.title}</span> |
|
|
|
); |
|
|
|
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} |
|
|
|
/> : <div style={{width:'100%',color:'#fff',textAlign:'center',marginTop:'90%'}}>暂无数据</div> |
|
|
|
treeData={loop(treeData)} |
|
|
|
/> : <div style={{ width: '100%', color: '#fff', textAlign: 'center', marginTop: '90%' }}>暂无数据</div> |
|
|
|
} |
|
|
|
|
|
|
|
</div> |
|
|
|