2020-08-01 00:41:00 +08:00
|
|
|
/**
|
|
|
|
* @file 用户信息状态 / ES module
|
|
|
|
* @module store/category
|
|
|
|
* @author Ronger <https://github.com/ronger-x>
|
|
|
|
*/
|
|
|
|
|
|
|
|
export const USER_API_PATH = '/api/user'
|
|
|
|
|
|
|
|
export const state = () => {
|
|
|
|
return {
|
|
|
|
fetching: false,
|
|
|
|
data: [],
|
2020-11-09 22:02:00 +08:00
|
|
|
userExtend: {},
|
2020-08-01 00:41:00 +08:00
|
|
|
articles: {
|
|
|
|
articles: [],
|
|
|
|
pagination: {}
|
|
|
|
},
|
|
|
|
portfolios: {
|
|
|
|
portfolios: [],
|
|
|
|
pagination: {}
|
2020-10-25 01:40:24 +08:00
|
|
|
},
|
|
|
|
followers: {
|
|
|
|
users: [],
|
|
|
|
pagination: {}
|
|
|
|
},
|
|
|
|
followings: {
|
|
|
|
users: [],
|
|
|
|
pagination: {}
|
2020-08-01 00:41:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
updateFetching(state, action) {
|
|
|
|
state.fetching = action
|
|
|
|
},
|
|
|
|
updateDetailData(state, action) {
|
|
|
|
state.data = action
|
|
|
|
},
|
2020-11-09 22:02:00 +08:00
|
|
|
updateUserExtendData(state, action) {
|
|
|
|
state.userExtend = action
|
|
|
|
},
|
2020-08-01 00:41:00 +08:00
|
|
|
updateArticleList(state, action) {
|
|
|
|
state.articles = action
|
|
|
|
},
|
|
|
|
updatePortfolioList(state, action) {
|
|
|
|
state.portfolios = action
|
2020-10-25 01:40:24 +08:00
|
|
|
},
|
|
|
|
updateFollowerList(state, action) {
|
|
|
|
state.followers = action
|
|
|
|
},
|
|
|
|
updateFollowingList(state, action) {
|
|
|
|
state.followings = action
|
2020-08-01 00:41:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const actions = {
|
|
|
|
fetchDetail({ commit }, params) {
|
|
|
|
commit('updateFetching', true);
|
|
|
|
return this.$axios
|
2021-03-26 10:44:54 +08:00
|
|
|
.$get(`${USER_API_PATH}/${params.account}`)
|
2020-08-01 00:41:00 +08:00
|
|
|
.then(response => {
|
|
|
|
commit('updateDetailData', response)
|
|
|
|
commit('updateFetching', false)
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
commit('updateFetching', false)
|
|
|
|
})
|
|
|
|
},
|
2020-11-09 22:02:00 +08:00
|
|
|
fetchUserExtend({ commit }, params) {
|
|
|
|
commit('updateFetching', true);
|
|
|
|
return this.$axios
|
2021-03-26 10:44:54 +08:00
|
|
|
.$get(`${USER_API_PATH}/${params.account}/user-extend`)
|
2020-11-09 22:02:00 +08:00
|
|
|
.then(response => {
|
|
|
|
commit('updateUserExtendData', response)
|
|
|
|
commit('updateFetching', false)
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
commit('updateFetching', false)
|
|
|
|
})
|
|
|
|
},
|
2020-08-01 00:41:00 +08:00
|
|
|
fetchArticleList({commit}, params) {
|
2020-08-02 00:25:44 +08:00
|
|
|
commit('updateFetching', true);
|
2020-08-01 00:41:00 +08:00
|
|
|
return this.$axios
|
2021-03-26 10:44:54 +08:00
|
|
|
.$get(`${USER_API_PATH}/${params.account}/articles`, {
|
2020-08-01 00:41:00 +08:00
|
|
|
params: {
|
|
|
|
page: params.page
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
commit('updateArticleList', response)
|
|
|
|
commit('updateFetching', false)
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
commit('updateFetching', false)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
fetchPortfolioList({commit}, params) {
|
2020-08-02 00:25:44 +08:00
|
|
|
commit('updateFetching', true);
|
2020-08-01 00:41:00 +08:00
|
|
|
return this.$axios
|
2021-03-26 10:44:54 +08:00
|
|
|
.$get(`${USER_API_PATH}/${params.account}/portfolios`, {
|
2020-08-01 00:41:00 +08:00
|
|
|
params: {
|
|
|
|
page: params.page
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
commit('updatePortfolioList', response)
|
|
|
|
commit('updateFetching', false)
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
commit('updateFetching', false)
|
|
|
|
})
|
2020-10-25 01:40:24 +08:00
|
|
|
},
|
|
|
|
fetchFollowerList({commit}, params) {
|
|
|
|
commit('updateFetching', true);
|
|
|
|
commit('updateFollowerList', {
|
|
|
|
users: [],
|
|
|
|
pagination: {}
|
|
|
|
})
|
|
|
|
return this.$axios
|
2021-03-26 10:44:54 +08:00
|
|
|
.$get(`${USER_API_PATH}/${params.account}/followers`, {
|
2020-10-25 01:40:24 +08:00
|
|
|
params: {
|
|
|
|
page: params.page
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
commit('updateFollowerList', response)
|
|
|
|
commit('updateFetching', false)
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
commit('updateFetching', false)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
fetchFollowingList({commit}, params) {
|
|
|
|
commit('updateFetching', true);
|
|
|
|
commit('updateFollowingList', {
|
|
|
|
users: [],
|
|
|
|
pagination: {}
|
|
|
|
})
|
|
|
|
return this.$axios
|
2021-03-26 10:44:54 +08:00
|
|
|
.$get(`${USER_API_PATH}/${params.account}/followings`, {
|
2020-10-25 01:40:24 +08:00
|
|
|
params: {
|
|
|
|
page: params.page
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
commit('updateFollowingList', response)
|
|
|
|
commit('updateFetching', false)
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
commit('updateFetching', false)
|
|
|
|
})
|
2020-08-01 00:41:00 +08:00
|
|
|
}
|
|
|
|
}
|