thainv-dev: tạo lại cấu trúc folder và làm UI

This commit is contained in:
nguyen van thai
2024-06-12 17:17:49 +07:00
parent c217ed82c9
commit 5b1e0af397
44 changed files with 2674 additions and 228 deletions
+92 -62
View File
@@ -1,72 +1,102 @@
import type { Category } from "~/server/models/category";
import type { Category, CategoryTree } from "~/server/models/category";
export const useCategoryStore = defineStore("category-v2", () => {
const categories = ref<Category[]>([]);
// export const useCategoryStore = defineStore("category-v2", () => {
// const categories = ref<Category[]>([]);
// const categoryTree = ref<any[]>([]);
// const currentCategoryTree = ref<any[]>([])
async function fetchCategories() {
const { data, error } = await useFetch<Category[]>("/api/v2/categories");
if (error.value) {
return [] as Category[];
}
// const findBySiteId = async () => {
// try {
// const { data } = await useFetch(`/api/services/category-tree`)
// categoryTree.value = data.value
// return categoryTree.value
// } catch (error) {}
// }
categories.value = Object.assign([], data.value);
// async function fetchCategories() {
// const { data, error } = await useFetch<Category[]>("/api/v2/categories");
// if (error.value) {
// return [] as Category[];
// }
return categories.value;
// categories.value = Object.assign([], data.value);
// return categories.value;
// }
// function findByCode(code?: string) {
// if (code) return categories.value.find((c) => c.code === code);
// }
// function findById(id?: number) {
// return categories.value.find((c) => c.id === id);
// }
// function findParents(category?: Category) {
// if (!category) return [];
// const parents = [];
// let parent = findById(category.parentId);
// while (parent) {
// parents.push(parent);
// parent = findById(parent.parentId);
// }
// return parents.reverse().concat(category);
// }
// function findSubTree(category?: Category) {
// if (!category) return [];
// let subTree = [] as Category[];
// function findChildren(category: Category) {
// const children = categories.value.filter((c:Category) => c.parentId === category.id);
// if (children.length === 0) return;
// subTree.push(...children,category);
// }
// if(category.parentId === 41){
// findChildren(category);
// }else{
// const parent = findById(category.parentId);
// if(parent){
// findChildren(parent);
// }
// }
// return subTree.reverse();
// }
// function findChildren(category: Category) {
// const children = categories.value.filter((c:Category) => c.parentId === category.id);
// if (children.length === 0) return;
// else return [...children]
// }
// return { categories, categoryTree, currentCategoryTree, findBySiteId, fetchCategories, findByCode, findById, findParents,findSubTree, findChildren };
// });
export const useCategoryStore = defineStore('usecategorystore', () => {
const categoryTree = shallowRef<CategoryTree[]>([])
const currentCategoryTree = shallowRef<any[]>([])
async function fetchBySiteId() {
const { data }: any = await useFetch(`/api/services/category-tree`)
categoryTree.value = data.value.items
return categoryTree.value
}
function findByCode(code?: string) {
if (code) return categories.value.find((c) => c.code === code);
return {
categoryTree,
currentCategoryTree,
fetchBySiteId
}
function findById(id?: number) {
return categories.value.find((c) => c.id === id);
}
function findParents(category?: Category) {
if (!category) return [];
const parents = [];
let parent = findById(category.parentId);
while (parent) {
parents.push(parent);
parent = findById(parent.parentId);
}
return parents.reverse().concat(category);
}
function findSubTree(category?: Category) {
if (!category) return [];
let subTree = [] as Category[];
function findChildren(category: Category) {
const children = categories.value.filter((c:Category) => c.parentId === category.id);
if (children.length === 0) return;
subTree.push(...children,category);
}
if(category.parentId === 41){
findChildren(category);
}else{
const parent = findById(category.parentId);
if(parent){
findChildren(parent);
}
}
return subTree.reverse();
}
function findChildren(category: Category) {
const children = categories.value.filter((c:Category) => c.parentId === category.id);
if (children.length === 0) return;
else return [...children]
}
return { categories, fetchCategories, findByCode, findById, findParents,findSubTree, findChildren };
});
})
if (import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useCategoryStore, import.meta.hot));
+863 -15
View File
@@ -10,6 +10,866 @@ export const useDynamicPageStore = defineStore("dynamicPageStore", () => {
async function fetchPageByCode(slug: any) {
try {
const { data } = await useFetch(`/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 = data.value
} catch (error: any) {}
@@ -35,6 +895,8 @@ export const useDynamicPageStore = defineStore("dynamicPageStore", () => {
(section: any) => 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);
console.log(sectionPublished.value, 'section');
};
const setComponentPublished = () => {
@@ -44,7 +906,7 @@ export const useDynamicPageStore = defineStore("dynamicPageStore", () => {
return section;
});
componentPublished.value = currentPage.value.components && currentPage.value.components.filter((section: any) => section.isPublished);
console.log(componentPublished.value ,'123123')
};
const setDataQuery = (query: any, componentId: number | string) => {
@@ -63,30 +925,16 @@ export const useDynamicPageStore = defineStore("dynamicPageStore", () => {
setComponentPublished();
};
function increaseStep(increase: number) {
step.value += increase
return step.value
}
function decreaseStep(decrease: number) {
step.value -= decrease
return step.value
}
return {
currentPage,
sectionPublished,
componentPublished,
step,
fetchPageByCode,
fetchPageById,
setSectionPublished,
setComponentPublished,
setDataQuery,
increaseStep,
decreaseStep,
};
});
+17 -12
View File
@@ -1,20 +1,25 @@
export const usePollOptionStore = defineStore('usepollOptionStore', () => {
import type { PollOption } from "~/server/models/poll-option"
export const usePollOptionStore = defineStore('usePollOptionStore', () => {
const currentPollOption = shallowReactive<PollOption>({})
const currentPollOptions = shallowRef<PollOption[] | any[]>([])
async function fetchByPollId(id: string) {
const { data, error } = await useFetch<any>(`/api/services/poll-option/pollId`, {
query: {
pollId: id
}
})
if(error.value) {
return null
}
try {
const { data } = await useFetch<any>(`/api/services/poll-option/pollId`, {
query: {
pollId: id
}
})
data.value && (currentPollOptions.value = data.value)
return currentPollOptions.value
} catch(error) {}
return data.value
}
return { fetchByPollId }
return { currentPollOptions, fetchByPollId }
})
if(import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useTagStore, import.meta.hot))
import.meta.hot.accept(acceptHMRUpdate(usePollOptionStore, import.meta.hot))
}
+33 -12
View File
@@ -1,19 +1,40 @@
export const usePollResponseStore = defineStore('usepollResponseStore', () => {
async function create(pollResponse: any) {
const { data, error } = await useFetch<any>(`/api/services/poll-response`, {
method: 'POST',
body: pollResponse
})
if(error.value) {
return null
import type { PollResponse } from "~/server/models/poll-response"
export const usePollResponseStore = defineStore('usePollResponseStore', () => {
const currentPollResponse = shallowReactive<PollResponse>({})
const currentPollResponses = shallowRef<PollResponse[]>([])
const create = async (pollResponse: any) => {
try {
const { data } = await useFetch<any>(`/api/services/poll-response`, {
method: 'POST',
body: pollResponse
})
data.value && (Object.assign(currentPollResponse, data.value))
return currentPollResponse
} catch (error) {
}
return data.value
}
return { create }
async function fetchByPollId(id: string) {
try {
const { data } = await useFetch<any>(`/api/services/poll-response/pollId`, {
query: {
pollId: id
}
})
data.value && (currentPollResponses.value = data.value)
return currentPollResponses.value
} catch (error) { }
}
return { currentPollResponse, currentPollResponses, create, fetchByPollId }
})
if(import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useTagStore, import.meta.hot))
if (import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(usePollResponseStore, import.meta.hot))
}
+25 -12
View File
@@ -1,20 +1,33 @@
export const usePollStore = defineStore('usepollStore', () => {
import type { Poll } from "~/server/models/poll"
export const usePollStore = defineStore('usePollStore', () => {
const currentPoll = shallowReactive<Poll>({})
async function fetchById(id: string) {
const { data, error } = await useFetch<any>(`/api/services/poll-by-id`, {
query: {
pollId: id
}
})
if(error.value) {
return null
}
return data.value
try {
const { data } = await useFetch<any>(`/api/services/poll-by-id`, {
query: {
pollId: id
}
})
data.value && (Object.assign(currentPoll, data.value))
return currentPoll
} catch(error) {
}
}
return { fetchById }
async function categoryId() {
try {
const { data } = await useFetch(`/api/services/category-tree`)
return data.value
} catch (error) {}
}
return { fetchById, currentPoll, categoryId }
})
if(import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useTagStore, import.meta.hot))
import.meta.hot.accept(acceptHMRUpdate(usePollStore, import.meta.hot))
}
+24
View File
@@ -0,0 +1,24 @@
import type { Quiz } from '~/server/models/quiz';
export const useQuizStore = defineStore('useQuizStore', () => {
const currentQuiz = shallowReactive<Quiz>({})
async function fetchById(id: number) {
try {
const { data } = await useFetch<any>(`/api/services/quiz/get-by-id`, {
query: {
quizId: id
}
})
data.value && (Object.assign(currentQuiz, data.value))
return currentQuiz
} catch(error) {
}
}
return { fetchById, currentQuiz }
})
if(import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useQuizStore, import.meta.hot))
}
+24
View File
@@ -0,0 +1,24 @@
import type { Survey } from '~/server/models/survey';
export const useSurveyStore = defineStore('useSurveyStore', () => {
const currentSurvey = shallowReactive<Survey>({})
async function fetchById(id: number) {
try {
const { data } = await useFetch<any>(`/api/services/survey/get-by-id`, {
query: {
surveyId: id
}
})
data.value && (Object.assign(currentSurvey, data.value))
return currentSurvey
} catch(error) {
}
}
return { fetchById, currentSurvey }
})
if(import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useSurveyStore, import.meta.hot))
}