import React, { Component } from 'react' import { Alert, Button, Card, Descriptions, Form, Popconfirm, Input, message as Message, Select, DatePicker, } from 'antd' import { Auth, Container, QueryTable } from 'components' import { api } from 'common/api' import { toCamelCase } from 'util/format' import { isEqual } from 'lodash' import getDictData from 'util/dic' import moment from 'moment' const { RangePicker } = DatePicker const apiAction = { page: api.sysVisLogPage, delete: api.sysVisLogDelete, } export default class index extends Component { state = { codes: { visType: [], }, } // 表格实例 table = React.createRef() // 表格字段 columns = [ { title: '日志名称', dataIndex: 'name', width: 200, sorter: true, }, { title: '访问类型', dataIndex: 'visType', width: 120, render: text => <>{this.bindCodeValue(text, 'vis_type')}, sorter: true, }, { title: '是否成功', dataIndex: 'success', width: 120, render: text => ( <> {text ? ( ) : ( )} ), sorter: true, }, { title: 'ip', dataIndex: 'ip', width: 180, sorter: true, }, { title: '浏览器', dataIndex: 'browser', width: 180, sorter: true, }, { title: '访问时间', dataIndex: 'visTime', width: 180, sorter: true, defaultSortOrder: 'descend', }, { title: '访问人', dataIndex: 'account', width: 180, sorter: true, }, ] /** * 阻止外部组件引发的渲染,提升性能 * 可自行添加渲染条件 * [必要] * @param {*} props * @param {*} state * @returns */ shouldComponentUpdate(props, state) { return !isEqual(this.state, state) } /** * 加载字典数据,之后开始加载表格数据 * 如果必须要加载字典数据,可直接对表格设置autoLoad=true */ componentDidMount() { this.table.current.onLoading() getDictData('vis_type').then(res => { this.setState( { codes: res, }, () => { this.table.current.onLoadData() } ) }) } /** * 调用加载数据接口,可在调用前对query进行处理 * [异步,必要] * @param {*} params * @param {*} query * @returns */ loadData = async (params, query) => { if (query.dates && query.dates.length) { query.searchBeginTime = moment(query.dates[0]).format('YYYY-MM-DD HH:mm:ss') query.searchEndTime = moment(query.dates[1]).format('YYYY-MM-DD HH:mm:ss') delete query.dates } const { data } = await apiAction.page({ ...params, ...query, }) return data } /** * 绑定字典数据 * @param {*} code * @param {*} name * @returns */ bindCodeValue(code, name) { name = toCamelCase(name) const codes = this.state.codes[name] if (codes) { const c = codes.find(p => +p.code === code) if (c) { return c.value } } return null } /** * 对表格上的操作进行统一处理 * [异步] * @param {*} action * @param {*} successMessage */ async onAction(action, successMessage) { this.table.current.onLoading() try { await action Message.success(successMessage) this.table.current.onReloadData() } catch { this.table.current.onLoaded() } } onVisLogClear() { this.onAction(apiAction.delete(), '清空成功') } render() { return (

} operator={ this.onVisLogClear()} > } expandable={{ expandedRowRender: record => ( {record.message} ), }} />
) } }