export const useCategoriesStore = defineStore('categories', () => { const tree = ref([]); const tags = ref([]); async function fetchCategories() { const res = await $fetch('/api/categories'); if (res.code === 0) tree.value = res.data; } async function fetchTags() { const res = await $fetch('/api/tags'); if (res.code === 0) tags.value = res.data; } async function createCategory(data: any) { const res = await $fetch('/api/categories', { method: 'POST', body: data, }); if (res.code === 0) await fetchCategories(); return res; } const topTags = computed(() => { return tags.value .filter((t: any) => t.itemCount > 0) .sort((a: any, b: any) => b.itemCount - a.itemCount) .slice(0, 10); }); return { tree, tags, fetchCategories, fetchTags, createCategory, topTags }; });