diff --git a/pages/admin/topic.vue b/pages/admin/topic.vue new file mode 100644 index 0000000..bbd34f0 --- /dev/null +++ b/pages/admin/topic.vue @@ -0,0 +1,75 @@ + + + + + 首页 + 专题管理 + + + + 创建专题 + + + + + + + + + + + {{ topic.topicTitle }} + + + + {{ topic.topicDescription }} + + + + + + + + + + + + diff --git a/store/index.js b/store/index.js index d0cb5c0..64f05d8 100644 --- a/store/index.js +++ b/store/index.js @@ -69,7 +69,7 @@ export const actions = { const initFetchAppData = [ // 内容数据 - store.dispatch('topic/fetchList'), + store.dispatch('topic/fetchNavList'), store.dispatch('article/fetchList') ] diff --git a/store/topic.js b/store/topic.js index b133e2f..5f73fd7 100644 --- a/store/topic.js +++ b/store/topic.js @@ -5,30 +5,69 @@ */ export const TOPIC_API_PATH = '/api/topic' +export const ADMIN_API_PATH = '/api/admin' + +const getDefaultListData = () => { + return { + topics: [], + pagination: {} + } +} export const state = () => { return { fetching: false, - data: [] + 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 }, - updateListData(state, action) { + updateNavData(state, action) { state.data = action } } export const actions = { - fetchList({ commit }, params) { + fetchList({commit}, params = {}) { + // 清空已有数据 + commit('updateListData', getDefaultListData()) + commit('updateListFetching', true) + let data = { + page: params.page || 1 + } + + return this.$axios + .$get(`${ADMIN_API_PATH}/topics`, { + params: data + }) + .then(response => { + commit('updateListFetching', false); + commit('updateListData', response); + }) + .catch(error => { + console.log(error); + commit('updateListFetching', false); + }); + }, + fetchNavList({ commit }, params) { commit('updateFetching', true); return this.$axios .$get(`${TOPIC_API_PATH}/topic-nav`) .then(response => { - commit('updateListData', response) + commit('updateNavData', response) commit('updateFetching', false) }) .catch(error => {