2021-05-20 22:02:49 +08:00
|
|
|
export const BASE_API_PATH = '/api/lucene';
|
|
|
|
const getDefaultArticleListData = () => {
|
|
|
|
return {
|
|
|
|
articles: [],
|
|
|
|
pagination: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const getDefaultUserListData = () => {
|
|
|
|
return {
|
|
|
|
users: [],
|
|
|
|
pagination: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const getDefaultPortfolioListData = () => {
|
|
|
|
return {
|
|
|
|
portfolios: [],
|
|
|
|
pagination: {}
|
|
|
|
}
|
|
|
|
}
|
2020-11-30 23:56:08 +08:00
|
|
|
|
|
|
|
export const state = () => {
|
|
|
|
return {
|
|
|
|
fetching: false,
|
2021-05-20 22:02:49 +08:00
|
|
|
list: [],
|
|
|
|
articles: {
|
|
|
|
fetching: false,
|
|
|
|
data: getDefaultArticleListData()
|
|
|
|
},
|
|
|
|
users: {
|
|
|
|
fetching: false,
|
|
|
|
data: getDefaultUserListData()
|
|
|
|
},
|
|
|
|
portfolios: {
|
|
|
|
fetching: false,
|
|
|
|
data: getDefaultPortfolioListData()
|
|
|
|
}
|
2020-11-30 23:56:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
// 数据列表
|
|
|
|
updateListFetching(state, action) {
|
|
|
|
state.fetching = action
|
|
|
|
},
|
|
|
|
updateListData(state, action) {
|
|
|
|
state.list = action
|
2021-05-20 22:02:49 +08:00
|
|
|
},
|
|
|
|
// 数据列表
|
|
|
|
updateArticleListFetching(state, action) {
|
|
|
|
state.articles.fetching = action
|
|
|
|
},
|
|
|
|
updateArticleListData(state, action) {
|
|
|
|
state.articles.data = action
|
|
|
|
},
|
|
|
|
// 数据列表
|
|
|
|
updateUserListFetching(state, action) {
|
|
|
|
state.users.fetching = action
|
|
|
|
},
|
|
|
|
updateUserListData(state, action) {
|
|
|
|
state.users.data = action
|
|
|
|
},
|
|
|
|
// 数据列表
|
|
|
|
updatePortfolioFetching(state, action) {
|
|
|
|
state.portfolios.fetching = action
|
|
|
|
},
|
|
|
|
updatePortfolioListData(state, action) {
|
|
|
|
state.portfolios.data = action
|
|
|
|
},
|
2020-11-30 23:56:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const actions = {
|
|
|
|
// 获取文章列表
|
2021-05-20 22:02:49 +08:00
|
|
|
fetchArticleList({commit}, params = {}) {
|
2020-11-30 23:56:08 +08:00
|
|
|
// 清空已有数据
|
2021-05-20 22:02:49 +08:00
|
|
|
commit('updateArticleListData', getDefaultArticleListData());
|
|
|
|
if (!params.queryString) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
commit('updateArticleListFetching', true);
|
2020-11-30 23:56:08 +08:00
|
|
|
|
|
|
|
return this.$axios
|
2021-05-20 22:02:49 +08:00
|
|
|
.$get(`${BASE_API_PATH}/search-article`, {
|
|
|
|
params: {
|
|
|
|
q: params.queryString,
|
|
|
|
page: params.page || 1
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
commit('updateArticleListFetching', false);
|
|
|
|
commit('updateArticleListData', response ? response : getDefaultArticleListData());
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
commit('updateArticleListFetching', false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fetchUserList({commit}, params = {}) {
|
|
|
|
// 清空已有数据
|
|
|
|
commit('updateUserListData', getDefaultUserListData());
|
|
|
|
if (!params.queryString) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
commit('updateUserListFetching', true);
|
|
|
|
|
|
|
|
return this.$axios
|
|
|
|
.$get(`${BASE_API_PATH}/search-user`, {
|
|
|
|
params: {
|
|
|
|
q: params.queryString,
|
|
|
|
page: params.page || 1
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
commit('updateUserListFetching', false);
|
|
|
|
commit('updateUserListData', response ? response : getDefaultUserListData());
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
commit('updateUserListFetching', false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fetchPortfolioList({commit}, params = {}) {
|
|
|
|
// 清空已有数据
|
|
|
|
commit('updatePortfolioListData', getDefaultPortfolioListData());
|
|
|
|
if (!params.queryString) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
commit('updatePortfolioFetching', true);
|
|
|
|
|
|
|
|
return this.$axios
|
|
|
|
.$get(`${BASE_API_PATH}/search-portfolio`, {
|
|
|
|
params: {
|
|
|
|
q: params.queryString,
|
|
|
|
page: params.page || 1
|
|
|
|
}
|
|
|
|
})
|
2020-11-30 23:56:08 +08:00
|
|
|
.then(response => {
|
2021-05-20 22:02:49 +08:00
|
|
|
commit('updatePortfolioFetching', false);
|
|
|
|
commit('updatePortfolioListData', response ? response : getDefaultPortfolioListData());
|
2020-11-30 23:56:08 +08:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
2021-05-20 22:02:49 +08:00
|
|
|
commit('updatePortfolioFetching', false);
|
2020-11-30 23:56:08 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|