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-09-08 07:59:55 +08:00
|
|
|
const getDefaultTagsData = () => {
|
|
|
|
return {
|
|
|
|
tags: [],
|
|
|
|
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-09-08 07:59:55 +08:00
|
|
|
},
|
|
|
|
detail: {
|
|
|
|
fetching: false,
|
|
|
|
data: {}
|
|
|
|
},
|
|
|
|
tags: {
|
|
|
|
fetching: false,
|
|
|
|
data: getDefaultTagsData()
|
2020-08-11 22:39:59 +08:00
|
|
|
}
|
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
|
2020-09-08 07:59:55 +08:00
|
|
|
},
|
|
|
|
updateDetailFetching(state, action) {
|
|
|
|
state.detail.fetching = action
|
|
|
|
},
|
|
|
|
updateDetailData(state, action) {
|
|
|
|
state.detail.data = action
|
|
|
|
},
|
|
|
|
updateTopicTagsFetching(state, action) {
|
|
|
|
state.tags.fetching = action
|
|
|
|
},
|
|
|
|
updateTopicTagsData(state, action) {
|
|
|
|
state.tags.data = action
|
2020-07-31 17:40:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
2020-09-08 07:59:55 +08:00
|
|
|
},
|
|
|
|
fetchDetail({ commit }, params) {
|
|
|
|
commit('updateDetailFetching', true);
|
|
|
|
return this.$axios
|
|
|
|
.$get(`${ADMIN_API_PATH}/topic/${params.topic_uri}`)
|
|
|
|
.then(response => {
|
|
|
|
commit('updateDetailData', response)
|
|
|
|
commit('updateDetailFetching', false)
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
commit('updateDetailFetching', false)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
fetchTopicTags({ commit }, params) {
|
|
|
|
commit('updateTopicTagsFetching', true);
|
|
|
|
return this.$axios
|
|
|
|
.$get(`${ADMIN_API_PATH}/topic/${params.topic_uri}/tags?page=${params.page}`)
|
|
|
|
.then(response => {
|
|
|
|
commit('updateTopicTagsData', response)
|
|
|
|
commit('updateTopicTagsFetching', false)
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
commit('updateTopicTagsFetching', false)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
fetchUnBindTags({ commit }, params) {
|
|
|
|
commit('updateTopicTagsFetching', true);
|
|
|
|
return this.$axios
|
|
|
|
.$get(`${ADMIN_API_PATH}/topic/unbind-topic-tags`, {
|
|
|
|
params: params
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
commit('updateTopicTagsData', response)
|
|
|
|
commit('updateTopicTagsFetching', false)
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
commit('updateTopicTagsFetching', false)
|
|
|
|
})
|
2020-07-31 17:40:17 +08:00
|
|
|
}
|
|
|
|
}
|