新增功能:搜索后定位滑动到 指定节点位置

新增功能:搜索后定位滑动到 指定节点位置
This commit is contained in:
TimSpan 2024-08-02 14:50:06 +08:00
parent fb2a21fffd
commit 01097b26d9
1 changed files with 26 additions and 2 deletions

View File

@ -30,7 +30,7 @@
</el-form-item>
</div>
<!-- <button @click="refreshTreeData">刷新</button> -->
<div v-loading="loading" style="padding: 0px 20px; height: 75%; overflow: auto">
<div ref="scrollContainer" v-loading="loading" style="padding: 0px 20px; height: 75%; overflow: auto">
<!-- <div v-loading="loading"> -->
<!-- :load-data="onLoadData" -->
<!-- height="500" -->
@ -559,6 +559,28 @@ const fieldNames: TreeProps['fieldNames'] = {
}
const loading = ref(false)
//
const scrollContainer = ref()
//
const scrollToMatchedNode = (searchValue: string) => {
nextTick(() => {
try {
// console.log(treeRef.value) //proxy
const treeEl = scrollContainer.value.querySelector('.ant-tree')
const titleElements = treeEl.querySelectorAll('.ant-tree-title')
let matchedNode = null
titleElements.forEach((element: any) => {
if (element.textContent.trim() === searchValue) {
matchedNode = element
}
})
console.log('matchedNode_________', matchedNode)
if (matchedNode) {
//
;(matchedNode as HTMLElement).scrollIntoView({ behavior: 'smooth', block: 'center' })
}
} catch (error) {}
})
}
const treedataall = ref([])
const searchValue = ref('') //
const treeRef = ref() // ref a-tree
@ -628,7 +650,9 @@ const onSearch = () => {
selectedKeys.value = keysToSelect
if (selectedKeys.value.length > 0) {
console.log('selectedKeys.value', selectedKeys.value)
scrollToKey(selectedKeys.value[0])
scrollToMatchedNode(searchValue.value)
// scrollToKey(selectedKeys.value[0])
}
}
const refreshTreeData = () => {