diff --git a/pages/admin/tag.vue b/pages/admin/tag.vue new file mode 100644 index 0000000..6a31ecc --- /dev/null +++ b/pages/admin/tag.vue @@ -0,0 +1,124 @@ + + + + + diff --git a/store/tag.js b/store/tag.js new file mode 100644 index 0000000..bbf68f5 --- /dev/null +++ b/store/tag.js @@ -0,0 +1,76 @@ +/** + * @file 分类数据状态 / ES module + * @module store/category + * @author Ronger + */ + +export const ADMIN_API_PATH = '/api/admin' + +const getDefaultListData = () => { + return { + tags: [], + pagination: {} + } +} + +export const state = () => { + return { + fetching: false, + data: [], + list: { + fetching: false, + data: getDefaultListData() + } + } +} + +export const mutations = { + updateListFetching(state, action) { + state.list.fetching = action + }, + updateListData(state, action) { + state.list.data = action + }, + updateFetching(state, action) { + state.fetching = action + }, + updateDetailData(state, action) { + state.data = action + } +} + +export const actions = { + fetchList({commit}, params = {}) { + // 清空已有数据 + commit('updateListData', getDefaultListData()) + commit('updateListFetching', true) + let data = { + page: params.page || 1 + } + + return this.$axios + .$get(`${ADMIN_API_PATH}/tags`, { + params: data + }) + .then(response => { + commit('updateListFetching', false); + commit('updateListData', response); + }) + .catch(error => { + console.log(error); + commit('updateListFetching', false); + }); + }, + fetchDetail({ commit }, params) { + commit('updateFetching', true); + return this.$axios + .$get(`${ADMIN_API_PATH}/tag/${params.tag_id}`) + .then(response => { + commit('updateDetailData', response) + commit('updateFetching', false) + }) + .catch(error => { + commit('updateFetching', false) + }) + } +}