test tree 不选择父选择框

This commit is contained in:
2023-05-15 08:59:25 +08:00
parent 56769f4152
commit eb3f2e831c
6 changed files with 22 additions and 24 deletions

View File

@@ -24,6 +24,7 @@ export interface TreeData {
isLeaf: boolean;
hasNextSibling: boolean;
parentNode: Nullable<TreeData>;
selectParent:boolean;
}
export interface TreeNodeProps {
@@ -107,16 +108,8 @@ function handleRowClick(node: TreeData) {
//判断是否半选
const isChildAllSelected = computed(() => {
function _isChildAllSelected(node: TreeData): boolean {
if (!props.showCheckbox) {
return false;
}
let childSelectNum = 0;
let res = false; // true为半选 false为全选
if(!props.selectParent){
return false
}
for (const item of node.children) {
if (item.isChecked) childSelectNum++;
}

View File

@@ -17,6 +17,7 @@ export interface TreeData {
isLeaf: boolean;
hasNextSibling: boolean;
parentNode: Nullable<TreeData>;
selectParent:boolean;
}
interface ReplaceFields {
@@ -99,6 +100,7 @@ class Tree {
const nodeTitle = Reflect.get(origin, title);
const nodeChildren = Reflect.get(origin, children);
const nodeDisabled = !!Reflect.get(origin, "disabled");
const selectParent = !!Reflect.get(origin, "selectParent");
const nodeIsLeaf = !!Reflect.get(origin, "spread");
const parentNode = nodeMap.get(parentKey);
@@ -113,6 +115,7 @@ class Tree {
isLeaf: false,
hasNextSibling: hasNextSibling,
parentNode: parentNode || null,
selectParent: selectParent
});
node.isDisabled = nodeDisabled;
@@ -183,6 +186,9 @@ class Tree {
node: TreeData
) {
node.isChecked = checked;
if (!node.selectParent) {
return false;
}
if (!checkStrictly) {
if (node.parentNode) {
this.setParentChecked(checked, node.parentNode);