| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609 |
- "use client";
- import {fetchApi, fetchFile} from "@/app/_modules/func";
- import {ClearOutlined, DeleteOutlined, ExclamationCircleFilled, EyeOutlined, ReloadOutlined,} from "@ant-design/icons";
- import type {ActionType, ProColumns, ProFormInstance,} from "@ant-design/pro-components";
- import {PageContainer, ProDescriptions, ProTable,} from "@ant-design/pro-components";
- import {Button, Modal, Space, Tag} from "antd";
- import {useRouter} from "next/navigation";
- import {faCheck, faDownload, faToggleOff, faToggleOn, faXmark,} from "@fortawesome/free-solid-svg-icons";
- import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
- import {useRef, useState} from "react";
- export default function OperLog() {
- const { push } = useRouter();
- // 添加用于控制删除确认模态框的状态
- const [deleteModalVisible, setDeleteModalVisible] = useState(false);
-
- // 添加用于控制清空确认模态框的状态
- const [clearModalVisible, setClearModalVisible] = useState(false);
- //表格列定义
- const columns: ProColumns[] = [
- {
- title: "日志编号",
- dataIndex: "operId",
- search: false,
- },
- {
- title: "系统模块",
- fieldProps: {
- placeholder: "请输入系统模块",
- },
- dataIndex: "title",
- order: 9,
- },
- {
- title: "操作类型",
- fieldProps: {
- placeholder: "请选择操作类型",
- },
- dataIndex: "businessType",
- order: 7,
- valueEnum: {
- 1: {
- text: "新增",
- status: "1",
- },
- 2: {
- text: "修改",
- status: "2",
- },
- 3: {
- text: "删除",
- status: "3",
- },
- 4: {
- text: "授权",
- status: "4",
- },
- 5: {
- text: "导出",
- status: "5",
- },
- 6: {
- text: "导入",
- status: "6",
- },
- 7: {
- text: "强退",
- status: "7",
- },
- 8: {
- text: "生成代码",
- status: "8",
- },
- 9: {
- text: "清空数据",
- status: "9",
- },
- 0: {
- text: "其他",
- status: "0",
- },
- },
- },
- {
- title: "操作人员",
- fieldProps: {
- placeholder: "请输入操作人员",
- },
- dataIndex: "operName",
- sorter: true,
- order: 8,
- },
- {
- title: "操作地址",
- fieldProps: {
- placeholder: "请输入操作地址",
- },
- dataIndex: "operIp",
- order: 10,
- },
- {
- title: "操作地点",
- dataIndex: "operLocation",
- search: false,
- },
- {
- title: "操作状态",
- fieldProps: {
- placeholder: "请选择操作状态",
- },
- dataIndex: "status",
- valueType: "select",
- render: (_, record) => {
- return (
- <Space>
- <Tag
- color={record.status == 0 ? "green" : "red"}
- icon={
- record.status == 0 ? (
- <FontAwesomeIcon icon={faCheck} />
- ) : (
- <FontAwesomeIcon icon={faXmark} />
- )
- }
- >
- {_}
- </Tag>
- </Space>
- );
- },
- valueEnum: {
- 0: {
- text: "成功",
- status: "0",
- },
- 1: {
- text: "失败",
- status: "1",
- },
- },
- order: 6,
- },
- {
- title: "操作时间",
- dataIndex: "operTime",
- valueType: "dateTime",
- search: false,
- sorter: true,
- },
- {
- title: "操作时间",
- fieldProps: {
- placeholder: ["开始日期", "结束日期"],
- },
- dataIndex: "operTimeRange",
- valueType: "dateRange",
- hideInTable: true,
- order: 5,
- search: {
- transform: (value) => {
- return {
- "params[beginTime]": `${value[0]} 00:00:00`,
- "params[endTime]": `${value[1]} 23:59:59`,
- };
- },
- },
- },
- {
- title: "消耗时间",
- dataIndex: "costTime",
- sorter: true,
- search: false,
- render: (_, record) => {
- return <span>{_}毫秒</span>;
- },
- },
- {
- title: "操作",
- key: "option",
- search: false,
- render: (_, record) => [
- <Button
- key={record.operId}
- type="link"
- icon={<EyeOutlined />}
- onClick={() => showRowModal(record)}
- >
- 详情
- </Button>,
- ],
- },
- ];
- //查询日志数据
- const getLog = async (params: any, sorter: any, filter: any) => {
- const searchParams = {
- pageNum: params.current,
- ...params,
- };
- delete searchParams.current;
- const queryParams = new URLSearchParams(searchParams);
- Object.keys(sorter).forEach((key) => {
- queryParams.append("orderByColumn", key);
- if (sorter[key] === "ascend") {
- queryParams.append("isAsc", "ascending");
- } else {
- queryParams.append("isAsc", "descending");
- }
- });
- const body = await fetchApi(
- `/api/monitor/operlog/list?${queryParams}`,
- push
- );
- console.log("data:", body);
- return body;
- };
- //删除按钮是否可用,选中行时才可用
- const [rowCanDelete, setRowCanDelete] = useState(false);
- //选中行操作
- const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
- const rowSelection = {
- onChange: (newSelectedRowKeys: React.Key[]) => {
- setSelectedRowKeys(newSelectedRowKeys);
- setRowCanDelete(newSelectedRowKeys && newSelectedRowKeys.length > 0);
- },
- };
- //点击删除按钮
- const onClickDeleteRow = () => {
- setDeleteModalVisible(true);
- };
- //点击清空按钮
- const onClickClear = () => {
- setClearModalVisible(true);
- };
- //确定删除选中的日志数据
- const executeDeleteRow = async () => {
- const body = await fetchApi(
- `/api/monitor/operlog/${selectedRowKeys.join(",")}`,
- push,
- {
- method: "DELETE",
- }
- );
- if (body !== undefined) {
- if (body.code == 200) {
- App.useApp().message.success("删除成功");
- //删除按钮变回不可点击
- setRowCanDelete(false);
- //选中的数据恢复为空
- setSelectedRowKeys([]);
- //刷新列表
- if (actionRef.current) {
- actionRef.current.reload();
- }
- } else {
- App.useApp().message.error(body.msg);
- }
- }
- setDeleteModalVisible(false);
- };
- //确定清空日志数据
- const executeClear = async () => {
- const body = await fetchApi("/api/monitor/operlog/clean", push, {
- method: "DELETE",
- });
- if (body !== undefined) {
- if (body.code == 200) {
- App.useApp().message.success("清空成功");
- //选中的数据恢复为空
- setSelectedRowKeys([]);
- //刷新列表
- if (actionRef.current) {
- actionRef.current.reload();
- }
- } else {
- App.useApp().message.error(body.msg);
- }
- }
- setClearModalVisible(false);
- };
- //控制是否展示行详情模态框
- const [isModalOpen, setIsModalOpen] = useState(false);
- //关闭行详情展示
- function closeRowModal() {
- setIsModalOpen(false);
- }
- const [selectedRow, setSelectedRow] = useState(undefined as any);
- //展示行详情
- function showRowModal(record: any) {
- setIsModalOpen(true);
- setSelectedRow(record);
- }
- //搜索栏显示状态
- const [showSearch, setShowSearch] = useState(true);
- //action对象引用
- const actionRef = useRef<ActionType>(null);
- //表单对象引用
- const formRef = useRef<ProFormInstance>(null!);
- //当前页数和每页条数
- const [page, setPage] = useState(1);
- const defaultPageSize = 10;
- const [pageSize, setPageSize] = useState(defaultPageSize);
- const pageChange = (page: number, pageSize: number) => {
- setPage(page);
- setPageSize(pageSize);
- };
- //导出日志文件
- const exportTable = async () => {
- if (formRef.current) {
- const formData = new FormData();
- const data = {
- pageNum: page,
- pageSize: pageSize,
- ...formRef.current.getFieldsValue(),
- };
- Object.keys(data).forEach((key) => {
- if (data[key] !== undefined) {
- formData.append(key, data[key]);
- }
- });
- await fetchFile(
- "/api/monitor/operlog/export",
- push,
- {
- method: "POST",
- body: formData,
- },
- `operlog_${new Date().getTime()}.xlsx`
- );
- }
- };
- return (
- <PageContainer title={false}>
- <ProTable
- formRef={formRef}
- rowKey="operId"
- rowSelection={{
- selectedRowKeys,
- ...rowSelection,
- }}
- columns={columns}
- request={async (params: any, sorter: any, filter: any) => {
- // 表单搜索项会从 params 传入,传递给后端接口。
- console.log(params, sorter, filter);
- const data = await getLog(params, sorter, filter);
- if (data !== undefined) {
- return Promise.resolve({
- data: data.rows,
- success: true,
- total: data.total,
- });
- }
- return Promise.resolve({
- data: [],
- success: true,
- });
- }}
- pagination={{
- defaultPageSize: defaultPageSize,
- showQuickJumper: true,
- showSizeChanger: true,
- onChange: pageChange,
- }}
- search={
- showSearch
- ? {
- defaultCollapsed: false,
- searchText: "搜索",
- }
- : false
- }
- dateFormatter="string"
- actionRef={actionRef}
- toolbar={{
- actions: [
- <Button
- key="danger"
- danger
- icon={<DeleteOutlined />}
- disabled={!rowCanDelete}
- onClick={onClickDeleteRow}
- >
- 删除
- </Button>,
- <Button
- key="clear"
- danger
- icon={<ClearOutlined />}
- onClick={onClickClear}
- >
- 清空
- </Button>,
- <Button
- key="export"
- type="primary"
- icon={<FontAwesomeIcon icon={faDownload} />}
- onClick={exportTable}
- >
- 导出
- </Button>,
- ],
- settings: [
- {
- key: "switch",
- icon: showSearch ? (
- <FontAwesomeIcon icon={faToggleOn} />
- ) : (
- <FontAwesomeIcon icon={faToggleOff} />
- ),
- tooltip: showSearch ? "隐藏搜索栏" : "显示搜索栏",
- onClick: (key: string | undefined) => {
- setShowSearch(!showSearch);
- },
- },
- {
- key: "refresh",
- tooltip: "刷新",
- icon: <ReloadOutlined />,
- onClick: (key: string | undefined) => {
- if (actionRef.current) {
- actionRef.current.reload();
- }
- },
- },
- ],
- }}
- />
- {selectedRow !== undefined && (
- <Modal
- title="操作日志详情"
- footer={<Button onClick={closeRowModal}>关闭</Button>}
- open={isModalOpen}
- onCancel={closeRowModal}
- >
- <ProDescriptions column={10}>
- <ProDescriptions.Item span={3} label="操作模块">
- {selectedRow.title} /
- </ProDescriptions.Item>
- <ProDescriptions.Item
- span={2}
- valueEnum={{
- 1: {
- text: "新增",
- status: "1",
- },
- 2: {
- text: "修改",
- status: "2",
- },
- 3: {
- text: "删除",
- status: "3",
- },
- 4: {
- text: "授权",
- status: "4",
- },
- 5: {
- text: "导出",
- status: "5",
- },
- 6: {
- text: "导入",
- status: "6",
- },
- 7: {
- text: "强退",
- status: "7",
- },
- 8: {
- text: "生成代码",
- status: "8",
- },
- 9: {
- text: "清空数据",
- status: "9",
- },
- 0: {
- text: "其他",
- status: "0",
- },
- }}
- >
- {selectedRow.businessType}
- </ProDescriptions.Item>
- <ProDescriptions.Item span={5} label="请求地址">
- {selectedRow.operUrl}
- </ProDescriptions.Item>
- </ProDescriptions>
- <ProDescriptions column={6}>
- <ProDescriptions.Item span={3} label="登录信息">
- {selectedRow.operName}/{selectedRow.operIp}/
- {selectedRow.operLocation}
- </ProDescriptions.Item>
- <ProDescriptions.Item span={3} label="请求方式">
- {selectedRow.requestMethod}
- </ProDescriptions.Item>
- <ProDescriptions.Item span={6} label="操作方法">
- {selectedRow.method}
- </ProDescriptions.Item>
- <ProDescriptions.Item span={6} label="请求参数">
- {selectedRow.operParam}
- </ProDescriptions.Item>
- <ProDescriptions.Item span={6} label="返回参数">
- {selectedRow.jsonResult}
- </ProDescriptions.Item>
- </ProDescriptions>
- <ProDescriptions column={8}>
- <ProDescriptions.Item
- span={2}
- label="操作状态"
- valueEnum={{
- 0: {
- text: "成功",
- status: "0",
- },
- 1: {
- text: "失败",
- status: "1",
- },
- }}
- >
- {selectedRow.status}
- </ProDescriptions.Item>
- <ProDescriptions.Item span={2} label="消耗时间">
- {selectedRow.costTime}
- </ProDescriptions.Item>
- <ProDescriptions.Item span={4} label="操作时间">
- {selectedRow.operTime}
- </ProDescriptions.Item>
- </ProDescriptions>
- {selectedRow.errorMsg && (
- <ProDescriptions>
- <ProDescriptions.Item label="异常信息">
- {selectedRow.errorMsg}
- </ProDescriptions.Item>
- </ProDescriptions>
- )}
- </Modal>
- )}
- {/* 删除确认模态框 */}
- <Modal
- title={
- <div style={{ display: 'flex', alignItems: 'center' }}>
- <ExclamationCircleFilled style={{ color: '#faad14', marginRight: 8 }} />
- <span>系统提示</span>
- </div>
- }
- open={deleteModalVisible}
- onOk={executeDeleteRow}
- onCancel={() => setDeleteModalVisible(false)}
- okText="确认"
- cancelText="取消"
- >
- <p>{`确定删除日志编号为“${selectedRowKeys.join(",")}”的数据项?`}</p>
- </Modal>
-
- {/* 清空确认模态框 */}
- <Modal
- title={
- <div style={{ display: 'flex', alignItems: 'center' }}>
- <ExclamationCircleFilled style={{ color: '#faad14', marginRight: 8 }} />
- <span>系统提示</span>
- </div>
- }
- open={clearModalVisible}
- onOk={executeClear}
- onCancel={() => setClearModalVisible(false)}
- okText="确认"
- cancelText="取消"
- >
- <p>是否确认清空所有操作日志数据项?</p>
- </Modal>
- </PageContainer>
- );
- }
|