accessLog.js
8.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
import React,{Component} from 'react';
import './style.less';
import WhiteBar from '../../components/Common/WhiteBar';
import {Table,Input,Form,Button,Row,Col,Select,DatePicker,Message} from 'antd';
import { API_SYS_MONITOR } from '@src/Api';
import axios from '@src/axios/index';
import Utils from '@src/utils/utils';
export default class AccessLog extends Component {
state = {
/* 请求数据 */
dataList: [],
pagination: {},
isLoading: true,
searchData: {},
expandStatus: false,
}
// 查询页数和数量配置
params = {
page: 1,
pageSize: 10
}
// 展开条件
expandMenu = ()=> {
this.setState({
expandStatus: !this.state.expandStatus,
})
}
componentDidMount () {
this.getLogs();
}
// 查询
search = (searchData) => {
this.params.page = 1;
this.getLogs(searchData);
}
// 重置
reset = () => {
this.params.page = 1;
this.getLogs();
}
// 获取日志列表
getLogs = (searchData) => {
this.setState({isLoading: true});
axios.ajax({
url: API_SYS_MONITOR.getSysLogPageListByCondition,
data: {
...searchData,
pageNum: this.params.page,
pageSize: this.params.pageSize
}
}).then((res) => {
this.setState({isLoading: false});
let _this = this;
let dataList = []
if(res && res.records && res.records.length > 0 ) {
dataList= res.records.map((item,index) => {
return {...item,key: index};
});
}
this.setState({
dataList: dataList,
pagination: Utils.pagination(res, (current) => {
_this.params.page = current;
_this.setState({isLoading: true});
this.getLogs(searchData);
})
});
});
}
render () {
const columns = [
{title: '序号', width: 50, dataIndex: 'key', key: 'key', align: 'left',
className:'pLeft',render: (key) => {
return (this.params.page-1)*10 + (key+1);
}},
{title: '日志标题', width: 100, dataIndex: 'logTitle',className: 'tdWidth', key: 'logTitle',render: (logTitle) => {
return Utils.formatTableColumn(logTitle);
}},
{title: '请求地址', width: 250, dataIndex: 'requestUrl', key: 'requestUrl',className: 'tdWidth',render: (requestUrl) => {
return Utils.formatTableColumn(requestUrl);
}},
{title: '传入参数', width: 300, dataIndex: 'requestData', key: 'requestData',className: 'tdWidth',render: (requestData) => {
return Utils.formatTableColumn(requestData);
}},
{title: '日志类型',width:100, dataIndex: 'logType', key: 'logType',render: (logType) => {
return {'1': '查询日志','2': '修改日志','3':'登录登出'}[logType]
}},
{title: '操作用户',width:100, dataIndex: 'loginName', key: 'loginName'},
{title: '是否异常',width:100, dataIndex: 'errorInfo', key: 'errorInfo',render: (errorInfo) => {
return (!errorInfo ? '正常' : '异常');
}},
{title: '操作时间',width:120, dataIndex: 'beginTime', key: 'beginTime',render: (beginTime) => {
return Utils.formateDateToDetail(beginTime,'seconds');
}},
{title: '客户端IP',width:100, dataIndex: 'requestIp', key: 'requestIp'},
{title: '设备名称',width:100, dataIndex: 'requestDevice', key: 'requestDevice', render: (requestDevice) => {
return {'1': 'IPHONE', '2': 'IPAD', '3': 'ANDROID', '4': 'ANDROID_PAD', '5': 'PC','6':'WE_CHAT'}[requestDevice]
}},
{title: '响应时间',width:100, dataIndex: 'useTime', key: 'useTime',render: (useTime) => {
return useTime + '毫秒';
}},
{title: '请求方式',width:100, dataIndex: 'httpMethod', key: 'httpMethod', className:'pRight',
align: 'right'}
];
return (
<div className="com-accessLog">
<div className="searchWrap">
<WhiteBar title="访问日志" />
<div className='expandMenu iconfont icon-chazhaobiaodanliebiao' onClick={this.expandMenu} ></div>
{
this.state.expandStatus ?
<SearchForm search={this.search} reset={this.reset} />
: ''
}
</div>
<WhiteBar title="详细数据" />
<div className="detail-wrapper" style={{minHeight: 500}}>
<Table
dataSource={this.state.dataList}
columns={columns}
pagination={this.state.pagination}
loading={this.state.isLoading}
scroll={{ x: '160%' }}>
>
</Table>
</div>
</div>
);
}
}
/* 查询表单组件 */
const SearchForm = Form.create()(
class extends Component {
// 查询
search = () => {
let searchData = this.props.form.getFieldsValue()
// 校验日期选择
if (searchData.beginTime && !searchData.endTime) {
Message.warn('请选择结束时间');
return;
} else if (!searchData.beginTime && searchData.endTime) {
Message.warn('请选择开始时间');
return;
}
// 判断日期并转换时间格式
if (searchData.beginTime && searchData.endTime) {
if (new Date(searchData.endTime._d) < new Date(searchData.beginTime._d)) {
Message.warn('选择结束时间要大于选择开始时间');
return;
} else {
searchData.beginTime = Utils.formateDateToDetail(searchData.beginTime._d,'standard');
searchData.endTime = Utils.formateDateToDetail(searchData.endTime._d,'standard');
}
}
this.props.search(searchData);
}
// 重置
reset = () => {
this.props.form.resetFields();
this.props.reset();
}
render () {
const FormItem = Form.Item;
const Option = Select.Option;
const {getFieldDecorator} = this.props.form;
return (
<div className="com-searchForm">
<Form layout="vertical">
<Row gutter={16}>
<Col span={4}>
<FormItem label="日志标题">
{
getFieldDecorator('logTitle',{
rules: []
})(<Input type="text" placeholder="日志标题" />)
}
</FormItem>
</Col>
<Col span={4}>
<FormItem label="请求地址">
{
getFieldDecorator('requestUrl',{
rules: []
})(<Input type="text" placeholder="请求地址" />)
}
</FormItem>
</Col>
<Col span={4}>
<FormItem label="日志类型">
{
getFieldDecorator('logType',{
rules: []
})(<Select placeholder="日志类型">
<Option value={1}>查询日志</Option>
<Option value={2}>修改日志</Option>
<Option value={3}>登录登出</Option>
</Select>)
}
</FormItem>
</Col>
<Col span={4}>
<FormItem label="是否异常">
{
getFieldDecorator('errorFlag',{
rules: []
})(<Select placeholder="是否异常">
<Option value={'normal'}>正常</Option>
<Option value={'abnormal'}>异常</Option>
</Select>)
}
</FormItem>
</Col>
</Row>
<Row gutter={16}>
<Col span={4}>
<FormItem label="客户端IP">
{
getFieldDecorator('requestIp',{
rules: []
})(<Input type="text" placeholder="客户端IP" />)
}
</FormItem>
</Col>
<Col span={4}>
<FormItem label="操作时间">
{
getFieldDecorator('beginTime',{
rules: []
})(
<DatePicker
style={{width:'100%'}}
showTime
format="YYYY-MM-DD HH:mm:ss"
placeholder="开始时间" />
)
}
</FormItem>
</Col>
<Col span={1} style={{paddingTop: 32,width: 30}}>
<span style={{marginTop: 29}}>至</span>
</Col>
<Col span={4}>
<FormItem style={{marginTop: 29}}>
{
getFieldDecorator('endTime',{
rules: []
})(
<DatePicker
style={{width: '100%'}}
showTime
format="YYYY-MM-DD HH:mm:ss"
placeholder="结束时间" />
)
}
</FormItem>
</Col>
<Col span={4}>
<FormItem style={{marginTop: 29}}>
<Button onClick={this.search} style={{background: '#00BB29',color:'#fff'}}>查询</Button>
<Button onClick={this.reset} style={{marginLeft: 15,background:'#ED1719',color:'#fff'}}>重置</Button>
</FormItem>
</Col>
</Row>
</Form>
</div>
);
}
}
);