From 450a97460b086663bb07b418b48354b0a3125e85 Mon Sep 17 00:00:00 2001
From: cl <1442464845@qq.com>
Date: 星期六, 09 五月 2026 16:05:06 +0800
Subject: [PATCH] 日志优化
---
rsf-admin/src/page/system/httpAuditLog/HttpAuditLogList.jsx | 317 ++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 242 insertions(+), 75 deletions(-)
diff --git a/rsf-admin/src/page/system/httpAuditLog/HttpAuditLogList.jsx b/rsf-admin/src/page/system/httpAuditLog/HttpAuditLogList.jsx
index 5093322..c0dc7b4 100644
--- a/rsf-admin/src/page/system/httpAuditLog/HttpAuditLogList.jsx
+++ b/rsf-admin/src/page/system/httpAuditLog/HttpAuditLogList.jsx
@@ -1,91 +1,258 @@
-import React from "react";
+import React, { useMemo } from "react";
import {
List,
- Datagrid,
+ DatagridConfigurable,
+ SearchInput,
+ TopToolbar,
+ SelectColumnsButton,
+ FilterButton,
TextField,
DateField,
- TopToolbar,
- FilterButton,
+ NumberField,
TextInput,
+ DateInput,
SelectInput,
+ WrapperField,
+ FunctionField,
ShowButton,
BulkDeleteButton,
- FunctionField,
+ useTranslate,
+ Pagination,
} from "react-admin";
-import { Chip } from "@mui/material";
+import { Box, Chip } from "@mui/material";
+import { styled } from "@mui/material/styles";
import EmptyData from "@/page/components/EmptyData";
-import { DEFAULT_PAGE_SIZE } from "@/config/setting";
+import { OPERATE_MODE, DEFAULT_PAGE_SIZE } from "@/config/setting";
-const filters = [
- <TextInput source="uri" label="table.field.httpAuditLog.uri" alwaysOn />,
- <TextInput source="clientIp" label="table.field.httpAuditLog.clientIp" />,
- <SelectInput
- source="okFlag"
- label="table.field.httpAuditLog.okFlag"
- choices={[
- { id: 1, name: "姝e父" },
- { id: 0, name: "寮傚父" },
- ]}
- />,
- <TextInput source="serviceName" label="table.field.httpAuditLog.serviceName" />,
- <SelectInput
- source="scopeType"
- label="table.field.httpAuditLog.scopeType"
- choices={[
- { id: "EXTERNAL", name: "澶栭儴" },
- { id: "INTERNAL", name: "鍐呴儴" },
- ]}
- />,
- <SelectInput
- source="ioDirection"
- label="table.field.httpAuditLog.ioDirection"
- choices={[
- { id: "IN", name: "IN" },
- { id: "OUT", name: "OUT" },
- ]}
- />,
- <TextInput source="functionDesc" label="table.field.httpAuditLog.functionDesc" />,
- <TextInput source="method" label="table.field.httpAuditLog.method" />,
-];
+const httpAuditLogPagination = <Pagination rowsPerPageOptions={[10, 25, 50, 100, 200]} />;
-const HttpAuditLogList = () => (
- <List
- title="menu.httpAuditLog"
- filters={filters}
- sort={{ field: "create_time", order: "DESC" }}
- perPage={DEFAULT_PAGE_SIZE}
- empty={<EmptyData />}
- actions={
- <TopToolbar>
- <FilterButton />
- </TopToolbar>
- }
- >
- <Datagrid bulkActionButtons={<BulkDeleteButton />}>
- <TextField source="id" />
- <TextField source="serviceName" label="table.field.httpAuditLog.serviceName" />
- <TextField source="scopeType" label="table.field.httpAuditLog.scopeType" />
- <TextField source="uri" label="table.field.httpAuditLog.uri" />
- <TextField source="ioDirection" label="table.field.httpAuditLog.ioDirection" />
- <TextField source="method" label="table.field.httpAuditLog.method" />
- <TextField source="functionDesc" label="table.field.httpAuditLog.functionDesc" />
- <TextField source="clientIp" label="table.field.httpAuditLog.clientIp" />
- <FunctionField
+const StyledDatagrid = styled(DatagridConfigurable)(() => ({
+ "& .RaDatagrid-row": { cursor: "default" },
+ "& .column-uri": {
+ maxWidth: "18em",
+ overflow: "hidden",
+ textOverflow: "ellipsis",
+ whiteSpace: "nowrap",
+ },
+ "& .column-requestBody": {
+ maxWidth: "18em",
+ overflow: "hidden",
+ textOverflow: "ellipsis",
+ whiteSpace: "nowrap",
+ },
+ "& .column-responseBody": {
+ maxWidth: "18em",
+ overflow: "hidden",
+ textOverflow: "ellipsis",
+ whiteSpace: "nowrap",
+ },
+ "& .opt": { width: 140 },
+}));
+
+function joinRequestParams(record) {
+ const parts = [];
+ if (record.queryString) {
+ parts.push(record.queryString);
+ }
+ if (record.requestBody) {
+ parts.push(record.requestBody);
+ }
+ return parts.join("\n");
+}
+
+const HttpAuditLogList = () => {
+ const translate = useTranslate();
+ const filters = useMemo(
+ () => [
+ <SearchInput source="condition" alwaysOn />,
+ <DateInput source="timeStart" label="common.time.after" />,
+ <DateInput source="timeEnd" label="common.time.before" />,
+ <TextInput source="uri" label="table.field.httpAuditLog.uri" />,
+ <TextInput source="clientIp" label="table.field.httpAuditLog.clientIp" />,
+ <SelectInput
+ source="okFlag"
label="table.field.httpAuditLog.okFlag"
- render={(record) =>
- record.okFlag === 1 ? (
- <Chip label="姝e父" color="success" size="small" variant="outlined" />
- ) : (
- <Chip label="寮傚父" color="error" size="small" variant="outlined" />
- )
+ choices={[
+ { id: 1, name: translate("table.field.httpAuditLog.okNormal") },
+ { id: 0, name: translate("table.field.httpAuditLog.okAbnormal") },
+ ]}
+ />,
+ <TextInput source="serviceName" label="table.field.httpAuditLog.serviceName" />,
+ <SelectInput
+ source="scopeType"
+ label="table.field.httpAuditLog.scopeType"
+ choices={[
+ { id: "EXTERNAL", name: translate("table.field.httpAuditLog.scopeExternal") },
+ { id: "INTERNAL", name: translate("table.field.httpAuditLog.scopeInternal") },
+ ]}
+ />,
+ <SelectInput
+ source="ioDirection"
+ label="table.field.httpAuditLog.ioDirection"
+ choices={[
+ { id: "IN", name: translate("table.field.httpAuditLog.ioIn") },
+ { id: "OUT", name: translate("table.field.httpAuditLog.ioOut") },
+ ]}
+ />,
+ <TextInput source="functionDesc" label="table.field.httpAuditLog.functionDesc" />,
+ <TextInput source="method" label="table.field.httpAuditLog.method" />,
+ <TextInput source="requestContains" label="table.field.httpAuditLog.requestContains" />,
+ <TextInput source="responseContains" label="table.field.httpAuditLog.responseContains" />,
+ ],
+ [translate],
+ );
+
+ return (
+ <Box display="flex">
+ <List
+ title="menu.httpAuditLog"
+ filters={filters}
+ sort={{ field: "create_time", order: "DESC" }}
+ perPage={DEFAULT_PAGE_SIZE}
+ pagination={httpAuditLogPagination}
+ empty={<EmptyData />}
+ actions={
+ <TopToolbar>
+ <FilterButton />
+ <SelectColumnsButton preferenceKey="httpAuditLog" />
+ </TopToolbar>
}
- />
- <TextField source="httpStatus" label="table.field.httpAuditLog.httpStatus" />
- <TextField source="spendMs" label="table.field.httpAuditLog.spendMs" />
- <DateField source="createTime" label="common.field.createTime" showTime />
- <ShowButton />
- </Datagrid>
- </List>
-);
+ >
+ <StyledDatagrid
+ preferenceKey="httpAuditLog"
+ rowClick={false}
+ bulkActionButtons={() => <BulkDeleteButton mutationMode={OPERATE_MODE} />}
+ >
+ <NumberField source="id" label="common.field.id" />
+ <TextField source="serviceName" label="table.field.httpAuditLog.serviceName" />
+ <FunctionField
+ source="scopeType"
+ label="table.field.httpAuditLog.scopeType"
+ render={(record) =>
+ record.scopeType === "EXTERNAL"
+ ? translate("table.field.httpAuditLog.scopeExternal")
+ : record.scopeType === "INTERNAL"
+ ? translate("table.field.httpAuditLog.scopeInternal")
+ : (record.scopeType ?? "")
+ }
+ />
+ <TextField source="uri" label="table.field.httpAuditLog.uri" />
+ <FunctionField
+ source="ioDirection"
+ label="table.field.httpAuditLog.ioDirection"
+ render={(record) =>
+ record.ioDirection === "IN"
+ ? translate("table.field.httpAuditLog.ioIn")
+ : record.ioDirection === "OUT"
+ ? translate("table.field.httpAuditLog.ioOut")
+ : (record.ioDirection ?? "")
+ }
+ />
+ <TextField source="method" label="table.field.httpAuditLog.method" />
+ <TextField source="functionDesc" label="table.field.httpAuditLog.functionDesc" />
+ <FunctionField
+ source="requestBody"
+ label="table.field.httpAuditLog.requestParams"
+ sortable={false}
+ render={(record) => {
+ const full = joinRequestParams(record);
+ if (!full) {
+ return "";
+ }
+ return (
+ <Box
+ component="span"
+ title={full}
+ sx={{
+ maxWidth: "inherit",
+ display: "inline-block",
+ overflow: "hidden",
+ textOverflow: "ellipsis",
+ whiteSpace: "nowrap",
+ verticalAlign: "bottom",
+ width: "100%",
+ }}
+ >
+ {full}
+ </Box>
+ );
+ }}
+ />
+ <FunctionField
+ source="responseBody"
+ label="table.field.httpAuditLog.responseParams"
+ sortable={false}
+ render={(record) => {
+ const full = record.responseBody ?? "";
+ if (!full) {
+ return "";
+ }
+ return (
+ <Box
+ component="span"
+ title={full}
+ sx={{
+ maxWidth: "inherit",
+ display: "inline-block",
+ overflow: "hidden",
+ textOverflow: "ellipsis",
+ whiteSpace: "nowrap",
+ verticalAlign: "bottom",
+ width: "100%",
+ }}
+ >
+ {full}
+ </Box>
+ );
+ }}
+ />
+ <TextField source="clientIp" label="table.field.httpAuditLog.clientIp" />
+ <FunctionField
+ source="okFlag"
+ label="table.field.httpAuditLog.okFlag"
+ render={(record) =>
+ record.okFlag === 1 ? (
+ <Chip
+ label={translate("table.field.httpAuditLog.okNormal")}
+ color="success"
+ size="small"
+ variant="outlined"
+ />
+ ) : (
+ <Chip
+ label={translate("table.field.httpAuditLog.okAbnormal")}
+ color="error"
+ size="small"
+ variant="outlined"
+ />
+ )
+ }
+ />
+ <NumberField source="httpStatus" label="table.field.httpAuditLog.httpStatus" />
+ <FunctionField
+ source="spendMs"
+ label="table.field.httpAuditLog.spendMs"
+ render={(record) =>
+ record.spendMs == null ? "" : String(Number((Number(record.spendMs) / 1000).toFixed(3)))
+ }
+ />
+ <FunctionField
+ source="responseTruncated"
+ label="table.field.httpAuditLog.responseTruncated"
+ render={(record) =>
+ record.responseTruncated === 1
+ ? translate("table.field.httpAuditLog.truncatedYes")
+ : translate("table.field.httpAuditLog.truncatedNo")
+ }
+ />
+ <DateField source="createTime" label="common.field.createTime" showTime />
+ <WrapperField label="common.field.opt" cellClassName="opt">
+ <ShowButton label="toolbar.detail" sx={{ padding: "1px", fontSize: ".75rem" }} />
+ </WrapperField>
+ </StyledDatagrid>
+ </List>
+ </Box>
+ );
+};
export default HttpAuditLogList;
--
Gitblit v1.9.1