import { PageContainer, ProList } from '@ant-design/pro-components';
import { Card } from 'antd';
import moment from 'moment';
import request from 'umi-request';
import transInfo, { LogsItem } from './logItem';

const Logs: React.FC = () => {
  return (
    <PageContainer>
      <Card>
        <ProList<LogsItem>
          search={{
            filterType: 'light',
          }}
          rowKey="op"
          headerTitle="日志列表"
          request={async (params = {} as Record<string, any>) =>
            request<{
              data: LogsItem[];
            }>('/admin/loglist', {
              params,
            })
          }
          pagination={{
            pageSize: 10,
          }}
          metas={{
            title: {
              dataIndex: 'op',
              title: '用户',
            },
            avatar: {
              dataIndex: 'avatar',
              search: false,
            },
            description: {
              dataIndex: ['operation', 'target', 'prev', 'curr'],
              search: false,
              render: (_, row) => {
                return (
                  <div>
                    {transInfo(row.operation, 'operation') +
                      '了' +
                      transInfo(row.target, 'target') +
                      '：' +
                      row.prev.info +
                      ' -> ' +
                      row.curr.info}
                  </div>
                );
              },
            },
            extra: {
              dataIndex: 'time',
              render: (_: React.ReactNode, row: LogsItem) => {
                return (
                  <div style={{ marginLeft: '3vh' }}>
                    {moment(row.time).format('YYYY-M-D HH:mm:ss')}
                  </div>
                );
              },
              search: false,
            },
            actions: {
              render: () => [
                <a href="" target="_blank" rel="noopener noreferrer" key="view">
                  查看
                </a>,
              ],
              search: false,
            },
            operation: {
              // 自己扩展的字段，主要用于筛选，不在列表中显示
              title: '操作',
              valueType: 'select',
              valueEnum: {
                all: { text: '全部', status: 'Default' },
                add: {
                  text: '增加',
                  status: '0',
                },
                delete: {
                  text: '删除',
                  status: '1',
                },
                change: {
                  text: '更改',
                  status: '2',
                },
              },
            },
            target: {
              // 自己扩展的字段，主要用于筛选，不在列表中显示
              title: '操作对象',
              valueType: 'select',
              valueEnum: {
                all: { text: '全部', status: 'Default' },
                dutyTable: {
                  text: '值班表',
                },
                dutyInfo: {
                  text: '值班信息',
                },
                conclusion: {
                  text: '值班总结',
                },
              },
            },
          }}
        />
      </Card>
    </PageContainer>
  );
};
export default Logs;
