import { logPage } from '@/services/system/log';


import React, { useRef, useEffect } from 'react';
import { useIntl, useAccess } from '@umijs/max';
import { message, Tag } from 'antd';
import { ActionType, PageContainer, ProTable } from '@ant-design/pro-components';




const LogTableList: React.FC = () => {
  const actionRef = useRef<ActionType>();

  const columns = [
    {
      title: 'ID',
      dataIndex: 'id',
      valueType: 'text',
      search: false,
    },
    {
      title: '标题',
      dataIndex: 'title',
      valueType: 'text',
      search: false,
    },
    {
      title: '类型',
      dataIndex: 'businessType',
      valueType: 'text',
      search: false,
      render: (_: any, record: any) => {
        let color = record.businessType == 1 ? 'volcano' : record.businessType == 2 ? 'orange' : 'red'
        return <Tag color={color}>{record.businessType}</Tag>
      }
    },
    {
      title: '方法',
      dataIndex: 'method',
      valueType: 'text',
      search: false,
    },
    {
      title: '请求方式',
      dataIndex: 'requestMethod',
      valueType: 'text',
      search: false,
    },
    {
      title: '操作类别',
      dataIndex: 'operatorType',
      valueType: 'text',
      search: false,
    },
    {
      title: '操作人员',
      dataIndex: 'operName',
      valueType: 'text',
      search: false,
    },
    {
      title: '请求URL',
      dataIndex: 'operUrl',
      valueType: 'text',
      search: false,
    },

    {
      title: '主机地址',
      dataIndex: 'operIp',
      valueType: 'text',
      search: false,
    },
    {
      title: '操作地点',
      dataIndex: 'operLocation',
      valueType: 'text',
      search: false,
    },
    {
      title: '请求参数',
      dataIndex: 'operParam',
      valueType: 'text',
      search: false,
    },
    {
      title: '返回参数',
      dataIndex: 'jsonResult',
      valueType: 'text',
      search: false,
    },
    {
      title: '状态',
      dataIndex: 'status',
      valueType: 'text',
      search: false,
    },
    {
      title: '错误消息',
      dataIndex: 'errorMsg',
      valueType: 'text',
      search: false,
    },
    {
      title: '操作时间',
      dataIndex: 'operTime',
      valueType: 'text',
      search: false,
    },
    {
      title: '消耗时间',
      dataIndex: 'costTime',
      valueType: 'text',
      search: false,
    },
  ];

  return (
    <PageContainer>
      <div style={{ width: '100%', float: 'right' }}>
        <ProTable
          actionRef={actionRef}
          rowKey="id"
          key="logList"
          search={{
            labelWidth: 120,
          }}
          request={async (params, sorter, filter) => {
            let { data } = await logPage(params)
            return {
              data: data?.records || [],
              total: data?.total,
            };
          }}
          columns={columns}
        />
      </div>
    </PageContainer>
  );
};

export default LogTableList;
