import { Card, Table, Tabs, Tag, Input, Space, Button, DatePicker, Select } from "antd"; import { useEffect, useState } from "react"; import { fetchLogs } from "../api"; import { SearchOutlined, ReloadOutlined } from "@ant-design/icons"; import dayjs from "dayjs"; const { RangePicker } = DatePicker; export default function Logs() { const [activeTab, setActiveTab] = useState("OPERATION"); const [loading, setLoading] = useState(false); const [data, setData] = useState([]); const [total, setTotal] = useState(0); const [params, setParams] = useState({ current: 1, size: 10, username: "", status: undefined, startDate: "", endDate: "" }); const loadData = async (currentParams = params) => { setLoading(true); try { const operationType = activeTab === "LOGIN" ? "LOGIN" : "OPERATION"; const result = await fetchLogs({ ...currentParams, operationType }); setData(result.records || []); setTotal(result.total || 0); } finally { setLoading(false); } }; useEffect(() => { loadData(); }, [activeTab, params.current, params.size]); const handleSearch = () => { setParams({ ...params, current: 1 }); loadData({ ...params, current: 1 }); }; const handleReset = () => { const resetParams = { current: 1, size: 10, username: "", status: undefined, startDate: "", endDate: "" }; setParams(resetParams); loadData(resetParams); }; const columns = [ { title: "用户名", dataIndex: "username", key: "username", width: 120, render: (text: string) => text || "系统/访客" }, { title: activeTab === "LOGIN" ? "登录模块" : "操作模块", dataIndex: "resourceType", key: "resourceType", width: 150 }, { title: "操作详情", dataIndex: "detail", key: "detail", ellipsis: true }, { title: "IP地址", dataIndex: "ipAddress", key: "ipAddress", width: 140 }, { title: "状态", dataIndex: "status", key: "status", width: 100, render: (status: number) => ( {status === 1 ? "成功" : "失败"} ) }, { title: "操作时间", dataIndex: "createdAt", key: "createdAt", width: 180, render: (text: string) => text?.replace('T', ' ').substring(0, 19) } ]; if (activeTab === "OPERATION") { columns.splice(1, 0, { title: "请求方式", dataIndex: "operationType", key: "operationType", width: 100, render: (t: string) => {t} }); } return (
setParams({ ...params, username: e.target.value })} />