|
@@ -1,5 +1,5 @@
|
|
/** 自定义hooks库 */
|
|
/** 自定义hooks库 */
|
|
-import { useState } from 'react'
|
|
|
|
|
|
+import { useState, useEffect } from 'react'
|
|
import { ContractTree } from '@/types/contract'
|
|
import { ContractTree } from '@/types/contract'
|
|
import { ListModal } from '@/types/safe'
|
|
import { ListModal } from '@/types/safe'
|
|
|
|
|
|
@@ -43,6 +43,12 @@ export const useContractTree = (): [ContractTree, (newTree: ContractTree) => voi
|
|
/** 树列表展开收起自定义hook */
|
|
/** 树列表展开收起自定义hook */
|
|
export const useTableExpand = (tree: ContractTree): [string[], (expanded: boolean, record?: ContractTree) => void] => {
|
|
export const useTableExpand = (tree: ContractTree): [string[], (expanded: boolean, record?: ContractTree) => void] => {
|
|
const [ ids, setIds ] = useState<Array<string>>([])
|
|
const [ ids, setIds ] = useState<Array<string>>([])
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ const newIds = expandTree(tree.children as ContractTree[])
|
|
|
|
+ console.log(newIds)
|
|
|
|
+
|
|
|
|
+ setIds(newIds)
|
|
|
|
+ }, [ tree ])
|
|
const onChange = (expanded: boolean, record?: ContractTree) => {
|
|
const onChange = (expanded: boolean, record?: ContractTree) => {
|
|
// 点击图标的展开收起
|
|
// 点击图标的展开收起
|
|
if (record) {
|
|
if (record) {
|
|
@@ -64,12 +70,13 @@ export const useTableExpand = (tree: ContractTree): [string[], (expanded: boolea
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function expandTree(data: ContractTree[]): string[] {
|
|
function expandTree(data: ContractTree[]): string[] {
|
|
- const idArr: Array<string> = []
|
|
|
|
|
|
+ let idArr: Array<string> = []
|
|
|
|
|
|
data.forEach((item: ContractTree) => {
|
|
data.forEach((item: ContractTree) => {
|
|
- if (item.isfolder && item.children?.length) {
|
|
|
|
|
|
+ if (!!item.isfolder && item.children?.length) {
|
|
idArr.push(item.id)
|
|
idArr.push(item.id)
|
|
- idArr.concat(expandTree(item.children))
|
|
|
|
|
|
+ const childIds = expandTree(item.children)
|
|
|
|
+ idArr = [ ...idArr, ...childIds ]
|
|
}
|
|
}
|
|
})
|
|
})
|
|
return idArr
|
|
return idArr
|