2024-06-04 15:03:54 +07:00
|
|
|
interface ArticleCondition {
|
|
|
|
|
ids?: number[]
|
|
|
|
|
}
|
2024-05-31 00:46:43 +07:00
|
|
|
export const useArticleStore = defineStore("article", () => {
|
|
|
|
|
const currentArticle = ref<any>({});
|
2024-06-04 15:03:54 +07:00
|
|
|
const currentArticles = ref<any[]>([])
|
2024-05-31 00:46:43 +07:00
|
|
|
|
|
|
|
|
const getArticleById = async (id: string | number) => {
|
|
|
|
|
try {
|
2024-05-31 12:39:53 +07:00
|
|
|
|
|
|
|
|
const { data} = await useFetch(`/api/articles/get-by-id/${id}`)
|
2024-05-31 00:46:43 +07:00
|
|
|
currentArticle.value = {}
|
2024-05-31 12:39:53 +07:00
|
|
|
currentArticle.value = data.value.item
|
2024-05-31 00:46:43 +07:00
|
|
|
} catch (error: any) {}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-31 15:04:22 +07:00
|
|
|
const getArticleBySlug = async (slug: string) => {
|
2024-05-31 13:49:36 +07:00
|
|
|
try {
|
2024-06-03 10:24:28 +07:00
|
|
|
const { data: article } = await useAsyncData('article', () => $fetch(`/api/articles/get-by-slug/${slug}`))
|
2024-05-31 13:49:36 +07:00
|
|
|
currentArticle.value = {}
|
2024-06-03 10:24:28 +07:00
|
|
|
currentArticle.value = article.value?.item
|
2024-05-31 13:49:36 +07:00
|
|
|
} catch (error: any) {}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-04 15:03:54 +07:00
|
|
|
const getArticleCondition = async (condition: ArticleCondition) => {
|
|
|
|
|
try {
|
|
|
|
|
const { data: articles } = await useFetch(`/api/articles/condition`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: condition
|
|
|
|
|
})
|
|
|
|
|
console.log(articles, 'data')
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-31 00:46:43 +07:00
|
|
|
return {
|
|
|
|
|
currentArticle,
|
2024-05-31 13:49:36 +07:00
|
|
|
getArticleById,
|
2024-06-04 15:03:54 +07:00
|
|
|
getArticleBySlug,
|
|
|
|
|
getArticleCondition
|
2024-05-31 00:46:43 +07:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
import.meta.hot && import.meta.hot.accept(acceptHMRUpdate(useArticleStore, import.meta.hot));
|