perf: expand or collapse automatically when node owns one child #40
This commit is contained in:
parent
3de2a47d12
commit
da4b8b9a4f
|
@ -4,7 +4,7 @@ import { ConnectionType } from '@/consts/connection_type.js'
|
||||||
import { NIcon, NSpace, NTag } from 'naive-ui'
|
import { NIcon, NSpace, NTag } from 'naive-ui'
|
||||||
import Key from '@/components/icons/Key.vue'
|
import Key from '@/components/icons/Key.vue'
|
||||||
import ToggleDb from '@/components/icons/ToggleDb.vue'
|
import ToggleDb from '@/components/icons/ToggleDb.vue'
|
||||||
import { find, get, includes, indexOf, isEmpty, remove } from 'lodash'
|
import { find, get, includes, indexOf, isEmpty, pull, remove, size } from 'lodash'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import Refresh from '@/components/icons/Refresh.vue'
|
import Refresh from '@/components/icons/Refresh.vue'
|
||||||
import CopyLink from '@/components/icons/CopyLink.vue'
|
import CopyLink from '@/components/icons/CopyLink.vue'
|
||||||
|
@ -300,14 +300,24 @@ const onUpdateExpanded = (value, option, meta) => {
|
||||||
if (!meta.node) {
|
if (!meta.node) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// console.log(JSON.stringify(meta))
|
|
||||||
switch (meta.action) {
|
// keep expand or collapse children while they own more than 1 child
|
||||||
case 'expand':
|
let node = meta.node
|
||||||
meta.node.expanded = true
|
while (node != null && size(node.children) === 1) {
|
||||||
break
|
const key = node.children[0].key
|
||||||
case 'collapse':
|
switch (meta.action) {
|
||||||
meta.node.expanded = false
|
case 'expand':
|
||||||
break
|
node.expanded = true
|
||||||
|
if (!includes(expandedKeys.value, key)) {
|
||||||
|
expandedKeys.value.push(key)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'collapse':
|
||||||
|
node.expanded = false
|
||||||
|
remove(expandedKeys.value, (v) => v === key)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
node = node.children[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue