错误页面

This commit is contained in:
unknown 2023-07-29 17:58:39 +08:00
parent 23d0e6265c
commit 5f959f3719
4 changed files with 62 additions and 22 deletions

View File

@ -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,

View File

@ -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);
}

View File

@ -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 (
<Result
status="404"
title="404"
subTitle="您访问的页面不存在"
title={code}
subTitle={error}
className={styles["main"]}
extra={
<Button

View File

@ -1,13 +1,5 @@
import { useEffect, useState } from "react";
import {
Table,
Typography,
Input,
Select,
Space,
Button,
DatePicker,
} from "antd";
import { Table, Typography, Input, Button, DatePicker } from "antd";
import { adminLog } from "../../../api";
// import styles from "./index.module.less";
import type { ColumnsType } from "antd/es/table";
@ -38,7 +30,7 @@ const SystemLogPage = () => {
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<any>([]);
const [createdAts, setCreatedAts] = useState<any>([]);
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) => <span>{record.id}</span>,
},
{
title: "管理员",
title: "管理员名称",
width: 150,
render: (_, record: any) => <span>{record.admin_name}</span>,
},
@ -156,6 +148,31 @@ const SystemLogPage = () => {
<div className="d-flex"></div>
<div className="d-flex">
<div className="d-flex mr-24">
<Typography.Text></Typography.Text>
<Input
value={title}
onChange={(e) => {
setTitle(e.target.value);
}}
allowClear
style={{ width: 160 }}
placeholder="请输入标题"
/>
</div>
<div className="d-flex mr-24">
<Typography.Text>ID</Typography.Text>
<Input
value={adminId}
onChange={(e) => {
setAdminId(e.target.value);
}}
allowClear
style={{ width: 160 }}
placeholder="请输入管理员ID"
/>
</div>
<div className="d-flex mr-24">
<Typography.Text></Typography.Text>
<RangePicker
disabledDate={disabledDate}
format={"YYYY-MM-DD"}