This commit is contained in:
2024-10-22 09:09:41 +08:00
parent ef869c5ab1
commit 3a9b2d55c6
99 changed files with 4506 additions and 3465 deletions

View File

@@ -54,7 +54,11 @@ const _sfc_main$1 = defineComponent({
emit("node-click", node);
}
function handleChange(checked, node) {
props.tree.setCheckedKeys(checked, props.checkStrictly || props.selectParent, node);
props.tree.setCheckedKeys(
checked,
props.checkStrictly || props.selectParent,
node
);
}
function handleIconClick(node) {
node.isLeaf = !node.isLeaf;
@@ -347,19 +351,22 @@ class Tree {
}
const useTree = (props, emit) => {
var _a, _b, _c, _d;
const tree = new Tree({
nodeMap: /* @__PURE__ */ new Map(),
originMap: /* @__PURE__ */ new Map(),
replaceFields: {
id: "id",
title: "title",
children: "children"
const tree = new Tree(
{
nodeMap: /* @__PURE__ */ new Map(),
originMap: /* @__PURE__ */ new Map(),
replaceFields: {
id: "id",
title: "title",
children: "children"
},
showCheckbox: (_a = props.showCheckbox) != null ? _a : false,
checkedKeys: (_b = props.checkedKeys) != null ? _b : [],
expandKeys: (_c = props.expandKeys) != null ? _c : [],
checkStrictly: (_d = props.checkStrictly) != null ? _d : false
},
showCheckbox: (_a = props.showCheckbox) != null ? _a : false,
checkedKeys: (_b = props.checkedKeys) != null ? _b : [],
expandKeys: (_c = props.expandKeys) != null ? _c : [],
checkStrictly: (_d = props.checkStrictly) != null ? _d : false
}, props.data);
props.data
);
const nodeList = computed(() => {
const nodes = tree.getData();
return nodes;
@@ -418,27 +425,39 @@ const _sfc_main = defineComponent({
tree.value = _tree;
nodeList.value = _nodeList.value;
};
watch(() => props.data, () => {
loadNodeList();
}, { deep: true, immediate: true });
watch(() => props.checkedKeys, () => {
console.log(tree.value);
if (!unWatch.value) {
watch(
() => props.data,
() => {
loadNodeList();
},
{ deep: true, immediate: true }
);
watch(
() => props.checkedKeys,
() => {
console.log(tree.value);
if (!unWatch.value) {
loadNodeList();
}
},
{
deep: true
}
}, {
deep: true
});
watch(tree, () => {
if (initStatus.value) {
const { checkedKeys } = tree.value.getKeys();
unWatch.value = true;
emit("update:checkedKeys", checkedKeys);
nextTick(() => {
unWatch.value = false;
});
}
}, { deep: true });
);
watch(
tree,
() => {
if (initStatus.value) {
const { checkedKeys } = tree.value.getKeys();
unWatch.value = true;
emit("update:checkedKeys", checkedKeys);
nextTick(() => {
unWatch.value = false;
});
}
},
{ deep: true }
);
onMounted(() => {
nextTick(() => {
initStatus.value = true;