160 lines
5.3 KiB
TypeScript
160 lines
5.3 KiB
TypeScript
import React, { useState } from 'react';
|
||
import {
|
||
Input, Button, Table, message, Space, Tabs, Card,
|
||
Typography
|
||
} from 'antd';
|
||
import { SearchOutlined, ReloadOutlined } from '@ant-design/icons';
|
||
import { useTranslation } from 'react-i18next';
|
||
|
||
const { Search } = Input;
|
||
const { TabPane } = Tabs;
|
||
|
||
const OnlineUserPage = () => {
|
||
const { t } = useTranslation();
|
||
// 模拟在线用户数据
|
||
const mockOnlineUsers = [
|
||
{
|
||
id: 1,
|
||
sessionId: 'c85c6fe7-2e70-47...',
|
||
loginName: 'admin',
|
||
dept: t('systemSetting.deptRnd'),
|
||
host: '127.0.0.1',
|
||
location: t('systemSetting.intranetIp'),
|
||
os: 'Linux',
|
||
browser: 'Firefox 136.0',
|
||
loginTime: '2026-05-08 09:46:08'
|
||
},
|
||
{
|
||
id: 2,
|
||
sessionId: '9f6c7d73-f684-4e...',
|
||
loginName: 'admin',
|
||
dept: t('systemSetting.deptRnd'),
|
||
host: '127.0.0.1',
|
||
location: t('systemSetting.intranetIp'),
|
||
os: 'Windows >=10',
|
||
browser: 'Edge 147',
|
||
loginTime: '2026-05-08 10:11:27'
|
||
}
|
||
];
|
||
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(t('systemSetting.fixed2SearchFixed2CompleteFixed2'));
|
||
}, 500);
|
||
};
|
||
|
||
// 重置
|
||
const handleReset = () => {
|
||
setSearchParams({ loginAddress: '', userName: '' });
|
||
setDataSource(mockOnlineUsers);
|
||
message.info(t('systemSetting.resetFixed2Search'));
|
||
};
|
||
|
||
// 强退用户
|
||
const handleForceLogout = (record) => {
|
||
message.info(t('systemSetting.forceLogoutSent', { sessionId: record.sessionId }));
|
||
};
|
||
|
||
// 表格列配置
|
||
const columns = [
|
||
{ title: t('systemSetting.s122'), dataIndex: 'id', width: 60 },
|
||
{ title: t('systemSetting.s132'), dataIndex: 'sessionId', ellipsis: true },
|
||
{ title: t('systemSetting.fixed2LoginFixed2NameFixed2'), dataIndex: 'loginName' },
|
||
{ title: t('systemSetting.s152'), dataIndex: 'dept' },
|
||
{ title: t('systemSetting.s162'), dataIndex: 'host' },
|
||
{ title: t('systemSetting.fixed2Login'), dataIndex: 'location' },
|
||
{ title: t('systemSetting.fixed2Actions'), dataIndex: 'os' },
|
||
{ title: t('systemSetting.s192'), dataIndex: 'browser' },
|
||
{ title: t('systemSetting.fixed2LoginFixed2TimeFixed2'), dataIndex: 'loginTime' },
|
||
{
|
||
title: t('roles.actions'), width: 100,
|
||
render: (_, record) => (
|
||
<Button type="link" onClick={() => handleForceLogout(record)} style={{ color: '#1890ff' }}>{t('systemSetting.s02')}</Button>
|
||
)
|
||
}
|
||
];
|
||
|
||
return (
|
||
<div style={{ padding: "8px 0px", background: '#f5f7fa', minHeight: '100vh' }}>
|
||
<div style={{ padding: '0px 0px 8px' }}>
|
||
<Typography.Title level={4} style={{ margin: 0, fontSize: 'clamp(14px, 1.2vw, 18px)' }}>{t('systemSetting.s110')}</Typography.Title>
|
||
</div>
|
||
{/* ====================== 顶部 Tabs ====================== */}
|
||
<Tabs
|
||
activeKey={activeTab}
|
||
onChange={setActiveTab}
|
||
style={{ marginBottom: 0 }}
|
||
>
|
||
<TabPane tab={t('systemSetting.onlineUsers')} key="onlineUser" />
|
||
<TabPane tab={t('systemSetting.fixed2Others')} 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>{t('systemSetting.fixed2LoginFixed2Fixed2')}</span>
|
||
<Input
|
||
placeholder={t('systemSetting.fixed2PleaseEnterFixed2Login')}
|
||
value={searchParams.loginAddress}
|
||
onChange={(e) => setSearchParams({ ...searchParams, loginAddress: e.target.value })}
|
||
style={{ width: 200 }}
|
||
/>
|
||
</div>
|
||
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||
<span>{t('profile.username')}</span>
|
||
<Input
|
||
placeholder={t('systemSetting.fixed2PleaseEnterFixed2UsernameFixed2')}
|
||
value={searchParams.userName}
|
||
onChange={(e) => setSearchParams({ ...searchParams, userName: e.target.value })}
|
||
style={{ width: 200 }}
|
||
/>
|
||
</div>
|
||
<Button type="primary" icon={<SearchOutlined />} onClick={handleSearch} loading={loading}>{t('common.search')}</Button>
|
||
<Button icon={<ReloadOutlined />} onClick={handleReset}>{t('common.reset')}</Button>
|
||
</div>
|
||
|
||
{/* 在线用户表格 */}
|
||
<Table
|
||
rowKey="id"
|
||
columns={columns}
|
||
dataSource={dataSource}
|
||
loading={loading}
|
||
pagination={{
|
||
total: 2,
|
||
pageSize: 10,
|
||
showSizeChanger: true,
|
||
showTotal: (total) => `${t('common.total')} ${total} ${t('common.items')}`,
|
||
showQuickJumper: true
|
||
}}
|
||
bordered={false}
|
||
/>
|
||
</Card>
|
||
)}
|
||
|
||
{/* ====================== Tab 2:其他页面(你可以随便改内容) ====================== */}
|
||
{activeTab === 'other' && (
|
||
<Card bordered={false} style={{ borderRadius: 8, padding: '40px 0', textAlign: 'center' }}>
|
||
<h2>{t('systemSetting.fixed2OthersContentFixed2')}</h2>
|
||
<p>{t('systemSetting.statusCpuContentFixed2')}</p>
|
||
</Card>
|
||
)}
|
||
</div>
|
||
);
|
||
};
|
||
|
||
export default OnlineUserPage;
|