#
luxiaotao1123
2024-02-13 52a6d76d9a6c1c43f824b2aa4d2572478c49f7a0
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
 
import React, { useState, useRef, useEffect } from 'react';
import { useIntl, FormattedMessage, useAccess } from '@umijs/max';
import { Button, message, Modal } from 'antd';
import { ActionType, FooterToolbar, PageContainer, ProColumns, ProTable } from '@ant-design/pro-components';
import { PlusOutlined, DeleteOutlined, ExclamationCircleOutlined, UnlockOutlined } from '@ant-design/icons';
import { getLogininforList, removeLogininfor, exportLogininfor, unlockLogininfor, cleanLogininfor } from '@/services/monitor/logininfor';
import { request } from '@umijs/max';
 
 
/**
 * 删除节点
 *
 * @param selectedRows
 */
const handleRemove = async (selectedRows) => {
    if (!selectedRows) return true;
    const hide = message.loading('正在删除');
    try {
        const resp = await removeLogininfor(selectedRows.map((row) => row.infoId).join(','));
        hide();
        if (resp.code === 200) {
            message.success('删除成功,即将刷新');
        } else {
            message.error(resp.msg);
        }
        return true;
    } catch (error) {
        hide();
        message.error('删除失败,请重试');
        return false;
    }
};
 
const handleClean = async () => {
    const hide = message.loading('请稍候');
    try {
        const resp = await cleanLogininfor();
        hide();
        if (resp.code === 200) {
            message.success('清空成功,即将刷新');
        } else {
            message.error(resp.msg);
        }
        return true;
    } catch (error) {
        hide();
        message.error('请求失败,请重试');
        return false;
    }
};
 
const handleUnlock = async (userName) => {
    const hide = message.loading('正在解锁');
    try {
        const resp = await unlockLogininfor(userName);
        hide();
        if (resp.code === 200) {
            message.success('解锁成功,即将刷新');
        } else {
            message.error(resp.msg);
        }
        return true;
    } catch (error) {
        hide();
        message.error('解锁失败,请重试');
        return false;
    }
};
 
/**
 * 导出数据
 *
 * @param id
 */
const handleExport = async () => {
    const hide = message.loading('正在导出');
    try {
        await exportLogininfor();
        hide();
        message.success('导出成功');
        return true;
    } catch (error) {
        hide();
        message.error('导出失败,请重试');
        return false;
    }
};
 
 
const LogininforTableList = () => {
    const formTableRef = useRef();
 
    const actionRef = useRef();
    const [selectedRows, setSelectedRows] = useState([]);
    const [statusOptions, setStatusOptions] = useState([]);
 
    /** 国际化配置 */
    const intl = useIntl();
 
    useEffect(() => {
        // getDictValueEnum('sys_common_status', true).then((data) => {
        //     setStatusOptions(data);
        // });
    }, []);
 
    const columns = [
        {
            title: <FormattedMessage id="monitor.logininfor.info_id" defaultMessage="访问编号" />,
            dataIndex: 'infoId',
            valueType: 'text',
            hideInSearch: true,
        },
        {
            title: '姓名',
            dataIndex: 'name',
            valueType: 'text',
        },
        {
            title: <FormattedMessage id="monitor.logininfor.user_name" defaultMessage="用户账号" />,
            dataIndex: 'userName',
            valueType: 'text',
        },
        {
            title: <FormattedMessage id="monitor.logininfor.ipaddr" defaultMessage="登录IP地址" />,
            dataIndex: 'ipaddr',
            valueType: 'text',
        },
        {
            title: <FormattedMessage id="monitor.logininfor.login_location" defaultMessage="登录地点" />,
            dataIndex: 'loginLocation',
            valueType: 'text',
            hideInSearch: true,
        },
        {
            title: <FormattedMessage id="monitor.logininfor.browser" defaultMessage="浏览器类型" />,
            dataIndex: 'browser',
            valueType: 'text',
            hideInSearch: true,
        },
        {
            title: <FormattedMessage id="monitor.logininfor.os" defaultMessage="操作系统" />,
            dataIndex: 'os',
            valueType: 'text',
            hideInSearch: true,
        },
        {
            title: <FormattedMessage id="monitor.logininfor.status" defaultMessage="登录状态" />,
            dataIndex: 'status',
            valueType: 'select',
            valueEnum: statusOptions,
            // render: (_, record) => {
            //     return (<DictTag enums={statusOptions} value={record.status} />);
            // },
        },
        {
            title: <FormattedMessage id="monitor.logininfor.msg" defaultMessage="提示消息" />,
            dataIndex: 'msg',
            valueType: 'text',
            hideInSearch: true,
        },
        {
            title: <FormattedMessage id="monitor.logininfor.login_time" defaultMessage="访问时间" />,
            dataIndex: 'loginTime',
            valueType: 'dateTime',
        },
    ];
 
    return (
        <PageContainer>
            <div style={{ width: '100%', float: 'right' }}>
                <ProTable
                    headerTitle={intl.formatMessage({
                        id: 'pages.searchTable.title',
                        defaultMessage: '信息',
                    })}
                    actionRef={actionRef}
                    formRef={formTableRef}
                    rowKey="infoId"
                    key="logininforList"
                    search={{
                        labelWidth: 120,
                    }}
                    toolBarRender={() => [
                        <Button
                            key="remove"
                            danger
                            hidden={selectedRows?.length === 0}
                            onClick={async () => {
                                Modal.confirm({
                                    title: '是否确认删除所选数据项?',
                                    icon: <ExclamationCircleOutlined />,
                                    content: '请谨慎操作',
                                    async onOk() {
                                        const success = await handleRemove(selectedRows);
                                        if (success) {
                                            setSelectedRows([]);
                                            actionRef.current?.reloadAndRest?.();
                                        }
                                    },
                                    onCancel() { },
                                });
                            }}
                        >
                            <DeleteOutlined />
                            <FormattedMessage id="pages.searchTable.delete" defaultMessage="删除" />
                        </Button>,
                        <Button
                            type="primary"
                            key="clean"
                            danger
                            hidden={selectedRows?.length === 0}
                            onClick={async () => {
                                Modal.confirm({
                                    title: '是否确认清空所有数据项?',
                                    icon: <ExclamationCircleOutlined />,
                                    content: '请谨慎操作',
                                    async onOk() {
                                        const success = await handleClean();
                                        if (success) {
                                            setSelectedRows([]);
                                            actionRef.current?.reloadAndRest?.();
                                        }
                                    },
                                    onCancel() { },
                                });
                            }}
                        >
                            <DeleteOutlined />
                            <FormattedMessage id="pages.searchTable.cleanAll" defaultMessage="清空" />
                        </Button>,
                        <Button
                            type="primary"
                            key="unlock"
                            hidden={selectedRows?.length === 0}
                            onClick={async () => {
                                Modal.confirm({
                                    title: '是否确认解锁该用户的数据项?',
                                    icon: <ExclamationCircleOutlined />,
                                    content: '请谨慎操作',
                                    async onOk() {
                                        const success = await handleUnlock(selectedRows[0].userName);
                                        if (success) {
                                            setSelectedRows([]);
                                            actionRef.current?.reloadAndRest?.();
                                        }
                                    },
                                    onCancel() { },
                                });
                            }}
                        >
                            <UnlockOutlined />
                            <FormattedMessage id="monitor.logininfor.unlock" defaultMessage="解锁" />
                        </Button>,
                        <Button
                            type="primary"
                            key="export"
                            onClick={async () => {
                                handleExport();
                            }}
                        >
                            <PlusOutlined />
                            <FormattedMessage id="pages.searchTable.export" defaultMessage="导出" />
                        </Button>,
                    ]}
                    request={(params) => {
                        console.log(params);
                        request('/api/role/page', {
                            method: 'POST',
                            headers: {
                                'Content-Type': 'application/json'
                            },
                            data: { ...params }
                        }).then((res) => {
                            if (res.code === 200) {
                                const result = {
                                    data: res.records,
                                    total: res.total,
                                    success: true,
                                };
                                return result;
                            } else {
                                message.error(res.msg)
                            }
                        })
                    }
                    }
                    columns={columns}
                    rowSelection={{
                        onChange: (_, selectedRows) => {
                            setSelectedRows(selectedRows);
                        },
                    }}
                />
            </div>
            {selectedRows?.length > 0 && (
                <FooterToolbar
                    extra={
                        <div>
                            <FormattedMessage id="pages.searchTable.chosen" defaultMessage="已选择" />
                            <a style={{ fontWeight: 600 }}>{selectedRows.length}</a>
                            <FormattedMessage id="pages.searchTable.item" defaultMessage="项" />
                        </div>
                    }
                >
                    <Button
                        key="remove"
                        onClick={async () => {
                            Modal.confirm({
                                title: '删除',
                                content: '确定删除该项吗?',
                                okText: '确认',
                                cancelText: '取消',
                                onOk: async () => {
                                    const success = await handleRemove(selectedRows);
                                    if (success) {
                                        setSelectedRows([]);
                                        actionRef.current?.reloadAndRest?.();
                                    }
                                },
                            });
                        }}
                    >
                        <FormattedMessage id="pages.searchTable.batchDeletion" defaultMessage="批量删除" />
                    </Button>
                </FooterToolbar>
            )}
        </PageContainer>
    );
};
 
export default LogininforTableList;