| | |
| | | const { setFilters } = useListContext(); // 获取列表上下文 |
| | | const [selectedOption, setSelectedOption] = useState(null); |
| | | const [treeData, setTreeData] = useState([]); |
| | | const trees = [] |
| | | const haveChildren = (item) => { |
| | | // 如果 item 是一个数组,遍历数组中的每个元素 |
| | | if (Array.isArray(item)) { |
| | | return item.map((k) => haveChildren(k)); |
| | | } |
| | | |
| | | // 如果 item 是一个对象 |
| | | if (item && typeof item === 'object') { |
| | | // 将 id 转换为字符串 |
| | | if (item.id !== undefined) { |
| | | item.id = item.id.toString(); |
| | | } |
| | | |
| | | // 如果存在 children,递归处理 children |
| | | if (item.children && Array.isArray(item.children)) { |
| | | item.children = haveChildren(item.children); |
| | | } |
| | | } |
| | | |
| | | return item; |
| | | }; |
| | | useEffect(() => { |
| | | request.post('/matnrGroup/tree') |
| | | .then(res => { |
| | | console.log('Tree Data:', res); |
| | | if (res?.data?.code === 200) { |
| | | setTreeData(res.data.data); |
| | | let data = res.data.data; |
| | | let items = haveChildren(data) |
| | | setTreeData(items) |
| | | } else { |
| | | notify(res.data.msg); |
| | | } |
| | |
| | | .catch(error => { |
| | | notify('Error fetching tree data'); |
| | | }); |
| | | |
| | | |
| | | |
| | | },[]); |
| | | |
| | | |
| | | |
| | | }, []); |
| | | |
| | | |
| | | |
| | |
| | | // 在这里可以根据 nodeId 更新主内容区域 |
| | | }; |
| | | const handleSearch = () => { |
| | | console.log('Search Input:', selectedOption); |
| | | console.log('Search Input:', selectedOption); |
| | | }; |
| | | |
| | | |
| | |
| | | > |
| | | <CardContent> |
| | | <SavedQueriesList icon={<BookmarkIcon />} /> |
| | | <FilterLiveSearch source="condition" /> |
| | | <FilterLiveSearch source="condition" /> |
| | | <RichTreeView |
| | | defaultExpandedItems={['grid', 'pickers']} |
| | | expansionTrigger="iconContainer" |
| | | items={ treeData } |
| | | slots={ CustomTreeItem } |
| | | items={treeData} |
| | | slots={CustomTreeItem} |
| | | onItemClick={handleNodeSelect} // 监听节点点击事件 |
| | | |
| | | /> |