2020-08-11 14:43:53 +08:00
|
|
|
export const ADMIN_API_PATH = '/api/admin'
|
|
|
|
|
|
|
|
const getDefaultUsersData = () => {
|
|
|
|
return {
|
|
|
|
users: [],
|
|
|
|
pagination: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const getDefaultRolesData = () => {
|
|
|
|
return {
|
|
|
|
role: [],
|
|
|
|
pagination: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-28 08:08:24 +08:00
|
|
|
const getDefaultArticlesData = () => {
|
|
|
|
return {
|
|
|
|
articles: [],
|
|
|
|
pagination: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const getDefaultCommentsData = () => {
|
|
|
|
return {
|
|
|
|
comments: [],
|
|
|
|
pagination: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-11 14:43:53 +08:00
|
|
|
export const state = () => {
|
|
|
|
return {
|
|
|
|
fetching: false,
|
|
|
|
user: getDefaultUsersData(),
|
2021-06-28 08:08:24 +08:00
|
|
|
role: getDefaultRolesData(),
|
|
|
|
article: getDefaultArticlesData(),
|
2022-03-03 11:26:42 +08:00
|
|
|
comment: getDefaultCommentsData(),
|
|
|
|
tabs: [
|
|
|
|
{
|
|
|
|
title: 'Dashboard',
|
|
|
|
name: 'admin-dashboard',
|
|
|
|
path: '/admin/dashboard',
|
|
|
|
icon: 'el-icon-s-data',
|
|
|
|
closable: false
|
|
|
|
}
|
|
|
|
],
|
|
|
|
activeTab: 'admin-dashboard'
|
2020-08-11 14:43:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
updateFetching(state, action) {
|
|
|
|
state.fetching = action
|
|
|
|
},
|
|
|
|
updateUsersData(state, action) {
|
|
|
|
state.user.users = action.users
|
|
|
|
state.user.pagination = action.pagination
|
|
|
|
},
|
|
|
|
updateRolesData(state, action) {
|
|
|
|
state.role.roles = action.roles
|
|
|
|
state.role.pagination = action.pagination
|
2021-06-28 08:08:24 +08:00
|
|
|
},
|
|
|
|
updateArticlesData(state, action) {
|
|
|
|
state.article.articles = action.articles
|
|
|
|
state.article.pagination = action.pagination
|
|
|
|
},
|
|
|
|
updateCommentsData(state, action) {
|
|
|
|
state.comment.comments = action.comments
|
|
|
|
state.comment.pagination = action.pagination
|
|
|
|
},
|
|
|
|
updateArticlePreference(state, action) {
|
|
|
|
let article = state.article.articles[action.index]
|
|
|
|
if (article.idArticle === action.idArticle) {
|
|
|
|
article.articlePerfect = action.articlePerfect
|
|
|
|
}
|
2022-03-03 11:26:42 +08:00
|
|
|
},
|
|
|
|
updateTags(state, action) {
|
|
|
|
state.tabs = action
|
|
|
|
},
|
|
|
|
pushTags(state, action) {
|
|
|
|
let tabs = state.tabs
|
|
|
|
tabs.push(action)
|
|
|
|
},
|
|
|
|
updateActiveTab(state, action) {
|
|
|
|
state.activeTab = action
|
2020-08-11 14:43:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const actions = {
|
|
|
|
fetchUsers({commit}, params = {}) {
|
2022-06-21 08:33:33 +08:00
|
|
|
if (params && params.reset === '0') {
|
|
|
|
return true;
|
|
|
|
}
|
2020-08-11 14:43:53 +08:00
|
|
|
// 清空已有数据
|
|
|
|
commit('updateUsersData', getDefaultUsersData())
|
|
|
|
commit('updateFetching', true)
|
|
|
|
|
2020-09-15 22:15:02 +08:00
|
|
|
let data = {
|
|
|
|
page: params.page || 1,
|
|
|
|
rows: params.rows || 10
|
|
|
|
}
|
|
|
|
|
2020-08-11 14:43:53 +08:00
|
|
|
return this.$axios
|
2020-09-15 22:05:06 +08:00
|
|
|
.$get(`${ADMIN_API_PATH}/users`, {
|
2020-09-15 22:15:02 +08:00
|
|
|
params: data
|
2020-09-15 22:05:06 +08:00
|
|
|
})
|
2020-08-11 14:43:53 +08:00
|
|
|
.then(response => {
|
|
|
|
commit('updateFetching', false);
|
|
|
|
commit('updateUsersData', response);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
commit('updateFetching', false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fetchRoles({commit}, params = {}) {
|
2022-06-21 08:33:33 +08:00
|
|
|
if (params && params.reset === '0') {
|
|
|
|
return true;
|
|
|
|
}
|
2020-08-11 14:43:53 +08:00
|
|
|
// 清空已有数据
|
|
|
|
commit('updateRolesData', getDefaultRolesData())
|
|
|
|
commit('updateFetching', true)
|
|
|
|
|
2020-09-15 22:15:02 +08:00
|
|
|
let data = {
|
|
|
|
page: params.page || 1,
|
|
|
|
rows: params.rows || 10
|
|
|
|
}
|
|
|
|
|
2020-08-11 14:43:53 +08:00
|
|
|
return this.$axios
|
2020-09-15 22:05:06 +08:00
|
|
|
.$get(`${ADMIN_API_PATH}/roles`, {
|
2020-09-15 22:15:02 +08:00
|
|
|
params: data
|
2020-09-15 22:05:06 +08:00
|
|
|
})
|
2020-08-11 14:43:53 +08:00
|
|
|
.then(response => {
|
|
|
|
commit('updateFetching', false);
|
|
|
|
commit('updateRolesData', response);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
commit('updateFetching', false);
|
|
|
|
});
|
2021-06-28 08:08:24 +08:00
|
|
|
},
|
|
|
|
fetchArticles({commit}, params = {}) {
|
2022-06-21 08:33:33 +08:00
|
|
|
if (params && params.reset === '0') {
|
|
|
|
return true;
|
|
|
|
}
|
2021-06-28 08:08:24 +08:00
|
|
|
// 清空已有数据
|
|
|
|
commit('updateArticlesData', getDefaultArticlesData())
|
|
|
|
commit('updateFetching', true)
|
|
|
|
|
|
|
|
let data = {
|
|
|
|
page: params.page || 1,
|
|
|
|
rows: params.rows || 10,
|
|
|
|
topicUri: 'news'
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.$axios
|
|
|
|
.$get(`${ADMIN_API_PATH}/articles`, {
|
|
|
|
params: data
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
commit('updateFetching', false);
|
|
|
|
commit('updateArticlesData', response);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
commit('updateFetching', false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fetchComments({commit}, params = {}) {
|
2022-06-21 08:33:33 +08:00
|
|
|
if (params && params.reset === '0') {
|
|
|
|
return true;
|
|
|
|
}
|
2021-06-28 08:08:24 +08:00
|
|
|
// 清空已有数据
|
|
|
|
commit('updateCommentsData', getDefaultArticlesData())
|
|
|
|
commit('updateFetching', true)
|
|
|
|
|
|
|
|
let data = {
|
|
|
|
page: params.page || 1,
|
|
|
|
rows: params.rows || 10
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.$axios
|
|
|
|
.$get(`${ADMIN_API_PATH}/comments`, {
|
|
|
|
params: data
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
commit('updateFetching', false);
|
|
|
|
commit('updateCommentsData', response);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
commit('updateFetching', false);
|
|
|
|
});
|
2020-08-11 14:43:53 +08:00
|
|
|
}
|
|
|
|
}
|