phongdt:page video
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { LocationQuery } from "vue-router";
|
||||
import { defineStore, acceptHMRUpdate } from "pinia";
|
||||
|
||||
export const useEventStore = defineStore('event', () => {
|
||||
|
||||
const pagination = ref({
|
||||
page: utils.toNumber(useRuntimeConfig().public.pagingDefault),
|
||||
limit: utils.toNumber(useRuntimeConfig().public.pagingLimit),
|
||||
total: 0,
|
||||
});
|
||||
|
||||
function setStateFromRoute(query: LocationQuery) {
|
||||
if (query.page) pagination.value.page = utils.toNumber(query.page)
|
||||
else pagination.value.page = utils.toNumber(useRuntimeConfig().public.pagingDefault);
|
||||
if (query.limit) pagination.value.limit = utils.toNumber(query.limit)
|
||||
else pagination.value.limit = utils.toNumber(useRuntimeConfig().public.pagingLimit);
|
||||
}
|
||||
|
||||
async function listPaging(siteId: number, page: number, fetch: number) {
|
||||
const { data, error } = await useFetch<any>(`/api/services/events-paging?siteId=${siteId}&page=${page}&fetch=${fetch}`)
|
||||
if (error.value) {
|
||||
return null
|
||||
}
|
||||
return data.value
|
||||
}
|
||||
|
||||
async function fetchById(id: string) {
|
||||
const { data, error } = await useFetch<any>(`/api/services/event`, {
|
||||
query: {
|
||||
eventId: id
|
||||
}
|
||||
})
|
||||
if(error.value) {
|
||||
return null
|
||||
}
|
||||
|
||||
return data.value
|
||||
}
|
||||
|
||||
return { listPaging, fetchById, setStateFromRoute, pagination }
|
||||
})
|
||||
|
||||
if (import.meta.hot) {
|
||||
import.meta.hot.accept(acceptHMRUpdate(useEventStore, import.meta.hot))
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
export const useTagStore = defineStore('tag', () => {
|
||||
// async function fetchByCode(code: string) {
|
||||
// const { data, error } = await useFetch<any>(`/api/services/tag`, { query: {code: code}})
|
||||
// if(error.value) {
|
||||
// return null
|
||||
// }
|
||||
// return data.value[0]
|
||||
// }
|
||||
|
||||
async function fetchById(id: string) {
|
||||
const { data, error } = await useFetch<any>(`/api/services/tag`, {
|
||||
query: {
|
||||
tagId: id
|
||||
}
|
||||
})
|
||||
if(error.value) {
|
||||
return null
|
||||
}
|
||||
|
||||
return data.value
|
||||
}
|
||||
|
||||
return { fetchById }
|
||||
})
|
||||
|
||||
if(import.meta.hot) {
|
||||
import.meta.hot.accept(acceptHMRUpdate(useTagStore, import.meta.hot))
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { LocationQuery } from "vue-router";
|
||||
import { defineStore, acceptHMRUpdate } from "pinia";
|
||||
|
||||
export const useTopicStore = defineStore('topic', () => {
|
||||
const pagination = ref({
|
||||
page: utils.toNumber(useRuntimeConfig().public.pagingDefault),
|
||||
limit: utils.toNumber(useRuntimeConfig().public.pagingLimit),
|
||||
total: 0,
|
||||
});
|
||||
|
||||
function setStateFromRoute(query: LocationQuery) {
|
||||
if (query.page) pagination.value.page = utils.toNumber(query.page)
|
||||
else pagination.value.page = utils.toNumber(useRuntimeConfig().public.pagingDefault);
|
||||
if (query.limit) pagination.value.limit = utils.toNumber(query.limit)
|
||||
else pagination.value.limit = utils.toNumber(useRuntimeConfig().public.pagingLimit);
|
||||
}
|
||||
|
||||
async function fetchById(topicId: string) {
|
||||
const { data, error } = await useFetch<any>(`/api/services/topic`, {
|
||||
query: {
|
||||
topicId: topicId
|
||||
}
|
||||
})
|
||||
if(error.value) {
|
||||
return null
|
||||
}
|
||||
|
||||
return data.value
|
||||
}
|
||||
|
||||
async function fetchByCategoryId(categoryId: number, limit?: number) {
|
||||
if(limit) {
|
||||
pagination.value.limit = limit
|
||||
}
|
||||
const { data, error } = await useFetch<any>(`/api/services/topics-paging`, {
|
||||
query: {
|
||||
categoryId: categoryId,
|
||||
limit: pagination.value.limit,
|
||||
page: pagination.value.page,
|
||||
sort: 'createdon desc'
|
||||
}
|
||||
})
|
||||
if(error.value) {
|
||||
return null
|
||||
}
|
||||
|
||||
return data.value.items
|
||||
}
|
||||
|
||||
return { pagination, setStateFromRoute, fetchById, fetchByCategoryId }
|
||||
})
|
||||
|
||||
if (import.meta.hot) {
|
||||
import.meta.hot.accept(acceptHMRUpdate(useTopicStore, import.meta.hot))
|
||||
}
|
||||
Reference in New Issue
Block a user