[update] 选部门组件先选复选框后再改变父子关联,页面选中数据和实际选中数据不符合的问题
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
<a-spin tip="Loading..." :spinning="false">
|
<a-spin tip="Loading..." :spinning="false">
|
||||||
<a-input-search style="margin-bottom: 1px" :placeholder="$t('selectDepartment.enterDepartmentPressEnter')" @search="onSearch" />
|
<a-input-search style="margin-bottom: 1px" :placeholder="$t('selectDepartment.enterDepartmentPressEnter')" @search="onSearch" />
|
||||||
<a-tree
|
<a-tree
|
||||||
|
ref="tree"
|
||||||
:checkable="true"
|
:checkable="true"
|
||||||
:class="treeScreenClass"
|
:class="treeScreenClass"
|
||||||
:treeData="treeData"
|
:treeData="treeData"
|
||||||
@@ -310,20 +311,58 @@ export default {
|
|||||||
}
|
}
|
||||||
return rows
|
return rows
|
||||||
},
|
},
|
||||||
|
// 获取currKeys及其子节点
|
||||||
|
getChildrenTreeData (currKeys, treeData) {
|
||||||
|
const childrenKeys = []
|
||||||
|
for (let i = 0; i < treeData.length; i++) {
|
||||||
|
if (currKeys.includes(treeData[i].key)) {
|
||||||
|
childrenKeys.push(treeData[i].key)
|
||||||
|
if (treeData[i].children) {
|
||||||
|
const childrenKeysArr = this.getChildrenKeys(treeData[i].children)
|
||||||
|
childrenKeys.push(...childrenKeysArr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (treeData[i].children) {
|
||||||
|
childrenKeys.push(...this.getChildrenTreeData(currKeys, treeData[i].children))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return childrenKeys
|
||||||
|
},
|
||||||
|
// 把传入的树结构key值全部存成一个数组
|
||||||
|
getChildrenKeys (treeData) {
|
||||||
|
const arr = []
|
||||||
|
for (const item of treeData) {
|
||||||
|
arr.push(item.key)
|
||||||
|
if (item.children) {
|
||||||
|
arr.push(...this.getChildrenKeys(item.children))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return arr
|
||||||
|
},
|
||||||
|
// 获取所有子节点全选的父节点
|
||||||
|
getChildAllCheckNode (treeData) {
|
||||||
|
const nodeKeys = []
|
||||||
|
for (const item of treeData) {
|
||||||
|
if (item.children) {
|
||||||
|
if (item.children.every(i => this.checkedKeys.includes(i.key))) {
|
||||||
|
// 子节点每一个都选中了
|
||||||
|
nodeKeys.push(item.key)
|
||||||
|
}
|
||||||
|
nodeKeys.push(...this.getChildAllCheckNode(item.children))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodeKeys
|
||||||
|
},
|
||||||
switchCheckStrictly (v) {
|
switchCheckStrictly (v) {
|
||||||
if (v === 1) {
|
if (v === 1) {
|
||||||
this.checkStrictly = false
|
this.checkStrictly = false
|
||||||
|
const allChildrenCheckKeys = this.getChildAllCheckNode(this.treeData)
|
||||||
|
const allChildrenKeys = this.getChildrenTreeData(this.checkedKeys, this.treeData)
|
||||||
|
this.checkedKeys = Array.from([...allChildrenCheckKeys, ...allChildrenKeys])
|
||||||
|
this.checkedRows = this.getCheckedRows(this.checkedKeys)
|
||||||
} else if (v === 2) {
|
} else if (v === 2) {
|
||||||
this.checkStrictly = true
|
this.checkStrictly = true
|
||||||
}
|
}
|
||||||
this.$nextTick(() => {
|
|
||||||
const dom = document.getElementsByClassName('ant-tree-checkbox')
|
|
||||||
console.log(dom)
|
|
||||||
dom[0].click()
|
|
||||||
setTimeout(() => {
|
|
||||||
dom[0].click()
|
|
||||||
}, 0)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
isFullscreen (val) {
|
isFullscreen (val) {
|
||||||
this.fullscreen = val
|
this.fullscreen = val
|
||||||
|
|||||||
Reference in New Issue
Block a user