You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
742 B
33 lines
742 B
import { listCategory } from '~/api/category'
|
|
import { categoryToTrees } from '~/utils/utils'
|
|
export const category = {
|
|
namespaced: true,
|
|
state: {
|
|
categories: [],
|
|
},
|
|
mutations: {
|
|
setCategories(state, categories) {
|
|
state.categories = categories || []
|
|
},
|
|
},
|
|
actions: {
|
|
async getCategories({ commit }) {
|
|
const res = await listCategory({
|
|
field: ['id', 'title', 'parent_id', 'cover', 'doc_count', 'enable'],
|
|
})
|
|
if (res.status === 200) {
|
|
commit('setCategories', res.data.category)
|
|
}
|
|
return res
|
|
},
|
|
},
|
|
getters: {
|
|
categories(state) {
|
|
return state.categories
|
|
},
|
|
categoryTrees(state) {
|
|
return categoryToTrees(state.categories)
|
|
},
|
|
},
|
|
}
|