From 2af3cd83f28d5aa553baebf6c55b57f203d50e35 Mon Sep 17 00:00:00 2001 From: gggaaallleee <91131304+gggaaallleee@users.noreply.github.com> Date: Mon, 14 Apr 2025 18:28:42 +0800 Subject: [PATCH] update Log (#4533) * add log search * update log --- .../account/team/OperationLog/index.tsx | 115 ++++++++++++++++-- .../support/user/team/operantionLog/api.ts | 9 +- 2 files changed, 115 insertions(+), 9 deletions(-) diff --git a/projects/app/src/pageComponents/account/team/OperationLog/index.tsx b/projects/app/src/pageComponents/account/team/OperationLog/index.tsx index bf85a21ff..e29b5a063 100644 --- a/projects/app/src/pageComponents/account/team/OperationLog/index.tsx +++ b/projects/app/src/pageComponents/account/team/OperationLog/index.tsx @@ -8,12 +8,12 @@ import { Td, Th, Thead, - Tr + Tr, + HStack } from '@chakra-ui/react'; -import { useState } from 'react'; +import { useState, useEffect, useMemo } from 'react'; import { useTranslation } from 'next-i18next'; import MyBox from '@fastgpt/web/components/common/MyBox'; -import SearchInput from '@fastgpt/web/components/common/Input/SearchInput'; import { useScrollPagination } from '@fastgpt/web/hooks/useScrollPagination'; import { getOperationLogs } from '@/web/support/user/team/operantionLog/api'; import { TeamPermission } from '@fastgpt/global/support/permission/user/controller'; @@ -21,28 +21,129 @@ import { operationLogI18nMap } from '@fastgpt/service/support/operationLog/const import { OperationLogEventEnum } from '@fastgpt/global/support/operationLog/constants'; import { formatTime2YMDHMS } from '@fastgpt/global/common/string/time'; import UserBox from '@fastgpt/web/components/common/UserBox'; +import MultipleSelect, { + useMultipleSelect +} from '@fastgpt/web/components/common/MySelect/MultipleSelect'; +import Avatar from '@fastgpt/web/components/common/Avatar'; +import { getTeamMembers } from '@/web/support/user/team/api'; function OperationLogTable({ Tabs }: { Tabs: React.ReactNode }) { const { t } = useTranslation(); + const [searchParams, setSearchParams] = useState<{ + tmbIds?: string[]; + events?: OperationLogEventEnum[]; + }>({}); + + const { data: members, ScrollData } = useScrollPagination(getTeamMembers, {}); + const tmbList = useMemo( + () => + members.map((item) => ({ + label: ( + + + {item.memberName} + + ), + value: item.tmbId + })), + [members] + ); + + const eventOptions = useMemo( + () => + Object.values(OperationLogEventEnum).map((event) => ({ + label: t(operationLogI18nMap[event].typeLabel), + value: event + })), + [t] + ); - const [searchKey, setSearchKey] = useState(''); const { data: operationLogs = [], isLoading: loadingLogs, ScrollData: LogScrollData } = useScrollPagination(getOperationLogs, { pageSize: 20, - refreshDeps: [searchKey], throttleWait: 500, - debounceWait: 200 + debounceWait: 200, + refreshDeps: [searchParams], + params: searchParams }); + const { + value: selectedTmbIds, + setValue: setSelectedTmbIds, + isSelectAll: isSelectAllTmb, + setIsSelectAll: setIsSelectAllTmb + } = useMultipleSelect( + tmbList.map((item) => item.value), + true + ); + + const { + value: selectedEvents, + setValue: setSelectedEvents, + isSelectAll: isSelectAllEvent, + setIsSelectAll: setIsSelectAllEvent + } = useMultipleSelect( + eventOptions.map((item) => item.value), + true + ); + + useEffect(() => { + setSearchParams({ + ...(isSelectAllTmb ? {} : { tmbIds: selectedTmbIds.length > 0 ? selectedTmbIds : undefined }), + ...(isSelectAllEvent + ? {} + : { events: selectedEvents.length > 0 ? selectedEvents : undefined }) + }); + }, [selectedTmbIds, selectedEvents, isSelectAllTmb, isSelectAllEvent]); + const isLoading = loadingLogs; return ( <> - + {Tabs} + + + {t('account_team:log_user')} + + + + list={tmbList} + value={selectedTmbIds} + onSelect={(val) => { + setSelectedTmbIds(val as string[]); + }} + itemWrap={false} + height={'32px'} + bg={'myGray.50'} + w={'160px'} + ScrollData={ScrollData} + isSelectAll={isSelectAllTmb} + setIsSelectAll={setIsSelectAllTmb} + /> + + + + + {t('account_team:log_type')} + + + + + diff --git a/projects/app/src/web/support/user/team/operantionLog/api.ts b/projects/app/src/web/support/user/team/operantionLog/api.ts index 728d3b0df..574639756 100644 --- a/projects/app/src/web/support/user/team/operantionLog/api.ts +++ b/projects/app/src/web/support/user/team/operantionLog/api.ts @@ -1,8 +1,13 @@ import { GET, POST, PUT } from '@/web/common/api/request'; import type { PaginationProps, PaginationResponse } from '@fastgpt/web/common/fetch/type'; import type { OperationListItemType } from '@fastgpt/global/support/operationLog/type'; - -export const getOperationLogs = (props: PaginationProps) => +import { OperationLogEventEnum } from '@fastgpt/global/support/operationLog/constants'; +export const getOperationLogs = ( + props: PaginationProps & { + tmbIds?: string[]; + events?: OperationLogEventEnum[]; + } +) => POST>( `/proApi/support/user/team/operationLog/list`, props