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: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const state = () => {
|
|
|
|
return {
|
|
|
|
fetching: false,
|
|
|
|
user: getDefaultUsersData(),
|
|
|
|
role: getDefaultRolesData()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const actions = {
|
|
|
|
fetchUsers({commit}, params = {}) {
|
|
|
|
// 清空已有数据
|
|
|
|
commit('updateUsersData', getDefaultUsersData())
|
|
|
|
commit('updateFetching', true)
|
|
|
|
|
|
|
|
return this.$axios
|
2020-09-15 22:05:06 +08:00
|
|
|
.$get(`${ADMIN_API_PATH}/users`, {
|
|
|
|
params: params
|
|
|
|
})
|
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 = {}) {
|
|
|
|
// 清空已有数据
|
|
|
|
commit('updateRolesData', getDefaultRolesData())
|
|
|
|
commit('updateFetching', true)
|
|
|
|
|
|
|
|
return this.$axios
|
2020-09-15 22:05:06 +08:00
|
|
|
.$get(`${ADMIN_API_PATH}/roles`, {
|
|
|
|
params: params
|
|
|
|
})
|
2020-08-11 14:43:53 +08:00
|
|
|
.then(response => {
|
|
|
|
commit('updateFetching', false);
|
|
|
|
commit('updateRolesData', response);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
commit('updateFetching', false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|