From d6152616f0b4be09c25f89170f62b685ad0e6a98 Mon Sep 17 00:00:00 2001 From: ronger Date: Tue, 11 Aug 2020 14:43:53 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=90=8E=E5=8F=B0=E7=AE=A1?= =?UTF-8?q?=E7=90=86-=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/admin/user.vue | 217 ++++++++++++++++++++++++++++++++++++++++++ plugins/element-ui.js | 2 +- store/admin.js | 72 ++++++++++++++ 3 files changed, 290 insertions(+), 1 deletion(-) create mode 100644 pages/admin/user.vue create mode 100644 store/admin.js 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); + }); + } +}