From 28bbaab8cdd97a776d59c214bee4589d548cd979 Mon Sep 17 00:00:00 2001 From: x ronger Date: Tue, 11 Aug 2020 22:39:12 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=90=8E=E5=8F=B0=E7=AE=A1?= =?UTF-8?q?=E7=90=86-=E6=A0=87=E7=AD=BE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/admin/tag.vue | 124 ++++++++++++++++++++++++++++++++++++++++++++ store/tag.js | 76 +++++++++++++++++++++++++++ 2 files changed, 200 insertions(+) create mode 100644 pages/admin/tag.vue create mode 100644 store/tag.js 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) + }) + } +}