forked from verdnatura/salix-front
refs #6763 fix tree
This commit is contained in:
parent
78877556cf
commit
5450f948a3
|
@ -1,5 +1,5 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref,computed, } from 'vue';
|
import { onMounted, ref,computed, watch, } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import { useState } from 'src/composables/useState';
|
import { useState } from 'src/composables/useState';
|
||||||
|
@ -27,14 +27,45 @@ const fetchedChildrensSet = ref(new Set());
|
||||||
const formData = computed(() => state.get('Tree'));
|
const formData = computed(() => state.get('Tree'));
|
||||||
|
|
||||||
const onNodeExpanded = (nodeKeysArray) => {
|
const onNodeExpanded = (nodeKeysArray) => {
|
||||||
|
console.log('ENTRY',nodeKeysArray)
|
||||||
|
|
||||||
// Verificar si el nodo ya fue expandido
|
// Verificar si el nodo ya fue expandido
|
||||||
if (!fetchedChildrensSet.value.has(nodeKeysArray.at(-1))) {
|
if (!fetchedChildrensSet.value.has(nodeKeysArray.at(-1))) {
|
||||||
fetchedChildrensSet.value.add(nodeKeysArray.at(-1));
|
fetchedChildrensSet.value.add(nodeKeysArray.at(-1));
|
||||||
fetchNodeLeaves(nodeKeysArray.at(-1)); // Llamar a la función para obtener los nodos hijos
|
fetchNodeLeaves(nodeKeysArray.at(-1)); // Llamar a la función para obtener los nodos hijos
|
||||||
}
|
}
|
||||||
state.set('Tree', nodeKeysArray.at(-1));
|
|
||||||
|
console.log(expanded.value)
|
||||||
|
console.log(nodes.value)
|
||||||
|
console.log(nodes.value[0].children)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
watch(
|
||||||
|
()=> nodes.value,
|
||||||
|
async(n) => {
|
||||||
|
console.log('ha entrado',n)
|
||||||
|
addTree({nodes: n});
|
||||||
|
},
|
||||||
|
{deep: true}
|
||||||
|
)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
()=> expanded.value,
|
||||||
|
async(n) => {
|
||||||
|
console.log('ha entrado', n)
|
||||||
|
addTree({nodeKeys: n});
|
||||||
|
},
|
||||||
|
{deep: true}
|
||||||
|
)
|
||||||
|
|
||||||
|
function addTree(tree){
|
||||||
|
const currentTree = state.get('Tree');
|
||||||
|
console.log('current', currentTree)
|
||||||
|
Object.assign(currentTree ?? {}, tree)
|
||||||
|
console.log('current assign', currentTree)
|
||||||
|
|
||||||
|
state.set('Tree', tree);
|
||||||
|
}
|
||||||
const fetchNodeLeaves = async (nodeKey) => {
|
const fetchNodeLeaves = async (nodeKey) => {
|
||||||
try {
|
try {
|
||||||
const node = treeRef.value.getNodeByKey(nodeKey);
|
const node = treeRef.value.getNodeByKey(nodeKey);
|
||||||
|
@ -88,10 +119,19 @@ const onNodeCreated = async () => {
|
||||||
await fetchNodeLeaves(creationNodeSelectedId.value);
|
await fetchNodeLeaves(creationNodeSelectedId.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const redirectToDepartmentSummary = (id) => {
|
onMounted(async () => {
|
||||||
if (!id) return;
|
const tree = state.get('Tree')
|
||||||
router.push({ name: 'DepartmentSummary', params: { id } });
|
if(tree) {
|
||||||
};
|
const {nodeKeys, nodes } = tree
|
||||||
|
console.log(tree, nodeKeys, nodes)
|
||||||
|
console.log('onMounted', Object.values(nodeKeys))
|
||||||
|
console.log('onMounted2', nodes)
|
||||||
|
nodes.value = nodes
|
||||||
|
onNodeExpanded(Object.values(nodeKeys))
|
||||||
|
expanded.value = nodeKeys
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -105,12 +145,13 @@ const redirectToDepartmentSummary = (id) => {
|
||||||
@update:expanded="onNodeExpanded($event)"
|
@update:expanded="onNodeExpanded($event)"
|
||||||
>
|
>
|
||||||
<template #default-header="{ node }">
|
<template #default-header="{ node }">
|
||||||
|
{{ node }}
|
||||||
<div
|
<div
|
||||||
class="row justify-between full-width q-pr-md cursor-pointer"
|
class="row justify-between full-width q-pr-md cursor-pointer"
|
||||||
@click.stop="redirectToDepartmentSummary(node.id)"
|
@click.stop=""
|
||||||
>
|
>
|
||||||
<a
|
<a
|
||||||
:href="`#/department/department/${node.id}/summary`"
|
:href="node.id && `#/department/department/${node.id}/summary`"
|
||||||
color: inherit
|
color: inherit
|
||||||
>
|
>
|
||||||
{{ node.name }}
|
{{ node.name }}
|
||||||
|
|
Loading…
Reference in New Issue