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/HttpAuditLogShow.jsx | 258 ++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 210 insertions(+), 48 deletions(-)
diff --git a/rsf-admin/src/page/system/httpAuditLog/HttpAuditLogShow.jsx b/rsf-admin/src/page/system/httpAuditLog/HttpAuditLogShow.jsx
index dab8957..4b10850 100644
--- a/rsf-admin/src/page/system/httpAuditLog/HttpAuditLogShow.jsx
+++ b/rsf-admin/src/page/system/httpAuditLog/HttpAuditLogShow.jsx
@@ -1,59 +1,221 @@
import React from "react";
-import { Show, SimpleShowLayout, TextField, DateField, FunctionField } from "react-admin";
-import { Box, Chip } from "@mui/material";
+import { Link } from "react-router-dom";
+import ArrowBackIcon from "@mui/icons-material/ArrowBack";
+import { Show, TopToolbar, useRecordContext, useTranslate, useCreatePath, useResourceContext } from "react-admin";
+import { Box, Button, Chip, Divider, Paper, Stack, Typography } from "@mui/material";
+
+const HttpAuditLogShowActions = () => {
+ const translate = useTranslate();
+ const resource = useResourceContext();
+ const createPath = useCreatePath();
+ const listPath = createPath({ resource, type: "list" });
+ return (
+ <TopToolbar>
+ <Button
+ component={Link}
+ to={listPath}
+ variant="outlined"
+ size="small"
+ startIcon={<ArrowBackIcon fontSize="small" />}
+ sx={{ textTransform: "none" }}
+ >
+ {translate("common.button.backToList")}
+ </Button>
+ </TopToolbar>
+ );
+};
const JsonBlock = ({ text }) => (
- <Box component="pre" sx={{ whiteSpace: "pre-wrap", wordBreak: "break-all", m: 0, fontSize: 12 }}>
+ <Box
+ component="pre"
+ sx={{
+ whiteSpace: "pre-wrap",
+ wordBreak: "break-all",
+ m: 0,
+ fontSize: 12,
+ fontFamily: "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",
+ bgcolor: (t) => (t.palette.mode === "dark" ? "grey.900" : "grey.50"),
+ color: "text.primary",
+ border: 1,
+ borderColor: "divider",
+ borderRadius: 1,
+ p: 1.5,
+ maxHeight: 360,
+ overflow: "auto",
+ }}
+ >
{text ?? ""}
</Box>
);
+const CompactItem = ({ labelKey, children }) => {
+ const translate = useTranslate();
+ return (
+ <Box
+ sx={{
+ minWidth: 108,
+ maxWidth: 260,
+ flex: "0 1 auto",
+ px: 1.25,
+ py: 1,
+ borderRadius: 1,
+ bgcolor: (t) => (t.palette.mode === "dark" ? "action.hover" : "grey.50"),
+ border: 1,
+ borderColor: "divider",
+ }}
+ >
+ <Typography variant="caption" color="text.secondary" component="div" sx={{ lineHeight: 1.4 }}>
+ {translate(labelKey)}
+ </Typography>
+ <Box sx={{ mt: 0.5 }}>{children}</Box>
+ </Box>
+ );
+};
+
+const BlockItem = ({ labelKey, children }) => {
+ const translate = useTranslate();
+ return (
+ <Box sx={{ width: "100%" }}>
+ <Typography
+ variant="subtitle2"
+ color="text.secondary"
+ component="div"
+ sx={{ mb: 0.75, fontWeight: 600 }}
+ >
+ {translate(labelKey)}
+ </Typography>
+ <Box>{children}</Box>
+ </Box>
+ );
+};
+
+const SectionTitle = ({ labelKey }) => {
+ const translate = useTranslate();
+ return (
+ <Typography variant="subtitle1" sx={{ fontWeight: 600, color: "text.primary", mb: 1.5 }}>
+ {translate(labelKey)}
+ </Typography>
+ );
+};
+
+const HttpAuditLogShowContent = () => {
+ const record = useRecordContext();
+ const translate = useTranslate();
+
+ if (!record) {
+ return null;
+ }
+
+ const spendSec =
+ record.spendMs == null ? "" : String(Number((Number(record.spendMs) / 1000).toFixed(3)));
+ const truncatedLabel =
+ record.responseTruncated === 1
+ ? translate("table.field.httpAuditLog.truncatedYes")
+ : translate("table.field.httpAuditLog.truncatedNo");
+
+ return (
+ <Box sx={{ p: 2, pb: 4, maxWidth: 1200, mx: "auto" }}>
+ <Paper variant="outlined" sx={{ p: 2.5, mb: 2, borderRadius: 2 }}>
+ <SectionTitle labelKey="httpAuditLog.show.sectionSummary" />
+ <Stack direction="row" flexWrap="wrap" useFlexGap spacing={1.5} sx={{ alignItems: "stretch" }}>
+ <CompactItem labelKey="common.field.id">
+ <Typography variant="body2" fontWeight={500}>
+ {record.id ?? ""}
+ </Typography>
+ </CompactItem>
+ <CompactItem labelKey="table.field.httpAuditLog.serviceName">
+ <Typography variant="body2" sx={{ wordBreak: "break-all" }}>
+ {record.serviceName ?? ""}
+ </Typography>
+ </CompactItem>
+ <CompactItem labelKey="table.field.httpAuditLog.scopeType">
+ <Typography variant="body2">{record.scopeType ?? ""}</Typography>
+ </CompactItem>
+ <CompactItem labelKey="table.field.httpAuditLog.ioDirection">
+ <Typography variant="body2">{record.ioDirection ?? ""}</Typography>
+ </CompactItem>
+ <CompactItem labelKey="table.field.httpAuditLog.method">
+ <Typography variant="body2" fontWeight={500}>
+ {record.method ?? ""}
+ </Typography>
+ </CompactItem>
+ <CompactItem labelKey="table.field.httpAuditLog.clientIp">
+ <Typography variant="body2">{record.clientIp ?? ""}</Typography>
+ </CompactItem>
+ <CompactItem labelKey="table.field.httpAuditLog.okFlag">
+ {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"
+ />
+ )}
+ </CompactItem>
+ <CompactItem labelKey="table.field.httpAuditLog.httpStatus">
+ <Typography variant="body2">{record.httpStatus ?? ""}</Typography>
+ </CompactItem>
+ <CompactItem labelKey="table.field.httpAuditLog.spendMs">
+ <Typography variant="body2">{spendSec}</Typography>
+ </CompactItem>
+ <CompactItem labelKey="table.field.httpAuditLog.responseTruncated">
+ <Typography variant="body2">{truncatedLabel}</Typography>
+ </CompactItem>
+ <CompactItem labelKey="common.field.createTime">
+ <Typography variant="body2" sx={{ wordBreak: "break-all" }}>
+ {record.createTime != null ? String(record.createTime) : ""}
+ </Typography>
+ </CompactItem>
+ </Stack>
+ </Paper>
+
+ <Paper variant="outlined" sx={{ p: 2.5, mb: 2, borderRadius: 2 }}>
+ <SectionTitle labelKey="httpAuditLog.show.sectionRequest" />
+ <Stack spacing={2}>
+ <BlockItem labelKey="table.field.httpAuditLog.uri">
+ <Typography variant="body2" sx={{ wordBreak: "break-all", lineHeight: 1.6 }}>
+ {record.uri ?? ""}
+ </Typography>
+ </BlockItem>
+ <BlockItem labelKey="table.field.httpAuditLog.functionDesc">
+ <Typography variant="body2" sx={{ wordBreak: "break-all", lineHeight: 1.6 }}>
+ {record.functionDesc ?? ""}
+ </Typography>
+ </BlockItem>
+ </Stack>
+ </Paper>
+
+ <Paper variant="outlined" sx={{ p: 2.5, borderRadius: 2 }}>
+ <SectionTitle labelKey="httpAuditLog.show.sectionPayload" />
+ <Stack spacing={2.5} divider={<Divider flexItem />}>
+ <BlockItem labelKey="table.field.httpAuditLog.queryString">
+ <JsonBlock text={record.queryString} />
+ </BlockItem>
+ <BlockItem labelKey="table.field.httpAuditLog.requestBody">
+ <JsonBlock text={record.requestBody} />
+ </BlockItem>
+ <BlockItem labelKey="table.field.httpAuditLog.responseBody">
+ <JsonBlock text={record.responseBody} />
+ </BlockItem>
+ <BlockItem labelKey="table.field.httpAuditLog.errorMessage">
+ <JsonBlock text={record.errorMessage} />
+ </BlockItem>
+ </Stack>
+ </Paper>
+ </Box>
+ );
+};
+
const HttpAuditLogShow = () => (
- <Show>
- <SimpleShowLayout>
- <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
- 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" />
- )
- }
- />
- <TextField source="httpStatus" label="table.field.httpAuditLog.httpStatus" />
- <TextField source="spendMs" label="table.field.httpAuditLog.spendMs" />
- <TextField source="responseTruncated" label="table.field.httpAuditLog.responseTruncated" />
- <DateField source="createTime" label="common.field.createTime" showTime />
- <FunctionField
- source="queryString"
- label="table.field.httpAuditLog.queryString"
- render={(record) => <JsonBlock text={record.queryString} />}
- />
- <FunctionField
- source="requestBody"
- label="table.field.httpAuditLog.requestBody"
- render={(record) => <JsonBlock text={record.requestBody} />}
- />
- <FunctionField
- source="responseBody"
- label="table.field.httpAuditLog.responseBody"
- render={(record) => <JsonBlock text={record.responseBody} />}
- />
- <FunctionField
- source="errorMessage"
- label="table.field.httpAuditLog.errorMessage"
- render={(record) => <JsonBlock text={record.errorMessage} />}
- />
- </SimpleShowLayout>
+ <Show actions={<HttpAuditLogShowActions />}>
+ <HttpAuditLogShowContent />
</Show>
);
--
Gitblit v1.9.1