feat: create by site
This commit is contained in:
+3
-3
@@ -13,9 +13,9 @@ const store = reactive({
|
|||||||
await store.category.fetchBySiteId()
|
await store.category.fetchBySiteId()
|
||||||
|
|
||||||
const { data } = await useAsyncData('index', () => store.dynamicPage.fetchPageByCode(route.path === '/' ? 'trang-chu' : route.path.replace('/', '')))
|
const { data } = await useAsyncData('index', () => store.dynamicPage.fetchPageByCode(route.path === '/' ? 'trang-chu' : route.path.replace('/', '')))
|
||||||
const asycnCurrentPage = data.value.currentPage;
|
const asycnCurrentPage = data.value && data.value.currentPage;
|
||||||
const asycnSectionPublished = data.value.sectionPublished;
|
const asycnSectionPublished = data.value && data.value.sectionPublished;
|
||||||
const asycnComponentPublished = data.value.componentPublished;
|
const asycnComponentPublished = data.value && data.value.componentPublished;
|
||||||
|
|
||||||
useHead({
|
useHead({
|
||||||
title: () => 'Trang chủ',
|
title: () => 'Trang chủ',
|
||||||
|
|||||||
@@ -63,9 +63,10 @@ export const getArticleById = async (event : any) => {
|
|||||||
try {
|
try {
|
||||||
const { apiUrl } = useRuntimeConfig().public
|
const { apiUrl } = useRuntimeConfig().public
|
||||||
const id = event.context.params.id;
|
const id = event.context.params.id;
|
||||||
|
const query = getQuery(event)
|
||||||
const { item }: any = await $fetch(`${apiUrl}/cms/digital-article/${id}`, {
|
const { item }: any = await $fetch(`${apiUrl}/cms/digital-article/${id}`, {
|
||||||
headers: new Headers({
|
headers: new Headers({
|
||||||
site: '1' || 1,
|
site: getSite(query.site).toString(),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -79,9 +80,10 @@ export const getArticleBySlug = async (event : any) => {
|
|||||||
try {
|
try {
|
||||||
const { apiUrl } = useRuntimeConfig().public
|
const { apiUrl } = useRuntimeConfig().public
|
||||||
const slug = event.context.params.slug;
|
const slug = event.context.params.slug;
|
||||||
|
const query = getQuery(event)
|
||||||
const { item }: any = await $fetch(`${apiUrl}/cms/digital-article/slug:${slug}`, {
|
const { item }: any = await $fetch(`${apiUrl}/cms/digital-article/slug:${slug}`, {
|
||||||
headers: new Headers({
|
headers: new Headers({
|
||||||
site: '1' || 1,
|
site: getSite(query.site).toString(),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
return { item }
|
return { item }
|
||||||
@@ -93,17 +95,17 @@ export const getArticleBySlug = async (event : any) => {
|
|||||||
export const listArticleCondition = async (event: H3Event) => {
|
export const listArticleCondition = async (event: H3Event) => {
|
||||||
try {
|
try {
|
||||||
const payload = await readBody<any>(event)
|
const payload = await readBody<any>(event)
|
||||||
const { apiUrl } = useRuntimeConfig().public
|
const { apiUrl } = useRuntimeConfig().public;
|
||||||
|
const query = getQuery(event)
|
||||||
const { items }: any = await $fetch(`${apiUrl}/cms/article/condition`, {
|
const { items }: any = await $fetch(`${apiUrl}/cms/article/condition`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: new Headers({
|
headers: new Headers({
|
||||||
site: '1' || 1,
|
site: getSite(query.site).toString(),
|
||||||
}),
|
}),
|
||||||
body: {
|
body: {
|
||||||
payload
|
payload
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// log(event)
|
|
||||||
|
|
||||||
return items
|
return items
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -17,12 +17,13 @@ export type Author = {
|
|||||||
export const fetchByCode = async (event: H3Event) => {
|
export const fetchByCode = async (event: H3Event) => {
|
||||||
try {
|
try {
|
||||||
const { apiUrl } = useRuntimeConfig().public
|
const { apiUrl } = useRuntimeConfig().public
|
||||||
const { authorCode }: any = getQuery(event)
|
const { authorCode }: any = getQuery(event);
|
||||||
|
const query = getQuery(event)
|
||||||
const { items }: any = await $fetch(`${apiUrl}/cms/author/code:${authorCode}`, {
|
const { items }: any = await $fetch(`${apiUrl}/cms/author/code:${authorCode}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: new Headers({
|
||||||
site: 1
|
site: getSite(query.site).toString(),
|
||||||
}
|
}),
|
||||||
})
|
})
|
||||||
return items[0]
|
return items[0]
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -28,15 +28,15 @@ export type CategoryTree = Category & {
|
|||||||
children?: Category[]
|
children?: Category[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const list = async () => {
|
export const list = async (event : H3Event) => {
|
||||||
try {
|
try {
|
||||||
const { site, apiUrl } = useRuntimeConfig().public;
|
const { site, apiUrl } = useRuntimeConfig().public;
|
||||||
|
const query = getQuery(event)
|
||||||
const { items }: CategoryTree[] | any = await $fetch(`${apiUrl}/cms/category/tree/site:1`, {
|
const { items }: CategoryTree[] | any = await $fetch(`${apiUrl}/cms/category/tree/site:1`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: new Headers({
|
||||||
site: 1,
|
site: getSite(query.site).toString(),
|
||||||
},
|
}),
|
||||||
});
|
});
|
||||||
return { items } ;
|
return { items } ;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -101,11 +101,13 @@ export const getDynamicPageByCode = async (event: any) => {
|
|||||||
try {
|
try {
|
||||||
const { apiUrl } = useRuntimeConfig().public
|
const { apiUrl } = useRuntimeConfig().public
|
||||||
const slug = event.context.params.slug;
|
const slug = event.context.params.slug;
|
||||||
|
const query = getQuery(event)
|
||||||
const { item }: any = await $fetch(`${apiUrl}/cms/page/overview-page/slug:${slug}`, {
|
const { item }: any = await $fetch(`${apiUrl}/cms/page/overview-page/slug:${slug}`, {
|
||||||
headers: new Headers({
|
headers: new Headers({
|
||||||
site: '1' || 1,
|
site: getSite(query.site).toString(),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
console.log(getSite(query.site))
|
||||||
return item
|
return item
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error);
|
handleError(error);
|
||||||
@@ -116,7 +118,12 @@ export const getDynamicPageById = async (event: any) => {
|
|||||||
try {
|
try {
|
||||||
const { apiUrl } = useRuntimeConfig().public
|
const { apiUrl } = useRuntimeConfig().public
|
||||||
const id = event.context.params.id;
|
const id = event.context.params.id;
|
||||||
const { item }: any = await $fetch(`${apiUrl}/cms/overview-page/${id}`)
|
const query = getQuery(event)
|
||||||
|
const { item }: any = await $fetch(`${apiUrl}/cms/overview-page/${id}`, {
|
||||||
|
headers: new Headers({
|
||||||
|
site: getSite(query.site).toString(),
|
||||||
|
}),
|
||||||
|
})
|
||||||
return item
|
return item
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error);
|
handleError(error);
|
||||||
@@ -126,10 +133,12 @@ export async function getOverviewPageComponentById(event: any) {
|
|||||||
try {
|
try {
|
||||||
const { apiUrl } = useRuntimeConfig().public
|
const { apiUrl } = useRuntimeConfig().public
|
||||||
const { componentId, dataQuery } = getQuery(event)
|
const { componentId, dataQuery } = getQuery(event)
|
||||||
|
const query = getQuery(event)
|
||||||
return await $fetch(`${apiUrl}/cms/overview-page-component/${componentId}`, {
|
return await $fetch(`${apiUrl}/cms/overview-page-component/${componentId}`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
site: getSite(query.site).toString(),
|
||||||
},
|
},
|
||||||
body: dataQuery,
|
body: dataQuery,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -21,11 +21,12 @@ export const fetchByCode = async(event: H3Event) => {
|
|||||||
try {
|
try {
|
||||||
const { apiUrl } = useRuntimeConfig().public
|
const { apiUrl } = useRuntimeConfig().public
|
||||||
const { eventCode }: any = getQuery(event)
|
const { eventCode }: any = getQuery(event)
|
||||||
|
const query = getQuery(event)
|
||||||
const { item }: any = await $fetch(`${apiUrl}/cms/event/code:${eventCode}`, {
|
const { item }: any = await $fetch(`${apiUrl}/cms/event/code:${eventCode}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: new Headers({
|
||||||
Site: 1
|
site: getSite(query.site).toString(),
|
||||||
}
|
}),
|
||||||
})
|
})
|
||||||
return item
|
return item
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -37,11 +38,12 @@ export const fetchById = async(event: H3Event) => {
|
|||||||
try {
|
try {
|
||||||
const { apiUrl } = useRuntimeConfig().public
|
const { apiUrl } = useRuntimeConfig().public
|
||||||
const { eventId }: any = getQuery(event)
|
const { eventId }: any = getQuery(event)
|
||||||
|
const query = getQuery(event);
|
||||||
const { item }: any = await $fetch(`${apiUrl}/cms/event/${eventId}`, {
|
const { item }: any = await $fetch(`${apiUrl}/cms/event/${eventId}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: new Headers({
|
||||||
Site: 1
|
site: getSite(query.site).toString(),
|
||||||
}
|
}),
|
||||||
})
|
})
|
||||||
return item
|
return item
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
export const getSite = (dns : any) => {
|
||||||
|
const SITE = {
|
||||||
|
DEFAULT: 1,
|
||||||
|
KINHTEDOTHI: 'kinhtedothi',
|
||||||
|
}
|
||||||
|
let site = null;
|
||||||
|
switch (dns) {
|
||||||
|
case SITE.KINHTEDOTHI:
|
||||||
|
site = 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
site = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return site;
|
||||||
|
}
|
||||||
+17
-3
@@ -5,9 +5,16 @@ export const useArticleStore = defineStore("article", () => {
|
|||||||
const currentArticle = ref<any>({});
|
const currentArticle = ref<any>({});
|
||||||
const currentArticles = ref<any[]>([])
|
const currentArticles = ref<any[]>([])
|
||||||
|
|
||||||
|
const url : any = useRequestURL();
|
||||||
|
const host = url.hostname.split('.')[0];
|
||||||
|
|
||||||
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}`, {
|
||||||
|
query: {
|
||||||
|
site: host
|
||||||
|
}
|
||||||
|
})
|
||||||
currentArticle.value = {}
|
currentArticle.value = {}
|
||||||
currentArticle.value = data.value.item
|
currentArticle.value = data.value.item
|
||||||
} catch (error: any) { }
|
} catch (error: any) { }
|
||||||
@@ -15,7 +22,11 @@ export const useArticleStore = defineStore("article", () => {
|
|||||||
|
|
||||||
const getArticleBySlug = async (slug: string) => {
|
const getArticleBySlug = async (slug: string) => {
|
||||||
try {
|
try {
|
||||||
const article = await $fetch(`/api/articles/get-by-slug/${slug}`)
|
const article = await $fetch(`/api/articles/get-by-slug/${slug}`, {
|
||||||
|
query: {
|
||||||
|
site: host
|
||||||
|
}
|
||||||
|
})
|
||||||
currentArticle.value = {}
|
currentArticle.value = {}
|
||||||
currentArticle.value = article?.item
|
currentArticle.value = article?.item
|
||||||
|
|
||||||
@@ -27,7 +38,10 @@ export const useArticleStore = defineStore("article", () => {
|
|||||||
try {
|
try {
|
||||||
const { data: articles } = await useFetch(`/api/articles/condition`, {
|
const { data: articles } = await useFetch(`/api/articles/condition`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: condition
|
body: condition,
|
||||||
|
query: {
|
||||||
|
site: host
|
||||||
|
}
|
||||||
})
|
})
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
|
||||||
|
|||||||
+10
-2
@@ -1,10 +1,14 @@
|
|||||||
import { defineStore, acceptHMRUpdate } from "pinia";
|
import { defineStore, acceptHMRUpdate } from "pinia";
|
||||||
import { useLocalStorage } from "@vueuse/core";
|
import { useLocalStorage } from "@vueuse/core";
|
||||||
|
|
||||||
export const useDynamicPageStore = defineStore("dynamicPageStore", () => {
|
export const useDynamicPageStore = defineStore("dynamicPageStore", () => {
|
||||||
const currentPage = ref<any>({});
|
const currentPage = ref<any>({});
|
||||||
const sectionPublished = ref<any[]>([]);
|
const sectionPublished = ref<any[]>([]);
|
||||||
const componentPublished = ref<any[]>([]);
|
const componentPublished = ref<any[]>([]);
|
||||||
|
|
||||||
|
const url : any = useRequestURL();
|
||||||
|
const host = url.hostname.split('.')[0];
|
||||||
|
|
||||||
const setSectionPublished = () => {
|
const setSectionPublished = () => {
|
||||||
const exsitsTemplate = ['None']
|
const exsitsTemplate = ['None']
|
||||||
const contentArr: any = [];
|
const contentArr: any = [];
|
||||||
@@ -45,7 +49,11 @@ export const useDynamicPageStore = defineStore("dynamicPageStore", () => {
|
|||||||
|
|
||||||
async function fetchPageByCode(slug: any) {
|
async function fetchPageByCode(slug: any) {
|
||||||
try {
|
try {
|
||||||
const page = await $fetch(`/api/dynamic-page/get-by-code/${slug}`)
|
const page = await $fetch(`/api/dynamic-page/get-by-code/${slug}`, {
|
||||||
|
query: {
|
||||||
|
site: host
|
||||||
|
}
|
||||||
|
})
|
||||||
currentPage.value = {}
|
currentPage.value = {}
|
||||||
currentPage.value = page
|
currentPage.value = page
|
||||||
|
|
||||||
@@ -60,7 +68,7 @@ export const useDynamicPageStore = defineStore("dynamicPageStore", () => {
|
|||||||
} catch (error: any) {}
|
} catch (error: any) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getOverviewPageComponentById(componentId, dataQuery) {
|
async function getOverviewPageComponentById(componentId: any, dataQuery: any) {
|
||||||
try {
|
try {
|
||||||
const { apiUrl } = useRuntimeConfig().public
|
const { apiUrl } = useRuntimeConfig().public
|
||||||
const res = await $fetch(`${apiUrl}/cms/page-component/overview-page-component/${componentId}`, {
|
const res = await $fetch(`${apiUrl}/cms/page-component/overview-page-component/${componentId}`, {
|
||||||
|
|||||||
Reference in New Issue
Block a user