diff --git a/pages/admin/user.vue b/pages/admin/user.vue new file mode 100644 index 0000000..603eae0 --- /dev/null +++ b/pages/admin/user.vue @@ -0,0 +1,217 @@ + + + + + diff --git a/plugins/element-ui.js b/plugins/element-ui.js index 9ec8b61..ff3dbc9 100644 --- a/plugins/element-ui.js +++ b/plugins/element-ui.js @@ -1,5 +1,5 @@ import Vue from 'vue' import Element from 'element-ui' -import locale from 'element-ui/lib/locale/lang/en' +import locale from 'element-ui/lib/locale/lang/zh-CN' Vue.use(Element, { locale }) diff --git a/store/admin.js b/store/admin.js new file mode 100644 index 0000000..3b43b61 --- /dev/null +++ b/store/admin.js @@ -0,0 +1,72 @@ +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 + .$get(`${ADMIN_API_PATH}/users`) + .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 + .$get(`${ADMIN_API_PATH}/roles`) + .then(response => { + commit('updateFetching', false); + commit('updateRolesData', response); + }) + .catch(error => { + console.log(error); + commit('updateFetching', false); + }); + } +}