From a6923632d1645d6ac0fe516cc4e7576d44d3a9d6 Mon Sep 17 00:00:00 2001 From: unknown <18119604035@163.com> Date: Sat, 29 Jul 2023 17:27:21 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/admin-log.ts | 21 ++ src/api/index.ts | 1 + src/compenents/left-menu/index.tsx | 1 + src/main.tsx | 1 + src/pages/system/adminlog/index.module.less | 0 src/pages/system/adminlog/index.tsx | 180 ++++++++++++++++++ .../system/adminroles/compenents/create.tsx | 5 + .../system/adminroles/compenents/update.tsx | 5 + src/routes/index.tsx | 5 + src/utils/index.ts | 7 + 10 files changed, 226 insertions(+) create mode 100644 src/api/admin-log.ts create mode 100644 src/pages/system/adminlog/index.module.less create mode 100644 src/pages/system/adminlog/index.tsx diff --git a/src/api/admin-log.ts b/src/api/admin-log.ts new file mode 100644 index 0000000..f7e68f2 --- /dev/null +++ b/src/api/admin-log.ts @@ -0,0 +1,21 @@ +import client from "./internal/httpClient"; + +export function adminLogList( + page: number, + size: number, + admin_id: number | null, + title: string, + opt: string, + start_time: string, + end_time: string +) { + return client.get("/backend/v1/admin/log/index", { + page: page, + size: size, + admin_id: admin_id, + title: title, + opt: opt, + start_time: start_time, + end_time: end_time, + }); +} diff --git a/src/api/index.ts b/src/api/index.ts index 733df58..927f052 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -14,3 +14,4 @@ export * as upload from "./upload"; export * as user from "./user"; export * as appConfig from "./app-config"; export * as dashboard from "./dashboard"; +export * as adminLog from "./admin-log"; diff --git a/src/compenents/left-menu/index.tsx b/src/compenents/left-menu/index.tsx index 40b26c6..85f7715 100644 --- a/src/compenents/left-menu/index.tsx +++ b/src/compenents/left-menu/index.tsx @@ -91,6 +91,7 @@ const items = [ null, "admin-user-index" ), + getItem("管理日志", "/system/adminlog", null, null, null, "admin-log"), // getItem("角色配置", "/system/adminroles", null, null, null, null), ], null, diff --git a/src/main.tsx b/src/main.tsx index 98bf043..b20c456 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -7,6 +7,7 @@ import { Provider } from "react-redux"; import store from "./store"; import { ConfigProvider } from "antd"; import zhCN from "antd/locale/zh_CN"; +import "dayjs/locale/zh-cn"; import AutoScorllTop from "./AutoTop"; ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( diff --git a/src/pages/system/adminlog/index.module.less b/src/pages/system/adminlog/index.module.less new file mode 100644 index 0000000..e69de29 diff --git a/src/pages/system/adminlog/index.tsx b/src/pages/system/adminlog/index.tsx new file mode 100644 index 0000000..d66cd84 --- /dev/null +++ b/src/pages/system/adminlog/index.tsx @@ -0,0 +1,180 @@ +import { useEffect, useState } from "react"; +import { Table, Typography, Input, Select, Button, DatePicker } from "antd"; +import { adminLog } from "../../../api"; +// import styles from "./index.module.less"; +import type { ColumnsType } from "antd/es/table"; +import { dateWholeFormat } from "../../../utils/index"; +const { RangePicker } = DatePicker; +import moment from "moment"; + +interface DataType { + id: React.Key; + admin_id: number; + ip: string; + opt: string; + adminName: string; + module: string; + created_at: string; + title: string; +} + +const SystemLogPage = () => { + const [loading, setLoading] = useState(true); + const [page, setPage] = useState(1); + const [size, setSize] = useState(10); + const [list, setList] = useState([]); + const [total, setTotal] = useState(0); + const [refresh, setRefresh] = useState(false); + const [title, setTitle] = useState(""); + const [adminId, setAdminId] = useState(0); + const [created_at, setCreatedAt] = useState([]); + const [createdAts, setCreatedAts] = useState([]); + + useEffect(() => { + getData(); + }, [refresh, page, size]); + + const getData = () => { + setLoading(true); + adminLog + .adminLogList( + page, + size, + adminId > 0 ? adminId : null, + title, + "", + created_at[0], + created_at[1] + ) + .then((res: any) => { + setList(res.data.data); + setTotal(res.data.total); + setLoading(false); + }) + .catch((e) => { + setLoading(false); + }); + }; + + const resetData = () => { + setTitle(""); + setAdminId(0); + setPage(1); + setSize(10); + setList([]); + setCreatedAts([]); + setCreatedAt([]); + setRefresh(!refresh); + }; + + const paginationProps = { + current: page, //当前页码 + pageSize: size, + total: total, // 总条数 + onChange: (page: number, pageSize: number) => + handlePageChange(page, pageSize), //改变页码的函数 + showSizeChanger: true, + }; + + const handlePageChange = (page: number, pageSize: number) => { + setPage(page); + setSize(pageSize); + }; + + const disabledDate = (current: any) => { + return current && current >= moment().add(0, "days"); // 选择时间要大于等于当前天。若今天不能被选择,去掉等号即可。 + }; + + const columns: ColumnsType = [ + { + title: "管理员ID", + width: 100, + render: (_, record: any) => {record.admin_id}, + }, + { + title: "管理员", + width: 150, + render: (_, record: any) => {record.adminName}, + }, + { + title: "标题", + render: (_, record: any) => {record.title}, + }, + { + title: "操作模块", + width: 100, + dataIndex: "module", + render: (module: string) => {module}, + }, + { + title: "操作指令", + width: 100, + dataIndex: "opt", + render: (opt: string) => {opt}, + }, + { + title: "IP", + width: 200, + dataIndex: "ip", + render: (ip: string) => {ip}, + }, + { + title: "时间", + width: 200, + dataIndex: "created_at", + render: (created_at: string) => ( + {dateWholeFormat(created_at)} + ), + }, + ]; + + return ( +
+
+
+
+
+ { + dateString[0] += " 00:00:00"; + dateString[1] += " 23:59:59"; + setCreatedAt(dateString); + setCreatedAts(date); + }} + placeholder={["时间-开始", "时间-结束"]} + /> +
+
+ + +
+
+
+
+ record.id} + pagination={paginationProps} + /> + + + ); +}; + +export default SystemLogPage; diff --git a/src/pages/system/adminroles/compenents/create.tsx b/src/pages/system/adminroles/compenents/create.tsx index f6ca78a..cf5d0ba 100644 --- a/src/pages/system/adminroles/compenents/create.tsx +++ b/src/pages/system/adminroles/compenents/create.tsx @@ -62,6 +62,11 @@ export const SystemAdminrolesCreate: React.FC = ({ value: "管理员-n", children: [], }, + { + title: "管理员日志", + value: "管理员日志-n", + children: [], + }, { title: "管理员角色", value: "管理员角色-n", diff --git a/src/pages/system/adminroles/compenents/update.tsx b/src/pages/system/adminroles/compenents/update.tsx index 0638e2e..d2b2639 100644 --- a/src/pages/system/adminroles/compenents/update.tsx +++ b/src/pages/system/adminroles/compenents/update.tsx @@ -65,6 +65,11 @@ export const SystemAdminrolesUpdate: React.FC = ({ value: "管理员-n", children: [], }, + { + title: "管理员日志", + value: "管理员日志-n", + children: [], + }, { title: "管理员角色", value: "管理员角色-n", diff --git a/src/routes/index.tsx b/src/routes/index.tsx index de42930..b137f33 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -39,6 +39,7 @@ const SystemAdministratorPage = lazy( () => import("../pages/system/administrator") ); const SystemAdminrolesPage = lazy(() => import("../pages/system/adminroles")); +const SystemLogPage = lazy(() => import("../pages/system/adminlog")); //部门页面 const DepartmentPage = lazy(() => import("../pages/department")); //测试 @@ -152,6 +153,10 @@ const routes: RouteObject[] = [ path: "/system/adminroles", element: } />, }, + { + path: "/system/adminlog", + element: } />, + }, { path: "/department", element: } />, diff --git a/src/utils/index.ts b/src/utils/index.ts index 05c0a0c..9bc1079 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -133,3 +133,10 @@ export function checkUrl(value: any) { } return url; } + +export function dateWholeFormat(dateStr: string) { + if (!dateStr) { + return ""; + } + return moment(dateStr).format("YYYY-MM-DD HH:mm:ss"); +}