< el- inputv- model= "searchForm.searchTreeValue" @input= "searchTreeData" style= "flex: 1; margin-right: 0.0694rem" placeholder= "请输入要搜索的设备" clearable/ > < imgclass = "refresh-img" src= "com_refresh.png" alt= "refresh" @click= "refreshTree" / >      < el- selectv- model= "searchForm.deviceType" placeholder= "请选择" size= "small" style= "flex: 1" @change= "searchTreeData" > < el- optionv- for = "item in data" : key= "item.value" : label= "item.label" : value= "item.value" / > < / el- select> < el- selectv- model= "searchForm.deviceSource" placeholder= "请选择" size= "small" style= "flex: 1" @change= "searchTreeData" > < el- optionv- for = "item in data" : key= "item.value" : label= "item.label" : value= "item.value" / > < / el- select> 
 < el- tree- v2class = "treev2-t" ref= "treeRef" style= "width: 100%" : height= "treeHeight" : data= "treeData" : filter- method= "filterNode" : default - expanded- keys= "expandedKeys" node- key= "hightlightKey" : expand- on- click- node= "true" : show- checkbox= "true" empty- text= "暂无组织数据" > < / tree> 
const  treeData =  reactive ( [ ] )  
const  treeRef =  ref ( null ) 
const  searchForm =  reactive ( { searchTreeValue:  '' , deviceType:  '' , deviceSource:  '' , deviceTag:  '' , 
} ) 
watch ( searchForm, ( newValue,  oldValue )  =>  { closeDialog ( ) treeRef. value?. filter ( ) } , {  immediate:  true ,  deep:  true  } 
) 
function  filterNode ( value,  data )  { if  ( ( ! value && ! searchForm. deviceType && ! searchForm. deviceSource && ! searchForm. deviceTag)  || data. toiName ==  undefined  || data. mac ==  undefined  || data. channelCode ==  undefined ) return  true return  checkNodeMatch ( data) 
} 
const  checkNodeMatch  =  ( node )  =>  { let  idsArr =  [ ] if  ( node. infos &&  node. infos. length >  0 )  { cliIds =  node. infos. map ( ( item )  =>  item. id) } const  conditions =  [ { value:  searchForm. searchTreeValue, match :  ( )  => node. name?. toLowerCase ( ) . includes ( searchForm. searchTreeValue. toLowerCase ( ) )  } , { value:  searchForm. deviceType, match :  ( )  => ! searchForm. deviceType || node. channelType ==  searchForm. deviceType, } , { value:  searchForm. deviceSource, match :  ( )  => ! searchForm. deviceSource || idsArr. includes ( searchForm. deviceSource) , } , ] return  conditions. every ( ( condition )  =>  ! condition. value ||  condition. match ( ) ) 
} const  treeFilterData =  computed ( ( )  =>  { if  ( ! hasSearchConditions ( ) )  { return  treeData} return  filterTree ( treeData) 
} ) 
const  hasSearchConditions  =  ( )  =>  { return  Object. values ( searchForm) . some ( ( value )  =>  value !==  '' ) 
} 
const  filterTree  =  ( data )  =>  { if  ( ! data)  return  [ ] return  data. reduce ( ( acc,  node )  =>  { const  newNode =  {  ... node } const  isMatch =  checkNodeMatch ( newNode) if  ( node. children?. length)  { const  filteredChildren =  filterTree ( node. children) if  ( filteredChildren. length)  { newNode. children =  filteredChildrenacc. push ( newNode) return  acc} } if  ( isMatch)  { if  ( ! newNode. children?. length)  { delete  newNode. children} acc. push ( newNode) } return  acc} ,  [ ] ) 
} const  searchTreeData =  useDebounce ( handleSearchTreeData,  300 )  
function  handleSearchTreeData ( )  { treeRef. value?. setData ( treeFilterData. value) 
} 
const  refreshTree =  useDebounce ( handleRefreshTree,  300 )  
function  handleRefreshTree ( ) { searchForm. deviceSource =  '' searchForm. deviceTag =  '' searchForm. deviceType =  '' searchForm. searchTreeValue =  '' treeRef. value?. setCheckedKeys ( [ ] ,  false ) 
} 
export  const  useDebounce  =  ( fn,  delay =  300  )  =>  { let  timer =  null return  ( ... args)  =>  { clearTimeout ( timer) timer =  setTimeout ( ( )  =>  { fn ( ... args) } ,  delay) } 
}