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