diff --git a/.changeset/tender-clocks-decide.md b/.changeset/tender-clocks-decide.md new file mode 100644 index 0000000000..6e23c5810f --- /dev/null +++ b/.changeset/tender-clocks-decide.md @@ -0,0 +1,5 @@ +--- +"@scow/mis-web": patch +--- + +修改 mis-web 下后端返回的操作日志内容,在 mis-web 前端处理操作类型,操作行为,操作详细的展示 diff --git a/apps/mis-web/src/apis/api.mock.ts b/apps/mis-web/src/apis/api.mock.ts index df4c4bdb52..7037a92041 100644 --- a/apps/mis-web/src/apis/api.mock.ts +++ b/apps/mis-web/src/apis/api.mock.ts @@ -17,7 +17,7 @@ import type { RunningJob } from "@scow/protos/build/common/job"; import type { Account } from "@scow/protos/build/server/account"; import type { AccountUserInfo, GetUserStatusResponse } from "@scow/protos/build/server/user"; import { api } from "src/apis/api"; -import { OperationResult, OperationType } from "src/models/operationLog"; +import { OperationResult } from "src/models/operationLog"; import { ClusterAccountInfo_ImportStatus, PlatformRole, TenantRole, UserInfo, UserRole, UserStatus } from "src/models/User"; import { DEFAULT_TENANT_NAME } from "src/utils/constants"; @@ -415,11 +415,9 @@ export const mockApi: MockApi = { operatorUserId: "testUser", operatorUserName: "testUser", operatorIp: "localhost", - operationCode: "000000", - operationType: OperationType.login, operationResult: OperationResult.SUCCESS, operationTime: "2020-04-23T23:49:50.000Z", - operationDetail:"用户登录", + operationEvent: { $case: "login", login: {} }, }], totalCount: 1 }), }; diff --git a/apps/mis-web/src/components/OperationLogTable.tsx b/apps/mis-web/src/components/OperationLogTable.tsx index 4b59faa2ed..fd15ed8386 100644 --- a/apps/mis-web/src/components/OperationLogTable.tsx +++ b/apps/mis-web/src/components/OperationLogTable.tsx @@ -19,6 +19,7 @@ import { useAsync } from "react-async"; import { api } from "src/apis"; import { FilterFormContainer } from "src/components/FilterFormContainer"; import { + getOperationDetail, OperationCodeMap, OperationLog, OperationLogQueryType, OperationResult, @@ -86,6 +87,20 @@ export const OperationLogTable: React.FC = ({ user, queryType, accountNam const { data, isLoading } = useAsync({ promiseFn }); + const getformatData = (results: OperationLog[] | undefined) => { + if (!results) { + return []; + } + return results.map((data) => { + return { + ...data, + operationCode: data.operationEvent?.["$case"] ? OperationCodeMap[data.operationEvent?.["$case"]] : "000000", + operationType: data.operationEvent?.["$case"] || "unknown", + operationDetail: getOperationDetail(data.operationEvent), + }; + }); + }; + return (
@@ -137,7 +152,7 @@ export const OperationLogTable: React.FC = ({ user, queryType, accountNam = ({ user, queryType, accountNam }} > dataIndex="operationLogId" title="ID" /> - dataIndex="operationCode" title="操作码" /> - + + OperationTypeTexts[operationType] } + render={(operationType) => OperationTypeTexts[operationType]} /> - + diff --git a/apps/mis-web/src/models/operationLog.ts b/apps/mis-web/src/models/operationLog.ts index b0014e44fb..81cf3377f0 100644 --- a/apps/mis-web/src/models/operationLog.ts +++ b/apps/mis-web/src/models/operationLog.ts @@ -10,8 +10,7 @@ * See the Mulan PSL v2 for more details. */ -import { OperationType as LibOperationType, OperationTypeEnum } from "@scow/lib-operation-log"; -import { OperationLog as OperationLogProto } from "@scow/protos/build/audit/operation_log"; +import { OperationEvent, OperationType as LibOperationType, OperationTypeEnum } from "@scow/lib-operation-log"; import { Static, Type } from "@sinclair/typebox"; import { ValueOf } from "next/dist/shared/lib/constants"; import { nullableMoneyToString } from "src/utils/money"; @@ -81,11 +80,9 @@ export const OperationLog = Type.Object({ operatorUserId: Type.String(), operatorUserName: Type.String(), operatorIp: Type.String(), - operationCode: Type.String(), - operationType: Type.Enum(OperationType), operationResult: Type.Enum(OperationResult), operationTime: Type.Optional(Type.String()), - operationDetail: Type.String(), + operationEvent: Type.Any(), }); export type OperationLog = Static; @@ -206,10 +203,9 @@ export const OperationCodeMap: { [key in LibOperationType]: string } = { tenantPay: "040302", }; -export const getOperationDetail = (operationLog: OperationLogProto) => { +export const getOperationDetail = (operationEvent: OperationEvent) => { try { - const { operationEvent } = operationLog; if (!operationEvent) { return ""; } diff --git a/apps/mis-web/src/pages/api/log/getOperationLog.ts b/apps/mis-web/src/pages/api/log/getOperationLog.ts index cfc3ff3011..7cadec5530 100644 --- a/apps/mis-web/src/pages/api/log/getOperationLog.ts +++ b/apps/mis-web/src/pages/api/log/getOperationLog.ts @@ -16,7 +16,7 @@ import { createOperationLogClient } from "@scow/lib-operation-log/build/index"; import { UserServiceClient } from "@scow/protos/build/server/user"; import { Static, Type } from "@sinclair/typebox"; import { authenticate } from "src/auth/server"; -import { getOperationDetail, OperationCodeMap, OperationLog, OperationLogQueryType, +import { OperationLog, OperationLogQueryType, OperationResult, OperationType } from "src/models/operationLog"; import { PlatformRole, TenantRole, UserRole } from "src/models/User"; import { getClient } from "src/utils/client"; @@ -158,12 +158,10 @@ export default typeboxRoute(GetOperationLogsSchema, async (req, res) => { operatorIp: x.operatorIp, operationResult: x.operationResult, operationTime: x.operationTime, - operationType: x.operationEvent?.["$case"] || "unknown", - operationCode: x.operationEvent?.["$case"] ? OperationCodeMap[x.operationEvent?.["$case"]] : "000000", - operationDetail: getOperationDetail(x), + operationEvent: x.operationEvent, }; }); return { - 200: { results: operationLogs as OperationLog[], totalCount }, + 200: { results: operationLogs as any as OperationLog[], totalCount }, }; });