diff --git a/src/api/users.js b/src/api/users.js index ed985cf0..69a8ee14 100644 --- a/src/api/users.js +++ b/src/api/users.js @@ -1,8 +1,8 @@ import request from '@/utils/request' -export async function fetchUsers(page = 1) { +export async function fetchUsers(page = 1, page_size) { return await request({ - url: `/api/pleroma/admin/users?page=${page}`, + url: `/api/pleroma/admin/users?page=${page}&page_size=${page_size}`, method: 'get' }) } @@ -14,9 +14,9 @@ export async function toggleUserActivation(nickname) { }) } -export async function searchUsers(query) { +export async function searchUsers(query, page = 1, page_size) { return await request({ - url: `/api/pleroma/admin/users/search?query=${query}`, + url: `/api/pleroma/admin/users/search?query=${query}&page=${page}&page_size=${page_size}`, method: 'get' }) } diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 01dfb497..095e47f0 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -4,6 +4,7 @@ import { getToken, setToken, removeToken } from '@/utils/auth' const user = { state: { user: '', + id: '', status: '', code: '', token: getToken(), @@ -40,6 +41,9 @@ const user = { }, SET_ROLES: (state, roles) => { state.roles = roles + }, + SET_ID: (state, id) => { + state.id = id } }, @@ -74,6 +78,7 @@ const user = { } commit('SET_NAME', data.name) + commit('SET_ID', data.id) commit('SET_AVATAR', data.profile_image_url) commit('SET_INTRODUCTION', '') resolve(response) @@ -129,6 +134,7 @@ const user = { const data = response.data commit('SET_ROLES', data.roles) commit('SET_NAME', data.name) + commit('SET_ID', data.id) commit('SET_AVATAR', data.avatar) commit('SET_INTRODUCTION', data.introduction) dispatch('GenerateRoutes', data) // 动态修改权限后 重绘侧边菜单 diff --git a/src/store/modules/users.js b/src/store/modules/users.js index 69c27f76..98dd98ae 100644 --- a/src/store/modules/users.js +++ b/src/store/modules/users.js @@ -3,7 +3,10 @@ import { fetchUsers, toggleUserActivation, searchUsers } from '@/api/users' const user = { state: { fetchedUsers: [], - loading: true + loading: true, + searchQuery: '', + totalUsersCount: 0, + pageSize: 2 }, mutations: { SET_USERS: (state, users) => { @@ -26,31 +29,48 @@ const user = { }, SET_PAGE_SIZE: (state, pageSize) => { state.pageSize = pageSize + }, + SET_SEARCH_QUERY: (state, query) => { + state.searchQuery = query } }, actions: { - async FetchUsers({ commit }, page = 1) { - const response = await fetchUsers(page) + async FetchUsers({ commit }, { page, page_size }) { + const response = await fetchUsers(page, page_size) - commit('SET_USERS', response.data.users) - commit('SET_COUNT', response.data.count) - commit('SET_PAGE_SIZE', response.data.page_size) - commit('SET_LOADING', false) + commit('SET_LOADING', true) + + loadUsers(commit, response.data) }, async ToggleUserActivation({ commit }, nickname) { const response = await toggleUserActivation(nickname) commit('SWAP_USER', response.data) }, - async SearchUsers({ commit, dispatch }, searchValue) { - if (searchValue.length === 0) { - dispatch('FetchUsers') + async SearchUsers({ commit, dispatch }, { query, page, page_size }) { + if (query.length === 0) { + // console.log(page) + // console.log(query) + // console.log(page_size) + commit('SET_SEARCH_QUERY', query) + dispatch('FetchUsers', { page, page_size: 2 }) } else { - const response = await searchUsers(searchValue) - commit('SET_USERS', response.data.users) + commit('SET_LOADING', true) + commit('SET_SEARCH_QUERY', query) + + const response = await searchUsers(query, page, page_size) + + loadUsers(commit, response.data) } } } } +const loadUsers = (commit, { users, count, page_size }) => { + commit('SET_USERS', users) + commit('SET_COUNT', count) + commit('SET_PAGE_SIZE', page_size) + commit('SET_LOADING', false) +} + export default user diff --git a/src/views/users/index.vue b/src/views/users/index.vue index 62aba6b6..e84d0088 100644 --- a/src/views/users/index.vue +++ b/src/views/users/index.vue @@ -3,7 +3,7 @@