nebula/store/topic.js

78 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-07-31 17:40:17 +08:00
/**
* @file 分类数据状态 / ES module
* @module store/category
2020-08-01 00:39:29 +08:00
* @author Ronger <https://github.com/ronger-x>
2020-07-31 17:40:17 +08:00
*/
export const TOPIC_API_PATH = '/api/topic'
2020-08-11 22:39:59 +08:00
export const ADMIN_API_PATH = '/api/admin'
const getDefaultListData = () => {
return {
topics: [],
pagination: {}
}
}
2020-07-31 17:40:17 +08:00
export const state = () => {
return {
fetching: false,
2020-08-11 22:39:59 +08:00
data: [],
list: {
fetching: false,
data: getDefaultListData()
}
2020-07-31 17:40:17 +08:00
}
}
export const mutations = {
2020-08-11 22:39:59 +08:00
updateListFetching(state, action) {
state.list.fetching = action
},
updateListData(state, action) {
state.list.data = action
},
2020-07-31 17:40:17 +08:00
updateFetching(state, action) {
state.fetching = action
},
2020-08-11 22:39:59 +08:00
updateNavData(state, action) {
2020-07-31 17:40:17 +08:00
state.data = action
}
}
export const actions = {
2020-08-11 22:39:59 +08:00
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) {
2020-08-01 00:39:29 +08:00
commit('updateFetching', true);
2020-07-31 17:40:17 +08:00
return this.$axios
.$get(`${TOPIC_API_PATH}/topic-nav`)
.then(response => {
2020-08-11 22:39:59 +08:00
commit('updateNavData', response)
2020-07-31 17:40:17 +08:00
commit('updateFetching', false)
})
.catch(error => {
commit('updateFetching', false)
})
}
}