From 5f959f37196ac6484c9fcb5777d8ea2996b0533a Mon Sep 17 00:00:00 2001 From: unknown <18119604035@163.com> Date: Sat, 29 Jul 2023 17:58:39 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=99=E8=AF=AF=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/admin-log.ts | 2 +- src/api/internal/httpClient.ts | 13 +++++---- src/pages/error/index.tsx | 26 +++++++++++++++-- src/pages/system/adminlog/index.tsx | 43 ++++++++++++++++++++--------- 4 files changed, 62 insertions(+), 22 deletions(-) diff --git a/src/api/admin-log.ts b/src/api/admin-log.ts index f7e68f2..2fd0502 100644 --- a/src/api/admin-log.ts +++ b/src/api/admin-log.ts @@ -3,7 +3,7 @@ import client from "./internal/httpClient"; export function adminLogList( page: number, size: number, - admin_id: number | null, + admin_id: string, title: string, opt: string, start_time: string, diff --git a/src/api/internal/httpClient.ts b/src/api/internal/httpClient.ts index 8c75dee..97ca635 100644 --- a/src/api/internal/httpClient.ts +++ b/src/api/internal/httpClient.ts @@ -7,8 +7,8 @@ const GoLogin = () => { window.location.href = "/login"; }; -const GoError = () => { - window.location.href = "/error"; +const GoError = (code: number) => { + window.location.href = "/error?code=" + code; }; export class HttpClient { @@ -56,13 +56,16 @@ export class HttpClient { GoLogin(); } else if (status === 404) { // 跳转到404页面 - GoError(); + GoError(404); } else if (status === 403) { // 跳转到无权限页面 - GoError(); + GoError(403); + } else if (status === 429) { + // 跳转到429页面 + GoError(429); } else if (status === 500) { // 跳转到500异常页面 - GoError(); + GoError(500); } return Promise.reject(error.response); } diff --git a/src/pages/error/index.tsx b/src/pages/error/index.tsx index 9a1a37d..e71298f 100644 --- a/src/pages/error/index.tsx +++ b/src/pages/error/index.tsx @@ -1,15 +1,35 @@ +import { useEffect, useState } from "react"; import { Button, Result } from "antd"; -import { useNavigate } from "react-router-dom"; +import { useParams, useNavigate, useLocation } from "react-router-dom"; import styles from "./index.module.less"; const ErrorPage = () => { const navigate = useNavigate(); + const result = new URLSearchParams(useLocation().search); + const [code, setCode] = useState(Number(result.get("code"))); + const [error, setError] = useState(""); + + useEffect(() => { + setCode(Number(result.get("code"))); + }, [result.get("code")]); + + useEffect(() => { + if (code === 403) { + setError("无权限操作"); + } else if (code === 404) { + setError("URL或资源不存在"); + } else if (code === 429) { + setError("请求次数过多,请稍后再试"); + } else { + setError("系统错误"); + } + }, [code]); return ( { const [total, setTotal] = useState(0); const [refresh, setRefresh] = useState(false); const [title, setTitle] = useState(""); - const [adminId, setAdminId] = useState(0); + const [adminId, setAdminId] = useState(""); const [created_at, setCreatedAt] = useState([]); const [createdAts, setCreatedAts] = useState([]); const [param, setParam] = useState(""); @@ -55,7 +47,7 @@ const SystemLogPage = () => { .adminLogList( page, size, - adminId > 0 ? adminId : null, + adminId, title, "", created_at[0], @@ -73,7 +65,7 @@ const SystemLogPage = () => { const resetData = () => { setTitle(""); - setAdminId(0); + setAdminId(""); setPage(1); setSize(10); setList([]); @@ -107,7 +99,7 @@ const SystemLogPage = () => { render: (_, record: any) => {record.id}, }, { - title: "管理员", + title: "管理员名称", width: 150, render: (_, record: any) => {record.admin_name}, }, @@ -156,6 +148,31 @@ const SystemLogPage = () => {
+ 标题: + { + setTitle(e.target.value); + }} + allowClear + style={{ width: 160 }} + placeholder="请输入标题" + /> +
+
+ 管理员ID: + { + setAdminId(e.target.value); + }} + allowClear + style={{ width: 160 }} + placeholder="请输入管理员ID" + /> +
+
+ 时间: