minhnt-dev: only ssr

This commit is contained in:
MoreStrive
2024-06-21 09:56:34 +07:00
parent 229155b24a
commit 6a275c354e
18 changed files with 84 additions and 1003 deletions
@@ -39,8 +39,6 @@ const findDataPosition = computed(() => {
} }
return result; return result;
}); });
console.log(findDataPosition, 'findDataPosition')
</script> </script>
<template> <template>
@@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import isEmpty from "lodash/isEmpty";
import { COLLECTION_QUERY_DROP, getValueStringWithKeyAndColon, getInputValue } from "@/utils/parseSQL"; import { COLLECTION_QUERY_DROP, getValueStringWithKeyAndColon, getInputValue } from "@/utils/parseSQL";
import { isEmpty } from "@/utils/lodash";
const emit = defineEmits(["dropData", "selectComponent"]); const emit = defineEmits(["dropData", "selectComponent"]);
@@ -1,7 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import DynamicComponent from "~/components/dynamic-page/page-component/templates/index.vue"; import DynamicComponent from "~/components/dynamic-page/page-component/templates/index.vue";
import { COLLECTION_QUERY_DROP, getValueStringWithKeyAndColon, getInputValue } from "@/utils/parseSQL"; import { COLLECTION_QUERY_DROP, getValueStringWithKeyAndColon, getInputValue } from "@/utils/parseSQL";
import { isEmpty, groupBy } from "lodash";
import { breakpoint } from "~/definitions"; import { breakpoint } from "~/definitions";
import { useWindowSize } from "@vueuse/core"; import { useWindowSize } from "@vueuse/core";
const { width } = useWindowSize() const { width } = useWindowSize()
@@ -15,7 +15,7 @@ const definedDynamicComponent: Record<string, any> = {
[enumPageComponentTemplates.ADVERTISING]: Dynamic_Advertising, [enumPageComponentTemplates.ADVERTISING]: Dynamic_Advertising,
[enumPageComponentTemplates.NAVIGATION]: Dynamic_Navigation, [enumPageComponentTemplates.NAVIGATION]: Dynamic_Navigation,
}; };
// console.log(_props.settings.template, 'template')
const getCurrentComponent = computed(() => `${_props.settings.template}`); const getCurrentComponent = computed(() => `${_props.settings.template}`);
const GET_PROPS = computed(() => { const GET_PROPS = computed(() => {
return () => { return () => {
@@ -41,7 +41,6 @@ const SETTING_OPTIONS = {
h4 { h4 {
font-size: 14px; font-size: 14px;
font-weight: normal; font-weight: normal;
text-align: center;
cursor: pointer; cursor: pointer;
} }
} }
@@ -1,5 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
import isEmpty from "lodash/isEmpty";
// import DynamicComponent from "~/components/cms/page-component/templates/index.vue"; // import DynamicComponent from "~/components/cms/page-component/templates/index.vue";
// import { getInputValue } from "@/utils/cms/page/parseSQL"; // import { getInputValue } from "@/utils/cms/page/parseSQL";
@@ -11,18 +10,17 @@ import isEmpty from "lodash/isEmpty";
// component?: any; // component?: any;
// }>(); // }>();
// const SETTING_OPTIONS = { const SETTING_OPTIONS = {
// MAX_ELEMENT: 10, MAX_ELEMENT: 10,
// }; };
</script> </script>
<template> <template>
ád <section>
<!-- <section>
<div v-for="navItem, index in Array(SETTING_OPTIONS.MAX_ELEMENT).fill({})" :key="index"> <div v-for="navItem, index in Array(SETTING_OPTIONS.MAX_ELEMENT).fill({})" :key="index">
<div class="empty"></div> <div class="empty"></div>
</div> </div>
</section> --> </section>
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
@@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import isEmpty from "lodash/isEmpty"; import { isEmpty } from "@/utils/lodash";
import DynamicComponent from "~/components/dynamic-page/page-component/templates/index.vue"; import DynamicComponent from "~/components/dynamic-page/page-component/templates/index.vue";
import { COLLECTION_PAGING_QUERY_DROP, getInputValue } from "@/utils/parseSQL"; import { COLLECTION_PAGING_QUERY_DROP, getInputValue } from "@/utils/parseSQL";
const router = useRouter(); const router = useRouter();
@@ -51,7 +51,7 @@ onBeforeMount(() => {
}); });
const loadPage = (page: string | number) => { const loadPage = (page: string | number) => {
console.log(`Loading page ${page}`); // console.log(`Loading page ${page}`);
// listArticleByCategory.value = // listArticleByCategory.value =
}; };
@@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import isEmpty from "lodash/isEmpty"; import { isEmpty } from "@/utils/lodash";
import DynamicComponent from "~/components/dynamic-page/page-component/templates/index.vue"; import DynamicComponent from "~/components/dynamic-page/page-component/templates/index.vue";
import { COLLECTION_PAGING_QUERY_DROP, getInputValue } from "@/utils/parseSQL"; import { COLLECTION_PAGING_QUERY_DROP, getInputValue } from "@/utils/parseSQL";
const router = useRouter(); const router = useRouter();
@@ -72,7 +72,7 @@ onBeforeMount(() => {
}); });
const loadPage = (page: string | number) => { const loadPage = (page: string | number) => {
console.log(`Loading page ${page}`); // console.log(`Loading page ${page}`);
// listArticleByCategory.value = // listArticleByCategory.value =
}; };
+7 -5
View File
@@ -6,12 +6,15 @@ export default defineNuxtConfig({
nitro: { nitro: {
preset: 'iis_node' preset: 'iis_node'
}, },
devtools: { enabled: true }, devtools: { enabled: true },
app: { app: {
head: { head: {
link: [], link: [],
}, },
}, },
modules: [ modules: [
'@nuxt/image', '@nuxt/image',
"@unocss/nuxt", "@unocss/nuxt",
@@ -20,7 +23,6 @@ export default defineNuxtConfig({
"nuxt-delay-hydration", "nuxt-delay-hydration",
"nuxt-icon", "nuxt-icon",
"dayjs-nuxt", "dayjs-nuxt",
"nuxt-lodash",
'@ant-design-vue/nuxt', '@ant-design-vue/nuxt',
], ],
@@ -49,10 +51,6 @@ export default defineNuxtConfig({
}], }],
}, },
lodash: {
prefix: "_",
},
// pinia // pinia
pinia: { pinia: {
autoImports: [ autoImports: [
@@ -70,6 +68,10 @@ export default defineNuxtConfig({
}, },
ssr: true, ssr: true,
routeRules: {
// Tất cả các route sẽ sử dụng SSR
'**': { ssr: true },
},
typescript: { typescript: {
shim: false, shim: false,
-3
View File
@@ -16,19 +16,16 @@
"dayjs-nuxt": "^2.1.8", "dayjs-nuxt": "^2.1.8",
"nuxt": "latest", "nuxt": "latest",
"nuxt-icon": "latest", "nuxt-icon": "latest",
"nuxt-lodash": "latest",
"typescript": "^5.3.3", "typescript": "^5.3.3",
"vue-tsc": "^1.8.27" "vue-tsc": "^1.8.27"
}, },
"dependencies": { "dependencies": {
"@types/lodash": "^4.17.4",
"@unocss/nuxt": "latest", "@unocss/nuxt": "latest",
"@unocss/reset": "latest", "@unocss/reset": "latest",
"@vueuse/core": "^10.8.0", "@vueuse/core": "^10.8.0",
"@vueuse/nuxt": "10.5.0", "@vueuse/nuxt": "10.5.0",
"axios": "^1.5.1", "axios": "^1.5.1",
"cheerio": "^1.0.0-rc.12", "cheerio": "^1.0.0-rc.12",
"lodash": "^4.17.21",
"nuxt-delay-hydration": "latest", "nuxt-delay-hydration": "latest",
"sass": "latest", "sass": "latest",
"sass-loader": "latest", "sass-loader": "latest",
+1 -19
View File
@@ -1,9 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import _cloneDeep from 'lodash/cloneDeep';
import DynamicTemplate from "~/components/dynamic-page/page/templates/index.vue"; import DynamicTemplate from "~/components/dynamic-page/page/templates/index.vue";
import DynamicSection from "~/components/dynamic-page/page-section/templates/index.vue"; import DynamicSection from "~/components/dynamic-page/page-section/templates/index.vue";
import { useDynamicPageStore } from '~/stores/dynamic-page'; import { useDynamicPageStore } from '~/stores/dynamic-page';
const { currentPage, sectionPublished, componentPublished } = storeToRefs(useDynamicPageStore()); const { currentPage, sectionPublished, componentPublished } = storeToRefs(useDynamicPageStore());
@@ -12,29 +9,15 @@ const store = reactive({
dynamicPage: useDynamicPageStore(), dynamicPage: useDynamicPageStore(),
}); });
(async () => { await useAsyncData('index', () => store.dynamicPage.fetchPageByCode(route.path.replace('/', '')))
try {
store.dynamicPage.fetchPageByCode(route.path.replace('/', ''));
} catch (error) {
console.error("Error fetching data:", error);
}
})();
watch(currentPage, () => {
store.dynamicPage.setSectionPublished();
store.dynamicPage.setComponentPublished();
}, { deep: true })
useHead({ useHead({
title: () => currentPage.value.title || '' title: () => currentPage.value.title || ''
}) })
</script> </script>
<template> <template>
<main class="h-screen" v-if="currentPage"> <main class="h-screen" v-if="currentPage">
<DynamicTemplate :settings="currentPage.settings"> <DynamicTemplate :settings="currentPage.settings">
<template v-if="sectionPublished && sectionPublished.length > 0">
<DynamicSection <DynamicSection
v-for="(section, index) in sectionPublished" v-for="(section, index) in sectionPublished"
:key="index" :key="index"
@@ -42,7 +25,6 @@ useHead({
:content="section.content ? JSON.parse(section.content) : null" :content="section.content ? JSON.parse(section.content) : null"
:section="section" :section="section"
/> />
</template>
</DynamicTemplate> </DynamicTemplate>
</main> </main>
</template> </template>
+29 -54
View File
@@ -5,8 +5,6 @@
*/ */
<script setup lang="ts"> <script setup lang="ts">
import _cloneDeep from 'lodash/cloneDeep';
import DynamicTemplate from "~/components/dynamic-page/page/templates/index.vue"; import DynamicTemplate from "~/components/dynamic-page/page/templates/index.vue";
import DynamicSection from "~/components/dynamic-page/page-section/templates/index.vue"; import DynamicSection from "~/components/dynamic-page/page-section/templates/index.vue";
@@ -22,64 +20,42 @@ const store = reactive({
article: useArticleStore(), article: useArticleStore(),
}); });
(async () => { const loadPage = async () => {
try { const promises = [];
await store.article.getArticleBySlug(route.params.slug); promises.push(store.article.getArticleBySlug(route.params.slug));
// useHead({ let isContentType = '';
// title: currentArticle.value?.title.replace(/<\/?[^>]+(>|$)/g, ""),
// })
useSeoMeta({
title: currentArticle.value?.title.replace(/<\/?[^>]+(>|$)/g, ""),
ogTitle: currentArticle.value?.title.replace(/<\/?[^>]+(>|$)/g, ""),
description: currentArticle.value?.intro.replace(/<\/?[^>]+(>|$)/g, ""),
ogDescription: currentArticle.value?.intro.replace(/<\/?[^>]+(>|$)/g, ""),
ogImage: currentArticle.value?.thumbnail,
})
} catch (error) {
console.error("Error fetching data:", error);
}
})();
const loadPage = async (contentType: string | number) => {
await store.dynamicPage.fetchPageByCode(contentType);
store.dynamicPage.setSectionPublished();
store.dynamicPage.setComponentPublished();
}
watch(currentArticle, async () => {
let isContentType : string = '';
switch (currentArticle.value?.contentType) { switch (currentArticle.value?.contentType) {
case 1: case 1:
isContentType = 'trang-chi-tiet-bai-viet-general' isContentType = 'trang-chi-tiet-bai-viet-general';
break; break;
case 2: case 2:
isContentType = 'trang-chi-tiet-bai-viet-image' isContentType = 'trang-chi-tiet-bai-viet-image';
break; break;
case 3: case 3:
isContentType = 'trang-chi-tiet-podcast' isContentType = 'trang-chi-tiet-podcast';
break; break;
case 4: case 4:
isContentType = 'trang-chi-tiet-bai-viet-video' isContentType = 'trang-chi-tiet-bai-viet-video';
break; break;
case 5: case 5:
if (currentArticle.value?.layoutType === 4) { if (currentArticle.value?.layoutType === 4) {
isContentType = 'trang-chi-tiet-bai-viet-emagazine' isContentType = 'trang-chi-tiet-bai-viet-emagazine';
break;
}
if (currentArticle.value?.layoutType === 3) {
isContentType = 'trang-chi-tiet-bai-viet-infographics'
break;
}
default:
isContentType = 'trang-chi-tiet-bai-viet-general'
break; break;
}
if (currentArticle.value?.layoutType === 3) {
isContentType = 'trang-chi-tiet-bai-viet-infographics';
break;
}
default:
isContentType = 'trang-chi-tiet-bai-viet-general';
break;
} }
await loadPage(isContentType); promises.push(store.dynamicPage.fetchPageByCode(isContentType));
}, { deep: true }) await Promise.all(promises);
};
await useAsyncData('detail-article', () => loadPage());
useSeoMeta({ useSeoMeta({
title: () => currentArticle.value?.title?.replace(/<[^>]+>/g, ''), title: () => currentArticle.value?.title?.replace(/<[^>]+>/g, ''),
@@ -87,9 +63,8 @@ useSeoMeta({
ogTitle: () => currentArticle.value?.title, ogTitle: () => currentArticle.value?.title,
ogImage: () => currentArticle.value?.thumbnail, ogImage: () => currentArticle.value?.thumbnail,
ogDescription: () => currentArticle.value?.intro, ogDescription: () => currentArticle.value?.intro,
twitterCard: 'summary_large_image', twitterCard: () => 'summary_large_image',
}) })
</script> </script>
<template> <template>
@@ -106,4 +81,4 @@ useSeoMeta({
</template> </template>
</DynamicTemplate> </DynamicTemplate>
</main> </main>
</template> </template>
+1 -17
View File
@@ -1,6 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
import _cloneDeep from 'lodash/cloneDeep';
import DynamicTemplate from "~/components/dynamic-page/page/templates/index.vue"; import DynamicTemplate from "~/components/dynamic-page/page/templates/index.vue";
import DynamicSection from "~/components/dynamic-page/page-section/templates/index.vue"; import DynamicSection from "~/components/dynamic-page/page-section/templates/index.vue";
import { useDynamicPageStore } from '~/stores/dynamic-page'; import { useDynamicPageStore } from '~/stores/dynamic-page';
@@ -11,19 +9,7 @@ const store = reactive({
dynamicPage: useDynamicPageStore(), dynamicPage: useDynamicPageStore(),
}); });
(async () => { await useAsyncData('index', () => store.dynamicPage.fetchPageByCode(route.path === '/' ? 'trang-chu' : route.path.replace('/', '')))
try {
store.dynamicPage.fetchPageByCode(route.path === '/' ? 'trang-chu' : route.path.replace('/', ''));
} catch (error) {
console.error("Error fetching data:", error);
}
})();
watch(currentPage, () => {
store.dynamicPage.setSectionPublished();
store.dynamicPage.setComponentPublished()
}, { deep: true })
useHead({ useHead({
title: 'Trang chủ' title: 'Trang chủ'
}) })
@@ -32,7 +18,6 @@ useHead({
<template> <template>
<main class="h-screen" v-if="currentPage"> <main class="h-screen" v-if="currentPage">
<DynamicTemplate :settings="currentPage.settings"> <DynamicTemplate :settings="currentPage.settings">
<template v-if="sectionPublished && sectionPublished.length > 0">
<DynamicSection <DynamicSection
v-for="(section, index) in sectionPublished" v-for="(section, index) in sectionPublished"
:key="index" :key="index"
@@ -40,7 +25,6 @@ useHead({
:content="section.content ? JSON.parse(section.content) : null" :content="section.content ? JSON.parse(section.content) : null"
:section="section" :section="section"
/> />
</template>
</DynamicTemplate> </DynamicTemplate>
</main> </main>
</template> </template>
+4 -5
View File
@@ -7,11 +7,10 @@ export const useArticleStore = defineStore("article", () => {
const getArticleById = async (id: string | number) => { const getArticleById = async (id: string | number) => {
try { try {
const { data } = await useFetch(`/api/articles/get-by-id/${id}`)
const { data} = await useFetch(`/api/articles/get-by-id/${id}`)
currentArticle.value = {} currentArticle.value = {}
currentArticle.value = data.value.item currentArticle.value = data.value.item
} catch (error: any) {} } catch (error: any) { }
} }
const getArticleBySlug = async (slug: string) => { const getArticleBySlug = async (slug: string) => {
@@ -19,7 +18,7 @@ export const useArticleStore = defineStore("article", () => {
const { data: article } = await useAsyncData('article', () => $fetch(`/api/articles/get-by-slug/${slug}`)) const { data: article } = await useAsyncData('article', () => $fetch(`/api/articles/get-by-slug/${slug}`))
currentArticle.value = {} currentArticle.value = {}
currentArticle.value = article.value?.item currentArticle.value = article.value?.item
} catch (error: any) {} } catch (error: any) { }
} }
const getArticleCondition = async (condition: ArticleCondition) => { const getArticleCondition = async (condition: ArticleCondition) => {
@@ -29,7 +28,7 @@ export const useArticleStore = defineStore("article", () => {
body: condition body: condition
}) })
} catch (error: any) { } catch (error: any) {
} }
} }
+20 -879
View File
@@ -9,869 +9,12 @@ export const useDynamicPageStore = defineStore("dynamicPageStore", () => {
async function fetchPageByCode(slug: any) { async function fetchPageByCode(slug: any) {
try { try {
const { data } = await useFetch(`/api/dynamic-page/get-by-code/${slug}`) const { data: { value } } = await useAsyncData('page', () => $fetch(`/api/dynamic-page/get-by-code/${slug}`))
// const data = ref({
// "sections": [
// {
// "id": 42,
// "siteId": 1,
// "pageId": 4,
// "parentId": null,
// "title": "section5hang",
// "slug": "section5hang",
// "code": "section5hang",
// "type": 1,
// "content": "[{\"type\":\"component\",\"data\":57},{\"type\":\"component\",\"data\":68},{\"type\":\"component\",\"data\":69},{\"type\":\"component\",\"data\":44},{\"type\":\"component\",\"data\":50}]",
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "LAYOUT:horizontal-TYPE:Default-MAX:5",
// "template": "Article",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": true,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T16:17:57.386059",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T16:18:56.082485"
// },
// {
// "id": 32,
// "siteId": 1,
// "pageId": 4,
// "parentId": null,
// "title": "section2hang",
// "slug": "section2hang",
// "code": "section2hang_doisong",
// "type": 1,
// "content": "[{\"type\":\"component\",\"data\":58},{\"type\":\"component\",\"data\":101}]",
// "keywords": null,
// "settings": {
// "label": "",
// "layout": "LAYOUT:horizontal-TYPE:Default-MAX:2",
// "template": "Article",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": true,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T10:33:59.071404",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T16:18:56.493553"
// },
// {
// "id": 31,
// "siteId": 1,
// "pageId": 4,
// "parentId": null,
// "title": "section2left3",
// "slug": "section2left3",
// "code": "section2left3_doisong",
// "type": 1,
// "content": "[{\"type\":\"section\",\"data\":42},{\"type\":\"section\",\"data\":32}]",
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "LAYOUT:vertical-TYPE:LEFT-MAX:2",
// "template": "Article",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": "",
// "isPublished": true,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T09:02:35.828188",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T09:36:43.623068"
// },
// {
// "id": 30,
// "siteId": 1,
// "pageId": 4,
// "parentId": null,
// "title": "section2left2",
// "slug": "section2left2",
// "code": "section2left2_doisong",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "LAYOUT:vertical-TYPE:LEFT-MAX:2",
// "template": "Article",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": "",
// "isPublished": false,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T09:02:09.626405",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T09:37:17.837094"
// },
// {
// "id": 29,
// "siteId": 1,
// "pageId": 4,
// "parentId": null,
// "title": "section2left1",
// "slug": "section2left1",
// "code": "section2left1_doisong",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "LAYOUT:vertical-TYPE:LEFT-MAX:2",
// "template": "Article",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": "",
// "isPublished": false,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T09:01:11.78265",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T09:01:40.494573"
// },
// {
// "id": 28,
// "siteId": 1,
// "pageId": 4,
// "parentId": null,
// "title": "section3cot",
// "slug": "section3cot",
// "code": "section3cot_doisong",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "LAYOUT:vertical-TYPE:Default-MAX:3",
// "template": "Article",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": "",
// "isPublished": false,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T09:00:32.765855",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T09:37:50.127734"
// },
// {
// "id": 27,
// "siteId": 1,
// "pageId": 4,
// "parentId": null,
// "title": "section2left",
// "slug": "section2left",
// "code": "section2left_doisong",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "LAYOUT:vertical-TYPE:LEFT-MAX:2",
// "template": "Article",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": "",
// "isPublished": false,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T09:00:05.873579",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T09:38:06.600079"
// },
// {
// "id": 26,
// "siteId": 1,
// "pageId": 4,
// "parentId": null,
// "title": "section3hang",
// "slug": "section3hang",
// "code": "section3hang_doisong",
// "type": 1,
// "content": null,
// "keywords": null,
// "settings": {
// "label": "",
// "layout": "LAYOUT:horizontal-TYPE:Default-MAX:3",
// "template": "Article",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": false,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T08:59:19.411836",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T09:38:29.410238"
// },
// {
// "id": 25,
// "siteId": 1,
// "pageId": 4,
// "parentId": null,
// "title": "section1hang1",
// "slug": "section1hang1",
// "code": "section1hang1_doisong",
// "type": 1,
// "content": "",
// "keywords": null,
// "settings": {
// "label": "",
// "layout": "LAYOUT:horizontal-TYPE:Default-MAX:1",
// "template": "Article",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": false,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T08:53:59.364384",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T08:57:34.1155"
// },
// {
// "id": 24,
// "siteId": 1,
// "pageId": 4,
// "parentId": null,
// "title": "section1hang",
// "slug": "section1hang",
// "code": "section1hang_doisong",
// "type": 1,
// "content": null,
// "keywords": null,
// "settings": {
// "label": "",
// "layout": "LAYOUT:horizontal-TYPE:Default-MAX:1",
// "template": "Article",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": false,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T08:53:52.871306",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T09:39:00.332127"
// }
// ],
// "components": [
// {
// "id": 101,
// "siteId": 1,
// "pageId": 4,
// "sectionId": null,
// "title": "ads2_doisong",
// "code": "ads2_doisong",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "ADS_DEFAULT",
// "template": "Other",
// "dataQuery": null,
// "dataResult": "",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": true,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-06-04T15:44:49.728501",
// "updatedBy": 1,
// "updatedOn": "2024-06-04T15:45:02.192997"
// },
// {
// "id": 69,
// "siteId": 1,
// "pageId": 4,
// "sectionId": null,
// "title": "coppy_link_2",
// "code": "coppy_link_2",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "ARTICLE_BUTTON",
// "template": "Other",
// "dataQuery": null,
// "dataResult": "",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": true,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T15:51:28.699877",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T16:19:00.334897"
// },
// {
// "id": 68,
// "siteId": 1,
// "pageId": 4,
// "sectionId": null,
// "title": "article_detail_1",
// "code": "article_detail_1",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "ARTICLE_DETAIL_DEFAULT",
// "template": "Other",
// "dataQuery": null,
// "dataResult": "",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": true,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T15:37:58.099224",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T16:19:00.742949"
// },
// {
// "id": 62,
// "siteId": 1,
// "pageId": 4,
// "sectionId": null,
// "title": "coppy_link_1",
// "code": "coppy_link_1",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "ARTICLE_DETAIL_DEFAULT",
// "template": "Other",
// "dataQuery": null,
// "dataResult": "",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": false,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": -1,
// "createdBy": 1,
// "createdOn": "2024-05-30T15:24:08.987936",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T15:25:38.566902"
// },
// {
// "id": 58,
// "siteId": 1,
// "pageId": 4,
// "sectionId": null,
// "title": "ads_1",
// "code": "ads_1",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "ADS_DEFAULT",
// "template": "Other",
// "dataQuery": null,
// "dataResult": "",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": true,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T15:09:08.953513",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T16:19:01.56169"
// },
// {
// "id": 57,
// "siteId": 1,
// "pageId": 4,
// "sectionId": null,
// "title": "breadcrumb_1",
// "code": "breadcrumb_1",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "BREADCRUM_DEFAULT",
// "template": "Other",
// "dataQuery": null,
// "dataResult": "",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": true,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T15:01:25.190114",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T16:19:01.972624"
// },
// {
// "id": 50,
// "siteId": 1,
// "pageId": 4,
// "sectionId": null,
// "title": "comment",
// "code": "comment_default1",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "COMMENT",
// "template": "Other",
// "dataQuery": null,
// "dataResult": "",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": true,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T11:37:42.957585",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T11:38:23.481239"
// },
// {
// "id": 47,
// "siteId": 1,
// "pageId": 4,
// "sectionId": null,
// "title": "collection_paging",
// "code": "collection_paging_doisong",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "DEFAULT",
// "template": "Section",
// "dataQuery": "Get[Article] Top[10] With[Categories:81]",
// "dataResult": "[]",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": false,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T09:49:48.945226",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T16:19:02.788055"
// },
// {
// "id": 44,
// "siteId": 1,
// "pageId": 4,
// "sectionId": null,
// "title": "collection5item2",
// "code": "collection5item2_doisong",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "TYPE:Article-LAYOUT:vertical-DATA:HORIZONTAL-MAX:5",
// "template": "Collection",
// "dataQuery": null,
// "dataResult": "",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": true,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T09:18:53.361283",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T16:19:03.20532"
// },
// {
// "id": 43,
// "siteId": 1,
// "pageId": 4,
// "sectionId": null,
// "title": "article_doc",
// "code": "article_doc_doisong",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "LAYOUT:vertical",
// "template": "Article",
// "dataQuery": null,
// "dataResult": "",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": false,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T09:18:26.503605",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T16:19:03.613773"
// },
// {
// "id": 42,
// "siteId": 1,
// "pageId": 4,
// "sectionId": null,
// "title": "collection5item",
// "code": "collection5item_doisong",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "TYPE:Article-LAYOUT:vertical-DATA:HORIZONTAL-MAX:5",
// "template": "Collection",
// "dataQuery": null,
// "dataResult": "",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": false,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T09:17:57.798722",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T16:19:04.026497"
// },
// {
// "id": 41,
// "siteId": 1,
// "pageId": 4,
// "sectionId": null,
// "title": "article_doc_intro3",
// "code": "article_doc_intro3_doisong",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "LAYOUT:vertical-HIDE:paragraph",
// "template": "Article",
// "dataQuery": null,
// "dataResult": "",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": false,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T09:17:21.675354",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T16:19:04.431454"
// },
// {
// "id": 40,
// "siteId": 1,
// "pageId": 4,
// "sectionId": null,
// "title": "article_doc_intro2",
// "code": "article_doc_intro2_doisong",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "LAYOUT:vertical-HIDE:paragraph",
// "template": "Article",
// "dataQuery": null,
// "dataResult": "",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": false,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T09:16:56.07848",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T16:19:04.842294"
// },
// {
// "id": 39,
// "siteId": 1,
// "pageId": 4,
// "sectionId": null,
// "title": "article_doc_intro1",
// "code": "article_doc_intro1_doisong",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "LAYOUT:vertical-HIDE:paragraph",
// "template": "Article",
// "dataQuery": null,
// "dataResult": "",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": false,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T09:16:39.074945",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T16:19:05.246938"
// },
// {
// "id": 38,
// "siteId": 1,
// "pageId": 4,
// "sectionId": null,
// "title": "article_ngang",
// "code": "article_ngang_doisong",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "LAYOUT:horizontal",
// "template": "Article",
// "dataQuery": null,
// "dataResult": "",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": false,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T09:15:38.638781",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T16:19:05.664736"
// },
// {
// "id": 37,
// "siteId": 1,
// "pageId": 4,
// "sectionId": null,
// "title": "category",
// "code": "category_doisong",
// "type": 1,
// "content": null,
// "keywords": "",
// "settings": {
// "label": "",
// "layout": "DEFAULT",
// "template": "Category",
// "dataQuery": null,
// "dataResult": "",
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": false,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": null,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T09:14:11.978206",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T16:19:06.0724"
// }
// ],
// "id": 4,
// "siteId": 1,
// "parentId": null,
// "title": "Trang đời sống",
// "slug": "trang-doi-song",
// "code": "page-doi-song",
// "type": 1,
// "content": null,
// "favicon": null,
// "keywords": null,
// "thumbnail": null,
// "settings": {
// "label": "",
// "layout": "Center_Page",
// "template": "Home",
// "dataQuery": null,
// "dataResult": null,
// "pinned": null
// },
// "features": "Navigation",
// "taxonomy": "Navigation",
// "description": null,
// "isPublished": false,
// "publishedBy": null,
// "publishedOn": null,
// "expiresOn": null,
// "order": 0,
// "status": 6,
// "createdBy": 1,
// "createdOn": "2024-05-30T08:42:10.319911",
// "updatedBy": 1,
// "updatedOn": "2024-05-30T16:18:55.254121"
// })
currentPage.value = {} currentPage.value = {}
currentPage.value = data.value currentPage.value = value
setSectionPublished();
setComponentPublished();
} catch (error: any) {} } catch (error: any) {}
} }
@@ -885,27 +28,25 @@ export const useDynamicPageStore = defineStore("dynamicPageStore", () => {
const setSectionPublished = () => { const setSectionPublished = () => {
const exsitsTemplate = ['None'] const exsitsTemplate = ['None']
const contentArr: any = []; const contentArr: any = [];
currentPage.value.sections && currentPage.value.sections.map((section: any) => { currentPage.value.sections && currentPage.value.sections.map((section: any) => {
contentArr.push(section.content && typeof section.content === 'string' && JSON.parse(section.content)); contentArr.push(section.content && typeof section.content === 'string' && JSON.parse(section.content));
return section; return section;
}); });
sectionPublished.value = currentPage.value.sections && currentPage.value.sections.filter(
sectionPublished.value = currentPage.value.sections && currentPage.value.sections.filter( (section: any) => !exsitsTemplate.includes(section.settings?.template) && section.isPublished && !contentArr.flat().some((_section: any) => _section && _section.data && _section.type === "section" && section.id === _section.data)
(section: any) => exsitsTemplate.includes(section.settings?.template) && section.isPublished && !contentArr.flat().some((_section: any) => _section && _section.data && _section.type === "section" && section.id === _section.data) ).sort((a: any, b: any) => a.order - b.order);
).sort((a: any, b: any) => a.order - b.order);
}; };
const setComponentPublished = () => { const setComponentPublished = () => {
const exsitsTemplate = ['None'] const contentArr: any = [];
const contentArr: any = []; currentPage.value.sections && currentPage.value.sections.map((section: any) => {
currentPage.value.sections && currentPage.value.sections.map((section: any) => { contentArr.push(section.content && JSON.parse(section.content) && JSON.parse(section.content));
contentArr.push(section.content && JSON.parse(section.content) && JSON.parse(section.content)); return section;
return section; });
}); componentPublished.value = currentPage.value.components && currentPage.value.components.filter((section: any) => section.isPublished);
componentPublished.value = currentPage.value.components && currentPage.value.components.filter((section: any) => section.isPublished); };
};
const setDataQuery = (query: any, componentId: number | string) => { const setDataQuery = (query: any, componentId: number | string) => {
for (const _component of currentPage.value.components && currentPage.value.components) { for (const _component of currentPage.value.components && currentPage.value.components) {
+9
View File
@@ -0,0 +1,9 @@
const isEmpty = (value : any) => {
return (
value == null || // From standard.js: Always use === - but obj == null is allowed to check null || undefined
(typeof value === 'object' && Object.keys(value).length === 0) ||
(typeof value === 'string' && value.trim().length === 0)
)
}
export { isEmpty }
+1 -1
View File
@@ -1,4 +1,4 @@
import isEmpty from "lodash/isEmpty"; import { isEmpty } from "@/utils/lodash";
const keyMapping = { const keyMapping = {
// 3 query key để phân loại // 3 query key để phân loại
+1 -3
View File
@@ -1,7 +1,5 @@
import cloneDeep from 'lodash/cloneDeep';
export function buildTree(data: any) { export function buildTree(data: any) {
const _array = cloneDeep(JSON.parse(data)) const _array = JSON.parse(JSON.stringify(JSON.parse(data)))
if (_array.length > 0) { if (_array.length > 0) {
let map = new Map(); let map = new Map();
_array.forEach((item : any) => map.set(item.id, item)); _array.forEach((item : any) => map.set(item.id, item));