|
|
|
@ -14,11 +14,11 @@
|
|
|
|
|
>
|
|
|
|
|
<span class="custom-tree-node" slot-scope="{ node, data }">
|
|
|
|
|
<span v-if="node.level === 1">
|
|
|
|
|
<span>{{ node.label }}</span>
|
|
|
|
|
<span>{{ node.label }}</span> ({{ data.children.length }})
|
|
|
|
|
</span>
|
|
|
|
|
<span v-else-if="node.level === 2">
|
|
|
|
|
<i v-if="data.marked" class="el-icon-s-flag"></i>
|
|
|
|
|
<span>{{ node.label }}</span>
|
|
|
|
|
<span :title="node.label">{{ node.label }}</span>
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
</el-tree>
|
|
|
|
@ -98,7 +98,7 @@ export default {
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {});
|
|
|
|
|
},
|
|
|
|
|
handleNodeClick(node) {
|
|
|
|
|
handleNodeClick(node, data) {
|
|
|
|
|
//点击父节点收起
|
|
|
|
|
if (node.children?.length) {
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
@ -108,8 +108,18 @@ export default {
|
|
|
|
|
}
|
|
|
|
|
this.currentNodeKey = node.name;
|
|
|
|
|
console.log(node); // 你会看到当前节点的数据
|
|
|
|
|
const parentNode = this.$refs.tree.getNode(node).parent.data;
|
|
|
|
|
console.log(parentNode); // 输出父节点的数据对象
|
|
|
|
|
console.log(data);
|
|
|
|
|
const parentNode = this.findParentNode(data.id, this.piclist);
|
|
|
|
|
|
|
|
|
|
if (parentNode) {
|
|
|
|
|
// 找到了父节点,打印父节点的数据
|
|
|
|
|
console.log(parentNode); // 输出父节点的数据对象
|
|
|
|
|
} else {
|
|
|
|
|
// 没找到父节点,处理错误情况
|
|
|
|
|
console.error("未能找到父节点");
|
|
|
|
|
}
|
|
|
|
|
//const parentNode = this.$refs.tree.getNode(node).parent;
|
|
|
|
|
// //const parentNode = this.$refs.tree.getNode(node).parent.data;
|
|
|
|
|
EventBus.$emit("currentNodeData", node);
|
|
|
|
|
EventBus.$emit("perentNode", parentNode);
|
|
|
|
|
this.defaultExpandedKeys = [parentNode.name];
|
|
|
|
@ -118,6 +128,18 @@ export default {
|
|
|
|
|
this.getlabels();
|
|
|
|
|
localStorage.setItem("currentData", JSON.stringify(node));
|
|
|
|
|
},
|
|
|
|
|
findParentNode(childId, treeData) {
|
|
|
|
|
console.log(childId);
|
|
|
|
|
console.log(treeData);
|
|
|
|
|
// 递归查找父节点
|
|
|
|
|
return treeData.find((parent) => {
|
|
|
|
|
console.log(parent);
|
|
|
|
|
return (
|
|
|
|
|
parent.children &&
|
|
|
|
|
parent.children.find((child) => child.$treeNodeId === childId)
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
getlabels() {
|
|
|
|
|
getLabelsApi({
|
|
|
|
|
path: this.pathParams,
|
|
|
|
@ -150,7 +172,7 @@ export default {
|
|
|
|
|
</script>
|
|
|
|
|
<style lang="less">
|
|
|
|
|
.picTree {
|
|
|
|
|
width: 300px;
|
|
|
|
|
width: 380px;
|
|
|
|
|
padding: 10px;
|
|
|
|
|
border: 1px solid #dcdfe6;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|