Browse Source

门类tree默认展开选中

master
xuhuajiao 3 years ago
parent
commit
dc0982bff7
  1. 44
      src/views/category/index.vue

44
src/views/category/index.vue

@ -143,12 +143,56 @@ export default {
// }
// return true
// },
//
findNode(tree, func) {
for (const node of tree) {
if (func(node)) return node
if (node.children) {
const res = this.findNode(node.children, func)
if (res) return res
}
}
return null
},
//
expandParents(node) {
node.expanded = true
if (node.parent) {
this.expandParents(node.parent)
}
},
[CRUD.HOOK.afterRefresh]() {
let currentKey
if (localStorage.getItem('currentCategoryKey')) {
currentKey = JSON.parse(localStorage.getItem('currentCategoryKey'))
} else {
if (this.crud.data[0].isType === 1) {
currentKey = this.findNode(this.crud.data[0].children, (node) => {
return node.isType !== 1
})
} else {
currentKey = this.crud.data[0]
}
}
//
this.$refs.tree.setCurrentKey(currentKey.id)
this.$nextTick(() => {
//
const selectedKey = this.$refs.tree.getCurrentNode()
if (this.$refs.tree.getNode(selectedKey) && this.$refs.tree.getNode(selectedKey).parent) {
this.expandParents(this.$refs.tree.getNode(selectedKey).parent)
}
//
this.handleNodeClick(selectedKey)
})
},
//
handleNodeClick(val) {
if (val) {
this.crud.selectionChangeHandler([val])
this.$refs.eform.pid = val.id
this.selectedCategory = val
localStorage.setItem('currentCategoryKey', JSON.stringify(val))
}
},
updateKeyChildren(data) {

Loading…
Cancel
Save