Files
NSG_PORTAL_V2/components/dynamic-page/page-section/RecusiveSection.vue
T

70 lines
1.9 KiB
Vue
Raw Normal View History

2024-05-30 18:06:50 +07:00
<script setup lang="ts">
import DynamicComponent from "~/components/dynamic-page/page-component/templates/index.vue";
import DynamicSection from "~/components/dynamic-page/page-section/templates/index.vue";
const props = defineProps<{
2024-05-31 17:08:43 +07:00
type: string;
2024-05-30 18:06:50 +07:00
id: any;
}>();
import { useDynamicPageStore } from '~/stores/dynamic-page';
const store = reactive({
dynamicPage: useDynamicPageStore(),
});
const { currentPage } = storeToRefs(useDynamicPageStore());
const defineTypeRecusive = {
COMPONENT: "component",
SECTION: "section",
};
const findDataPosition = computed(() => {
let result = {};
switch (props.type) {
case defineTypeRecusive.COMPONENT:
result = currentPage.value.components && currentPage.value.components.find((component: any) => component.id === props.id);
break;
case defineTypeRecusive.SECTION:
result = currentPage.value.sections && currentPage.value.sections.find((section: any) => section.id === props.id);
break;
default:
result = {};
break;
}
return result;
});
</script>
<template>
<div>
<template v-if="props.type === defineTypeRecusive.COMPONENT">
<DynamicComponent
v-if="findDataPosition && findDataPosition?.id"
:settings="findDataPosition.settings"
:component="findDataPosition"
2024-06-25 09:08:44 +07:00
:content="findDataPosition.content"
2024-05-30 18:06:50 +07:00
/>
</template>
<template v-else-if="props.type === defineTypeRecusive.SECTION">
<DynamicSection
v-if="findDataPosition && findDataPosition?.id"
:settings="findDataPosition.settings"
:content="findDataPosition.content ? JSON.parse(findDataPosition.content) : null"
:section="findDataPosition"
/>
</template>
</div>
</template>
<style lang="scss" scoped>
2024-05-31 17:08:43 +07:00
.collection-container {
&.vertical {
grid-template-columns: repeat(1, minmax(0, 1fr));
}
&.horizontal {
grid-template-rows: auto;
grid-auto-flow: column;
}
}
</style>