Files
web-Iot/src/components/SystemSetting/OnlineUser.tsx

161 lines
4.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, { useState } from 'react';
import {
Input, Button, Table, message, Space, Tabs, Card
} from 'antd';
import { SearchOutlined, ReloadOutlined } from '@ant-design/icons';
const { Search } = Input;
const { TabPane } = Tabs;
// 模拟在线用户数据
const mockOnlineUsers = [
{
id: 1,
sessionId: 'c85c6fe7-2e70-47...',
loginName: 'admin',
dept: '研发部门',
host: '127.0.0.1',
location: '内网IP',
os: 'Linux',
browser: 'Firefox 136.0',
loginTime: '2026-05-08 09:46:08'
},
{
id: 2,
sessionId: '9f6c7d73-f684-4e...',
loginName: 'admin',
dept: '研发部门',
host: '127.0.0.1',
location: '内网IP',
os: 'Windows >=10',
browser: 'Edge 147',
loginTime: '2026-05-08 10:11:27'
}
];
const OnlineUserPage = () => {
const [activeTab, setActiveTab] = useState('onlineUser'); // 默认选中在线用户
const [loading, setLoading] = useState(false);
const [dataSource, setDataSource] = useState(mockOnlineUsers);
const [searchParams, setSearchParams] = useState({
loginAddress: '',
userName: ''
});
// 搜索
const handleSearch = () => {
setLoading(true);
// 模拟接口请求
setTimeout(() => {
setLoading(false);
message.success('搜索完成');
}, 500);
};
// 重置
const handleReset = () => {
setSearchParams({ loginAddress: '', userName: '' });
setDataSource(mockOnlineUsers);
message.info('已重置搜索条件');
};
// 强退用户
const handleForceLogout = (record) => {
message.info(`已向会话 ${record.sessionId} 发送强退指令`);
};
// 表格列配置
const columns = [
{ title: '序号', dataIndex: 'id', width: 60 },
{ title: '会话编号', dataIndex: 'sessionId', ellipsis: true },
{ title: '登录名称', dataIndex: 'loginName' },
{ title: '所属部门', dataIndex: 'dept' },
{ title: '主机', dataIndex: 'host' },
{ title: '登录地点', dataIndex: 'location' },
{ title: '操作系统', dataIndex: 'os' },
{ title: '浏览器', dataIndex: 'browser' },
{ title: '登录时间', dataIndex: 'loginTime' },
{
title: '操作', width: 100,
render: (_, record) => (
<Button type="link" onClick={() => handleForceLogout(record)} style={{ color: '#1890ff' }}>
强退
</Button>
)
}
];
return (
<div style={{ padding: 20, background: '#f5f7fa', minHeight: '100vh' }}>
{/* ====================== 顶部 Tabs ====================== */}
<Tabs
activeKey={activeTab}
onChange={setActiveTab}
style={{ marginBottom: 20 }}
>
<TabPane tab="在线用户" key="onlineUser" />
<TabPane tab="其他监控" key="other" />
</Tabs>
{/* ====================== Tab 1:在线用户 ====================== */}
{activeTab === 'onlineUser' && (
<Card bordered={false} style={{ borderRadius: 8 }}>
{/* 搜索栏 */}
<div style={{ display: 'flex', alignItems: 'center', gap: 16, marginBottom: 20 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<span>登录地址</span>
<Input
placeholder="请输入登录地址"
value={searchParams.loginAddress}
onChange={(e) => setSearchParams({ ...searchParams, loginAddress: e.target.value })}
style={{ width: 200 }}
/>
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<span>用户名称</span>
<Input
placeholder="请输入用户名称"
value={searchParams.userName}
onChange={(e) => setSearchParams({ ...searchParams, userName: e.target.value })}
style={{ width: 200 }}
/>
</div>
<Button type="primary" icon={<SearchOutlined />} onClick={handleSearch} loading={loading}>
搜索
</Button>
<Button icon={<ReloadOutlined />} onClick={handleReset}>
重置
</Button>
</div>
{/* 在线用户表格 */}
<Table
rowKey="id"
columns={columns}
dataSource={dataSource}
loading={loading}
pagination={{
total: 2,
pageSize: 10,
showSizeChanger: true,
showTotal: (total) => `共 ${total} 条`,
showQuickJumper: true
}}
bordered={false}
/>
</Card>
)}
{/* ====================== Tab 2:其他页面(你可以随便改内容) ====================== */}
{activeTab === 'other' && (
<Card bordered={false} style={{ borderRadius: 8, padding: '40px 0', textAlign: 'center' }}>
<h2>其他监控内容</h2>
<p>这里可以放服务状态、CPU监控、内存监控、接口监控等内容</p>
</Card>
)}
</div>
);
};
export default OnlineUserPage;