Skip to content

Commit 42f71f5

Browse files
committedFeb 24, 2024
feat: 切换节点的时候, 将高亮节点调整至可视区域
1 parent 75846b2 commit 42f71f5

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed
 

‎src/components/waterfall/PicDrawer.vue

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22
<div>
3-
<q-drawer v-model="leftDrawerSync" content-class="bg-grey-1" elevated show-if-above :width="drawer_width">
3+
<q-drawer v-model="leftDrawerSync" content-class="bg-grey-1" elevated
4+
show-if-above id="drawer" :width="drawer_width">
45
<div class="q-pa-md q-gutter-sm">
56
<div style="text-align: center">
67
<q-badge :color="badge.color" :text-color="badge.text_color">
@@ -15,7 +16,7 @@
1516
</template>
1617
</q-input>
1718
</div>
18-
<div>
19+
<div id="drawer_tree">
1920
<q-tree ref="qtree" no-transition v-model:expanded="tree.expanded"
2021
:filter="tree.filter" :nodes="tree.nodes"
2122
v-model:selected="tree.selectedNodeSync" node-key="nodeKey" @lazy-load="onLazyLoad"
@@ -164,6 +165,22 @@ export default {
164165
fail([])
165166
})
166167
},
168+
highlightNodeInView: function (nodeKey) {
169+
const scroll = document.querySelector("#drawer")
170+
const allNodes = Array.from(document.querySelectorAll('#drawer_tree .q-tree__node .row')).filter(_ => _.id)
171+
let nodes = allNodes.map(_ => ({id: parseInt(_.id), top: _.offsetTop, height: _.offsetHeight, bottom: _.offsetBlockEnd}))
172+
// 标题和输入框高度
173+
let height = 4 + 21 + 4 + 56 + 4
174+
for (const node of nodes) {
175+
// padding + 每个节点高度
176+
height += node.top + node.height
177+
if (node.id === nodeKey) {
178+
break
179+
}
180+
}
181+
this.$log.debug(`scroll drawer to ${height}`)
182+
scroll.scrollTop = height
183+
},
167184
update_selected: function (key, autoNext = undefined) {
168185
this.$log.debug(key, this.tree.selectedNodeSync)
169186
if (key !== null) {
@@ -183,6 +200,7 @@ export default {
183200
this.tree.expanded = this.nodeKeyMapToExpandNodes(key)
184201
// update select node
185202
this.tree.selectedNodeSync = key
203+
this.highlightNodeInView(key)
186204
} else {
187205
// lazy load 情况下 node 为 null, 直接强制加载默认值
188206
this.$log.debug('??? unkown node, redirect to 1')
@@ -244,6 +262,9 @@ export default {
244262
this.$log.debug(`expandedNodes: ${expanded}`)
245263
this.tree.expanded = expanded
246264
})
265+
.then(_ => {
266+
this.highlightNodeInView(this.currentNodeKey)
267+
})
247268
.catch(e => {
248269
this.$log.error('connection_fail', e)
249270
this.$q.notify({

0 commit comments

Comments
 (0)