minhnt-dev: add build node with arr

This commit is contained in:
MoreStrive
2024-06-17 09:55:33 +07:00
parent ecf4512cd3
commit c2b9208746
4 changed files with 27 additions and 6 deletions
@@ -1,7 +1,7 @@
<script setup lang="ts">
import DynamicComponent from "~/components/dynamic-page/page-component/templates/index.vue";
import { COLLECTION_QUERY_DROP, getValueStringWithKeyAndColon, getInputValue } from "@/utils/parseSQL";
import { isEmpty } from "lodash";
import isEmpty from "lodash/isEmpty";
const emit = defineEmits(["dropComponent", "dropData", "selectComponent"]);
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { isEmpty } from "lodash";
import isEmpty from "lodash/isEmpty";
import DynamicComponent from "~/components/dynamic-page/page-component/templates/index.vue";
import { COLLECTION_PAGING_QUERY_DROP, getInputValue } from "@/utils/parseSQL";
const router = useRouter();
+4 -4
View File
@@ -94,11 +94,11 @@ export const listArticleCondition = async (event: H3Event) => {
try {
const payload = await readBody<any>(event)
const { apiUrl } = useRuntimeConfig().public
const { items }: any = await $fetch(`${apiUrl}/cms/digital-article/condition`, {
const { items }: any = await $fetch(`${apiUrl}/cms/article/condition`, {
method: "POST",
headers: {
Site: 1
},
headers: new Headers({
site: '1' || 1,
}),
body: {
payload
}
+21
View File
@@ -0,0 +1,21 @@
import cloneDeep from 'lodash/cloneDeep';
export function buildTree(data: any) {
const _array = cloneDeep(JSON.parse(data))
if (_array.length > 0) {
let map = new Map();
_array.forEach((item : any) => map.set(item.id, item));
_array.forEach((item : any) => {
if (item.parentId !== undefined) {
let parent = map.get(item.parentId);
if (parent) {
parent.childs.push(item);
}
}
});
return _array.filter(item => !item.parentId);
} else {
return []
}
}