refs #6763 refactor node
This commit is contained in:
parent
fddc669729
commit
3a48d09080
|
@ -23,42 +23,31 @@ const expanded = ref([]);
|
||||||
const nodes = ref([{ id: null, name: t('Departments'), sons: true, children: [{}] }]);
|
const nodes = ref([{ id: null, name: t('Departments'), sons: true, children: [{}] }]);
|
||||||
|
|
||||||
const fetchedChildrensSet = ref(new Set());
|
const fetchedChildrensSet = ref(new Set());
|
||||||
// const formData = computed(() => state.get('Tree'));
|
|
||||||
|
|
||||||
const onNodeExpanded = (nodeKeysArray) => {
|
const onNodeExpanded = (nodeKeysArray) => {
|
||||||
// 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));
|
||||||
}
|
}
|
||||||
// if (nodeKeysArray.length >= 2) {
|
|
||||||
// const lastStateTree = state.get('TreeState');
|
|
||||||
// if (lastStateTree && lastStateTree) {
|
|
||||||
// !nodeKeysArray.includes(lastStateTree) && nodeKeysArray.push(lastStateTree);
|
|
||||||
// }
|
|
||||||
// fetchNodeLeaves(nodeKeysArray.at(-1));
|
|
||||||
// } else {
|
|
||||||
// fetchNodeLeaves(1); // Llamar a la función para obtener los nodos hijos
|
|
||||||
// }
|
|
||||||
state.set('Tree', nodeKeysArray);
|
state.set('Tree', nodeKeysArray);
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchNodeLeaves = async (nodeKey) => {
|
const fetchNodeLeaves = async (nodeKey) => {
|
||||||
console.log('nodeKey: ', nodeKey);
|
|
||||||
try {
|
try {
|
||||||
const node = treeRef.value?.getNodeByKey(nodeKey);
|
const node = treeRef.value?.getNodeByKey(nodeKey);
|
||||||
|
|
||||||
console.log(node);
|
|
||||||
if (!node || node.sons === 0) return;
|
if (!node || node.sons === 0) return;
|
||||||
|
|
||||||
const params = { parentId: node.id };
|
const params = { parentId: node.id };
|
||||||
const response = await axios.get('/departments/getLeaves', { params });
|
const response = await axios.get('/departments/getLeaves', { params });
|
||||||
|
|
||||||
// Si hay datos en la respuesta y tiene hijos, agregarlos al nodo actual
|
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
node.children = response.data;
|
node.children = response.data.map((n) => {
|
||||||
node.children.forEach((node) => {
|
const hasChildrens = n.sons > 0;
|
||||||
node.children = node.sons > 0 ? [{}] : null;
|
|
||||||
|
n.children = hasChildrens ? [{}] : null;
|
||||||
|
n.clickable = true;
|
||||||
|
return n;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,40 +94,22 @@ onMounted(async (n) => {
|
||||||
const tree = [...state.get('Tree'), 1];
|
const tree = [...state.get('Tree'), 1];
|
||||||
const lastStateTree = state.get('TreeState');
|
const lastStateTree = state.get('TreeState');
|
||||||
if (tree) {
|
if (tree) {
|
||||||
console.log('tree: ', tree);
|
|
||||||
if (lastStateTree) tree.push(lastStateTree);
|
|
||||||
for (let n of tree) {
|
for (let n of tree) {
|
||||||
console.log('n', n);
|
|
||||||
// setTimeout(async () => {
|
|
||||||
// await fetchNodeLeaves(n);
|
|
||||||
// }, 1000);
|
|
||||||
await fetchNodeLeaves(n);
|
await fetchNodeLeaves(n);
|
||||||
}
|
}
|
||||||
expanded.value = tree;
|
expanded.value = tree;
|
||||||
console.log('expanded.value', expanded.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// const lastStateTree = state.get('TreeState');
|
if (lastStateTree) {
|
||||||
// if (lastStateTree && lastStateTree) {
|
tree.push(lastStateTree);
|
||||||
// fetchNodeLeaves(lastStateTree);
|
await fetchNodeLeaves(lastStateTree);
|
||||||
// !treeRef.value.expanded.includes(lastStateTree) &&
|
}
|
||||||
// treeRef.value.expanded.push(lastStateTree);
|
}
|
||||||
// }
|
|
||||||
// treeRef.value.expandAll();
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (lastStateTree) {
|
if (lastStateTree) {
|
||||||
const xx = treeRef.value.getNodeByKey(lastStateTree);
|
|
||||||
console.log(xx);
|
|
||||||
document.getElementById(lastStateTree).scrollIntoView();
|
document.getElementById(lastStateTree).scrollIntoView();
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
});
|
});
|
||||||
// function handleClick(event, node) {
|
|
||||||
|
|
||||||
// }
|
|
||||||
// function handleTab(event, node) {
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
function handleEvent(type, event, node) {
|
function handleEvent(type, event, node) {
|
||||||
const isParent = node.sons > 0;
|
const isParent = node.sons > 0;
|
||||||
|
@ -162,20 +133,6 @@ function handleEvent(type, event, node) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function handleRow(event, node) {
|
|
||||||
switch (event.currentTarget.nodeName.toLowerCase()) {
|
|
||||||
case 'div':
|
|
||||||
node.id &&
|
|
||||||
router.push({ path: `#/department/department/${node.id}/summary` });
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'span':
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -190,10 +147,9 @@ function handleRow(event, node) {
|
||||||
:default-expand-all="true"
|
:default-expand-all="true"
|
||||||
>
|
>
|
||||||
<template #default-header="{ node }">
|
<template #default-header="{ node }">
|
||||||
<!-- @click="node.id && router.push({path:`#/department/department/${node.id}/summary`})" -->
|
|
||||||
<div
|
<div
|
||||||
:id="node.id"
|
:id="node.id"
|
||||||
class="row justify-between full-width q-pr-md cursor-pointer"
|
class="qtr row justify-between full-width q-pr-md cursor-pointer"
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<span @click="handleEvent('row', $event, node)">
|
<span @click="handleEvent('row', $event, node)">
|
||||||
|
@ -249,9 +205,11 @@ function handleRow(event, node) {
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
a {
|
span {
|
||||||
color: inherit;
|
color: $primary;
|
||||||
text-decoration: none;
|
}
|
||||||
|
.hover-shadow:hover {
|
||||||
|
background-color: #9e9e9e;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<i18n>
|
<i18n>
|
||||||
|
|
Loading…
Reference in New Issue