|
|
@ -1,89 +1,15 @@ |
|
|
|
import React, { useMemo, useState, useEffect } from 'react'; |
|
|
|
import { SearchOutlined } from '@ant-design/icons'; |
|
|
|
import { Col, Row, Input, Tree } from 'antd' |
|
|
|
import React, { useState, useEffect } from 'react'; |
|
|
|
import { connect } from 'react-redux'; |
|
|
|
import { Input, Tree } from 'antd' |
|
|
|
import Module from '../../public/module' |
|
|
|
import { getBusTierList } from '../../../actions/example' |
|
|
|
import './style.less' |
|
|
|
|
|
|
|
const { Search } = Input; |
|
|
|
const x = 3; |
|
|
|
const y = 2; |
|
|
|
const z = 1; |
|
|
|
const defaultData = []; |
|
|
|
|
|
|
|
const generateData = (_level, _preKey, _tns) => { |
|
|
|
const preKey = _preKey || '0'; |
|
|
|
const tns = _tns || defaultData; |
|
|
|
const children = []; |
|
|
|
|
|
|
|
for (let i = 0; i < x; i++) { |
|
|
|
const key = `${preKey}-${i}`; |
|
|
|
tns.push({ |
|
|
|
title: key, |
|
|
|
key, |
|
|
|
}); |
|
|
|
|
|
|
|
if (i < y) { |
|
|
|
children.push(key); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (_level < 0) { |
|
|
|
return tns; |
|
|
|
} |
|
|
|
|
|
|
|
const level = _level - 1; |
|
|
|
children.forEach((key, index) => { |
|
|
|
tns[index].children = []; |
|
|
|
return generateData(level, key, tns[index].children); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
generateData(z); |
|
|
|
const dataList = []; |
|
|
|
|
|
|
|
const generateList = (data) => { |
|
|
|
for (let i = 0; i < data.length; i++) { |
|
|
|
const node = data[i]; |
|
|
|
const { key } = node; |
|
|
|
dataList.push({ |
|
|
|
key, |
|
|
|
title: key, |
|
|
|
}); |
|
|
|
|
|
|
|
if (node.children) { |
|
|
|
generateList(node.children); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
generateList(defaultData); |
|
|
|
|
|
|
|
const getParentKey = (key, tree) => { |
|
|
|
let parentKey; |
|
|
|
|
|
|
|
for (let i = 0; i < tree.length; i++) { |
|
|
|
const node = tree[i]; |
|
|
|
|
|
|
|
if (node.children) { |
|
|
|
if (node.children.some((item) => item.key === key)) { |
|
|
|
parentKey = node.key; |
|
|
|
} else if (getParentKey(key, node.children)) { |
|
|
|
parentKey = getParentKey(key, node.children); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return parentKey; |
|
|
|
}; |
|
|
|
|
|
|
|
const Left = () => { |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
}, []) |
|
|
|
|
|
|
|
const style = { height: "97%", marginTop: "3%" } |
|
|
|
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) => { |
|
|
@ -91,60 +17,76 @@ const Left = () => { |
|
|
|
setAutoExpandParent(false); |
|
|
|
}; |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
const { dispatch } = props |
|
|
|
dispatch(getBusTierList()) |
|
|
|
}, []) |
|
|
|
const { busTier } = props |
|
|
|
const style = { height: "97%", marginTop: "3%" } |
|
|
|
|
|
|
|
const onChange = (e) => { |
|
|
|
const { value } = e.target; |
|
|
|
const newExpandedKeys = dataList |
|
|
|
.map((item) => { |
|
|
|
if (item.title.indexOf(value) > -1) { |
|
|
|
return getParentKey(item.key, defaultData); |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
}) |
|
|
|
.filter((item, i, self) => item && self.indexOf(item) === i); |
|
|
|
setExpandedKeys(newExpandedKeys); |
|
|
|
let keys = [] |
|
|
|
const newExpandedKeys = treeDataList.filter(e=> e.key.match(value)) |
|
|
|
newExpandedKeys.forEach(e=>{ |
|
|
|
keys.push(e.key) |
|
|
|
}) |
|
|
|
setExpandedKeys(keys); |
|
|
|
setSearchValue(value); |
|
|
|
setAutoExpandParent(true); |
|
|
|
}; |
|
|
|
|
|
|
|
const treeData = useMemo(() => { |
|
|
|
const loop = (data) => |
|
|
|
data.map((item) => { |
|
|
|
const strTitle = item.title; |
|
|
|
const index = strTitle.indexOf(searchValue); |
|
|
|
const beforeStr = strTitle.substring(0, index); |
|
|
|
const afterStr = strTitle.slice(index + searchValue.length); |
|
|
|
const title = |
|
|
|
index > -1 ? ( |
|
|
|
<span> |
|
|
|
{beforeStr} |
|
|
|
<span className="site-tree-search-value">{searchValue}</span> |
|
|
|
{afterStr} |
|
|
|
</span> |
|
|
|
) : ( |
|
|
|
<span>{strTitle}</span> |
|
|
|
); |
|
|
|
|
|
|
|
if (item.children) { |
|
|
|
useEffect(() => { |
|
|
|
let busTierList = [] |
|
|
|
let busTierOpen = [] |
|
|
|
let dataList = [] |
|
|
|
busTier && busTier.data && busTier.data.forEach((e, index) => { |
|
|
|
if (index == 0) { |
|
|
|
busTierOpen.push(e.name) |
|
|
|
} |
|
|
|
busTierList.push({ |
|
|
|
key: e.name, |
|
|
|
title: e.name, |
|
|
|
children: e.child.map(s => { |
|
|
|
return { |
|
|
|
title, |
|
|
|
key: item.key, |
|
|
|
children: loop(item.children), |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
return { |
|
|
|
title, |
|
|
|
key: item.key, |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
return loop(defaultData); |
|
|
|
}, [searchValue]); |
|
|
|
key: s.name, |
|
|
|
title: s.name, |
|
|
|
children: s.child.map(i => { |
|
|
|
return { |
|
|
|
key: i.vehicleLicensePlateNumber, |
|
|
|
title: i.vehicleLicensePlateNumber, |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
busTier && busTier.data && busTier.data.forEach(e => { |
|
|
|
dataList.push({ |
|
|
|
key: e.name, |
|
|
|
title: e.name, |
|
|
|
}) |
|
|
|
e.child.forEach(i=>{ |
|
|
|
dataList.push({ |
|
|
|
key: i.name, |
|
|
|
title: i.name, |
|
|
|
}) |
|
|
|
i.child.forEach(s=>{ |
|
|
|
dataList.push({ |
|
|
|
key: s.vehicleLicensePlateNumber, |
|
|
|
title: s.vehicleLicensePlateNumber, |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
setTreeData(busTierList) |
|
|
|
setExpandedKeys(busTierOpen) |
|
|
|
setTreeDataList(dataList) |
|
|
|
}, [busTier]) |
|
|
|
return ( |
|
|
|
<div style={{ display: 'flex', flexDirection: 'column', width: "23%", height: "100%", marginLeft: "1%" }}> |
|
|
|
<Module style={style} title={"公交车辆信息"}> |
|
|
|
<div style={{ width: '90%', height: '96', margin: '2% 5%', }}> |
|
|
|
<Module style={style} customize={true} title={"公交车辆信息"}> |
|
|
|
<div style={{ width: '90%', height: '96%', margin: '2% 5%', overflow: 'hidden' }}> |
|
|
|
<div style={{ border: '1px solid rgba(10, 114, 255, 1)', backgroundColor: 'rgba(10, 114, 255, 0.1)' }}> |
|
|
|
<img src='assets/images/quanju/search.png' style={{ width: '5%', margin: '0 1.5% 1% 3.5%' }} /> |
|
|
|
<Input |
|
|
@ -160,21 +102,30 @@ const Left = () => { |
|
|
|
onChange={onChange} |
|
|
|
/> |
|
|
|
</div> |
|
|
|
<Tree |
|
|
|
rootStyle={{ |
|
|
|
background: 'none', |
|
|
|
borderColor: 'none', |
|
|
|
color: 'rgba(255, 255, 255, 1)' |
|
|
|
}} |
|
|
|
onExpand={onExpand} |
|
|
|
expandedKeys={expandedKeys} |
|
|
|
autoExpandParent={autoExpandParent} |
|
|
|
treeData={treeData} |
|
|
|
/> |
|
|
|
<div className='busList'> |
|
|
|
<Tree |
|
|
|
rootStyle={{ |
|
|
|
marginTop: '1%', |
|
|
|
background: 'none', |
|
|
|
borderColor: 'none', |
|
|
|
color: 'rgba(255, 255, 255, 1)' |
|
|
|
}} |
|
|
|
onExpand={onExpand} |
|
|
|
expandedKeys={expandedKeys} |
|
|
|
autoExpandParent={autoExpandParent} |
|
|
|
treeData={treeData} |
|
|
|
/> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</Module> |
|
|
|
</div> |
|
|
|
); |
|
|
|
}; |
|
|
|
function mapStateToProps(state) { |
|
|
|
const { busTier } = state |
|
|
|
return { |
|
|
|
busTier: busTier |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export default Left; |
|
|
|
export default connect(mapStateToProps)(Left); |