add tree 可以不选中父子
This commit is contained in:
@@ -24,7 +24,8 @@ const _sfc_main$1 = defineComponent({
|
||||
checkStrictly: { type: [Boolean, String] },
|
||||
collapseTransition: { type: Boolean },
|
||||
onlyIconControl: { type: Boolean },
|
||||
hideicon: { type: Boolean }
|
||||
hideicon: { type: Boolean },
|
||||
selectParent: { type: Boolean }
|
||||
},
|
||||
emits: ["node-click"],
|
||||
setup(__props, { emit }) {
|
||||
@@ -52,7 +53,7 @@ const _sfc_main$1 = defineComponent({
|
||||
emit("node-click", node);
|
||||
}
|
||||
function handleChange(checked, node) {
|
||||
props.tree.setCheckedKeys(checked, props.checkStrictly, node);
|
||||
props.tree.setCheckedKeys(checked, props.checkStrictly || props.selectParent, node);
|
||||
}
|
||||
function handleIconClick(node) {
|
||||
node.isLeaf = !node.isLeaf;
|
||||
@@ -72,17 +73,16 @@ const _sfc_main$1 = defineComponent({
|
||||
}
|
||||
const isChildAllSelected = computed(() => {
|
||||
function _isChildAllSelected(node) {
|
||||
if (!props.showCheckbox) {
|
||||
return false;
|
||||
}
|
||||
let childSelectNum = 0;
|
||||
let res = false;
|
||||
for (const item of node.children) {
|
||||
if (item.isChecked)
|
||||
childSelectNum++;
|
||||
}
|
||||
if (childSelectNum > 0)
|
||||
node.isChecked = true;
|
||||
if (!props.selectParent) {
|
||||
if (childSelectNum > 0)
|
||||
node.isChecked = true;
|
||||
}
|
||||
if (childSelectNum == node.children.length) {
|
||||
for (const item of node.children) {
|
||||
res = _isChildAllSelected(item);
|
||||
@@ -95,11 +95,14 @@ const _sfc_main$1 = defineComponent({
|
||||
return res;
|
||||
}
|
||||
return (node) => {
|
||||
console.log(props.selectParent);
|
||||
if (props.checkStrictly) {
|
||||
return false;
|
||||
} else {
|
||||
} else if (props.selectParent) {
|
||||
let res = _isChildAllSelected(node);
|
||||
return res;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -166,6 +169,7 @@ const _sfc_main$1 = defineComponent({
|
||||
checkStrictly: __props.checkStrictly,
|
||||
"only-icon-control": __props.onlyIconControl,
|
||||
hideicon: props.hideicon,
|
||||
"select-parent": props.selectParent,
|
||||
onNodeClick: recursiveNodeClick
|
||||
}, createSlots({ _: 2 }, [
|
||||
_ctx.$slots.title ? {
|
||||
@@ -177,7 +181,7 @@ const _sfc_main$1 = defineComponent({
|
||||
]),
|
||||
key: "0"
|
||||
} : void 0
|
||||
]), 1032, ["tree", "node-list", "show-checkbox", "show-line", "selected-key", "collapse-transition", "checkStrictly", "only-icon-control", "hideicon"])
|
||||
]), 1032, ["tree", "node-list", "show-checkbox", "show-line", "selected-key", "collapse-transition", "checkStrictly", "only-icon-control", "hideicon", "select-parent"])
|
||||
])) : createCommentVNode("", true)
|
||||
]),
|
||||
_: 2
|
||||
@@ -227,6 +231,7 @@ class Tree {
|
||||
checkStrictly,
|
||||
replaceFields: { children, id, title }
|
||||
} = this.config;
|
||||
console.log(origin, "origin");
|
||||
const nodeKey = Reflect.get(origin, id);
|
||||
const nodeTitle = Reflect.get(origin, title);
|
||||
const nodeChildren = Reflect.get(origin, children);
|
||||
@@ -264,6 +269,7 @@ class Tree {
|
||||
});
|
||||
}
|
||||
setChildrenChecked(checked, nodes) {
|
||||
console.log("\u8D70\u8D4B\u503C\u5B50\u8282\u70B9\u4E86");
|
||||
var ableCount = 0;
|
||||
var checkCount = 0;
|
||||
const len = nodes.length;
|
||||
@@ -284,6 +290,7 @@ class Tree {
|
||||
}
|
||||
}
|
||||
setParentChecked(checked, parent) {
|
||||
console.log("\u8D70\u8D4B\u503C\u7236\u8282\u70B9\u4E86");
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
@@ -299,6 +306,7 @@ class Tree {
|
||||
}
|
||||
setCheckedKeys(checked, checkStrictly, node) {
|
||||
node.isChecked = checked;
|
||||
console.log(node, checkStrictly, 186);
|
||||
if (!checkStrictly) {
|
||||
if (node.parentNode) {
|
||||
this.setParentChecked(checked, node.parentNode);
|
||||
@@ -383,7 +391,8 @@ const _sfc_main = defineComponent({
|
||||
title: "title"
|
||||
};
|
||||
} },
|
||||
hideicon: { type: Boolean }
|
||||
hideicon: { type: Boolean },
|
||||
selectParent: { type: Boolean, default: false }
|
||||
},
|
||||
emits: ["update:checkedKeys", "update:expandKeys", "node-click"],
|
||||
setup(__props, { emit }) {
|
||||
@@ -446,7 +455,8 @@ const _sfc_main = defineComponent({
|
||||
"collapse-transition": __props.collapseTransition,
|
||||
"only-icon-control": __props.onlyIconControl,
|
||||
onNodeClick: handleClick,
|
||||
hideicon: props.hideicon
|
||||
hideicon: props.hideicon,
|
||||
selectParent: props.selectParent
|
||||
}, createSlots({ _: 2 }, [
|
||||
_ctx.$slots.title ? {
|
||||
name: "title",
|
||||
@@ -455,7 +465,7 @@ const _sfc_main = defineComponent({
|
||||
]),
|
||||
key: "0"
|
||||
} : void 0
|
||||
]), 1032, ["tree", "node-list", "show-checkbox", "show-line", "selectedKey", "check-strictly", "collapse-transition", "only-icon-control", "hideicon"])
|
||||
]), 1032, ["tree", "node-list", "show-checkbox", "show-line", "selectedKey", "check-strictly", "collapse-transition", "only-icon-control", "hideicon", "selectParent"])
|
||||
], 2);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user