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
|
|
|
|
2024-07-15 21:02:22 +07:00
|
|
|
const url : any = useRequestURL();
|
|
|
|
|
const host = url.hostname.split('.')[0];
|
|
|
|
|
|
2024-05-31 00:46:43 +07:00
|
|
|
const getArticleById = async (id: string | number) => {
|
|
|
|
|
try {
|
2024-07-15 21:02:22 +07:00
|
|
|
const { data } = await useFetch(`/api/articles/get-by-id/${id}`, {
|
|
|
|
|
query: {
|
|
|
|
|
site: host
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-05-31 00:46:43 +07:00
|
|
|
currentArticle.value = {}
|
2024-05-31 12:39:53 +07:00
|
|
|
currentArticle.value = data.value.item
|
2024-06-21 09:56:34 +07:00
|
|
|
} catch (error: any) { }
|
2024-05-31 00:46:43 +07:00
|
|
|
}
|
|
|
|
|
|
2024-05-31 15:04:22 +07:00
|
|
|
const getArticleBySlug = async (slug: string) => {
|
2024-05-31 13:49:36 +07:00
|
|
|
try {
|
2024-07-15 21:02:22 +07:00
|
|
|
const article = await $fetch(`/api/articles/get-by-slug/${slug}`, {
|
|
|
|
|
query: {
|
|
|
|
|
site: host
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-05-31 13:49:36 +07:00
|
|
|
currentArticle.value = {}
|
2024-06-21 17:51:36 +07:00
|
|
|
currentArticle.value = article?.item
|
2024-06-24 16:46:59 +07:00
|
|
|
|
|
|
|
|
return currentArticle;
|
2024-06-21 09:56:34 +07:00
|
|
|
} catch (error: any) { }
|
2024-05-31 13:49:36 +07:00
|
|
|
}
|
|
|
|
|
|
2024-06-04 15:03:54 +07:00
|
|
|
const getArticleCondition = async (condition: ArticleCondition) => {
|
|
|
|
|
try {
|
|
|
|
|
const { data: articles } = await useFetch(`/api/articles/condition`, {
|
|
|
|
|
method: 'POST',
|
2024-07-15 21:02:22 +07:00
|
|
|
body: condition,
|
|
|
|
|
query: {
|
|
|
|
|
site: host
|
|
|
|
|
}
|
2024-06-04 15:03:54 +07:00
|
|
|
})
|
|
|
|
|
} catch (error: any) {
|
2024-06-21 09:56:34 +07:00
|
|
|
|
2024-06-04 15:03:54 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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));
|