From 1a1189ad48870b0121d92e560999b1b6d7467ecf Mon Sep 17 00:00:00 2001 From: ZihanChen821 <130351655+ZihanChen821@users.noreply.github.com> Date: Wed, 29 Nov 2023 22:12:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(mis):=20=E4=BF=AE=E5=A4=8D=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E7=AE=A1=E7=90=86=E9=A1=B5=E9=9D=A2=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84=E7=94=A8=E6=88=B7=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E9=94=99=E8=AF=AF=20(#1013)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### 现状: 1. 平台管理页面下的AllUserTable里的数据接口是后端分页,但是前端对三个tab的数据统计是根据该分页接口的该页数据过滤得到的,是不准确的。 2. 之前的GetPlatformUsersCounts是用来适配GetAllUsers后端分页接口,但在此处#905 被删去,原因在于当用户填入了筛选项时,数据统计的接口并不是筛选后的情况。 ### 改动 1. 恢复AllUserTable里的GetPlatformUsersCounts接口,确保统计数据准确, 2. 同时给该接口增加过滤参数,确保用户输入过滤项时的数据实时更新。 --- .changeset/fast-trees-draw.md | 6 ++++ .changeset/itchy-trains-play.md | 5 ++++ apps/mis-server/src/services/user.ts | 20 +++++++++---- .../pageComponents/admin/AllUsersTable.tsx | 29 +++++++++---------- .../pages/api/admin/getPlatformUsersCounts.ts | 10 +++++-- protos/server/user.proto | 1 + 6 files changed, 48 insertions(+), 23 deletions(-) create mode 100644 .changeset/fast-trees-draw.md create mode 100644 .changeset/itchy-trains-play.md diff --git a/.changeset/fast-trees-draw.md b/.changeset/fast-trees-draw.md new file mode 100644 index 0000000000..5e7f568945 --- /dev/null +++ b/.changeset/fast-trees-draw.md @@ -0,0 +1,6 @@ +--- +"@scow/mis-server": patch +"@scow/mis-web": patch +--- + +管理系统 AllUserTable 恢复计数接口并且新增筛选参数 diff --git a/.changeset/itchy-trains-play.md b/.changeset/itchy-trains-play.md new file mode 100644 index 0000000000..e21f600254 --- /dev/null +++ b/.changeset/itchy-trains-play.md @@ -0,0 +1,5 @@ +--- +"@scow/grpc-api": patch +--- + +GetPlatformUsersCounts 新增 id_or_name 参数 diff --git a/apps/mis-server/src/services/user.ts b/apps/mis-server/src/services/user.ts index 13665d8484..6d0cb37af6 100644 --- a/apps/mis-server/src/services/user.ts +++ b/apps/mis-server/src/services/user.ts @@ -595,13 +595,23 @@ export const userServiceServer = plugin((server) => { }]; }, - getPlatformUsersCounts: async ({ em }) => { - - const totalCount = await em.count(User); + getPlatformUsersCounts: async ({ request, em }) => { + const { idOrName } = request; + const idOrNameQuery = idOrName ? { + $and: [ + { + $or: [ + { userId: { $like: `%${idOrName}%` } }, + { name: { $like: `%${idOrName}%` } }, + ], + }, + ], + } : {}; + const totalCount = await em.count(User, idOrNameQuery); const totalAdminCount = await em.count(User, - { platformRoles: { $like: `%${PlatformRole.PLATFORM_ADMIN}%` } }); + { platformRoles: { $like: `%${PlatformRole.PLATFORM_ADMIN}%` }, ...idOrNameQuery }); const totalFinanceCount = await em.count(User, - { platformRoles: { $like: `%${PlatformRole.PLATFORM_FINANCE}%` } }); + { platformRoles: { $like: `%${PlatformRole.PLATFORM_FINANCE}%` }, ...idOrNameQuery }); return [{ totalCount: totalCount, diff --git a/apps/mis-web/src/pageComponents/admin/AllUsersTable.tsx b/apps/mis-web/src/pageComponents/admin/AllUsersTable.tsx index 35d0aad1d4..e13139d6e1 100644 --- a/apps/mis-web/src/pageComponents/admin/AllUsersTable.tsx +++ b/apps/mis-web/src/pageComponents/admin/AllUsersTable.tsx @@ -15,7 +15,7 @@ import { DEFAULT_PAGE_SIZE } from "@scow/lib-web/build/utils/pagination"; import { PlatformUserInfo } from "@scow/protos/build/server/user"; import { Static } from "@sinclair/typebox"; import { App, Button, Divider, Form, Input, Space, Table } from "antd"; -import React, { useCallback, useEffect, useMemo, useState } from "react"; +import React, { useCallback, useMemo, useState } from "react"; import { useAsync } from "react-async"; import { api } from "src/apis"; import { ChangePasswordModalLink } from "src/components/ChangePasswordModal"; @@ -68,7 +68,6 @@ export const AllUsersTable: React.FC = ({ refreshToken, user }) => { const [pageInfo, setPageInfo] = useState({ page: 1, pageSize: DEFAULT_PAGE_SIZE }); const [sortInfo, setSortInfo] = useState({ sortField: undefined, sortOrder: undefined }); const [currentPlatformRole, setCurrentPlatformRole] = useState(undefined); - const [allUsers, setAllUsers] = useState(undefined); const promiseFn = useCallback(async () => { @@ -83,30 +82,27 @@ export const AllUsersTable: React.FC = ({ refreshToken, user }) => { }, [query, pageInfo, sortInfo, currentPlatformRole]); const { data, isLoading, reload: reloadAllUsers } = useAsync({ promiseFn, watch: refreshToken }); - useEffect(() => { - if (currentPlatformRole === undefined) { - setAllUsers(data?.platformUsers); - } - }, [data]); + + const { data: platformUsersCounts, isLoading: isCountLoading, reload: reloadUsersCounts } = useAsync({ + promiseFn: useCallback( + async () => await api.getPlatformUsersCounts({ query:{ idOrName: query.idOrName } }), [query, refreshToken], + ), + }); const roleChangedHandlers = useMemo(() => ({ "ALL_USERS": { setCurrentPlatformRole: () => setCurrentPlatformRole(undefined), - count: allUsers?.length ?? 0, + count: platformUsersCounts?.totalCount ?? 0, }, "PLATFORM_ADMIN": { setCurrentPlatformRole: () => setCurrentPlatformRole(PlatformRole.PLATFORM_ADMIN), - count: allUsers?.filter((user) => { - return user.platformRoles.includes(PlatformRole.PLATFORM_ADMIN); - }).length ?? 0, + count: platformUsersCounts?.totalAdminCount ?? 0, }, "PLATFORM_FINANCE": { setCurrentPlatformRole: () => setCurrentPlatformRole(PlatformRole.PLATFORM_FINANCE), - count: allUsers?.filter((user) => { - return user.platformRoles.includes(PlatformRole.PLATFORM_FINANCE); - }).length ?? 0, + count: platformUsersCounts?.totalFinanceCount ?? 0, }, - }), [allUsers]); + }), [platformUsersCounts]); const handleFilterRoleChange = (role: FilteredRole) => { roleChangedHandlers[role].setCurrentPlatformRole(); @@ -116,6 +112,7 @@ export const AllUsersTable: React.FC = ({ refreshToken, user }) => { const reload = () => { reloadAllUsers(); + reloadUsersCounts(); }; return ( @@ -156,7 +153,7 @@ export const AllUsersTable: React.FC = ({ refreshToken, user }) => { setPageInfo={setPageInfo} sortInfo={sortInfo} setSortInfo={setSortInfo} - isLoading={isLoading} + isLoading={isLoading || isCountLoading} reload={reload} user={user} /> diff --git a/apps/mis-web/src/pages/api/admin/getPlatformUsersCounts.ts b/apps/mis-web/src/pages/api/admin/getPlatformUsersCounts.ts index 56462b277f..74ad62e0ff 100644 --- a/apps/mis-web/src/pages/api/admin/getPlatformUsersCounts.ts +++ b/apps/mis-web/src/pages/api/admin/getPlatformUsersCounts.ts @@ -28,6 +28,10 @@ export type GetPlatformUsersCountsResponse = Static