😎调整在线用户列表页面

This commit is contained in:
zuohuaijun 2024-07-01 14:48:41 +08:00
parent 4381baaed6
commit 8318a39c7e
3 changed files with 136 additions and 69 deletions

View File

@ -62,11 +62,11 @@ const openDialog = (row: any) => {
var receiveUser = JSON.parse(JSON.stringify(row));
state.ruleForm.receiveUserId = receiveUser.userId;
state.ruleForm.receiveUserName = receiveUser.realName;
state.ruleForm.receiveUserName = receiveUser.realName;
state.ruleForm.connectionId = receiveUser.connectionId;
state.ruleForm.sendUserId = userInfos.value.id;
state.ruleForm.sendUserName = userInfos.value.realName;
state.ruleForm.sendUserName = userInfos.value.realName;
state.ruleForm.sendTime = formatDate(new Date(), 'YYYY-mm-dd HH:MM:SS');
state.isShowDialog = true;
};

View File

@ -1,54 +1,67 @@
<template>
<div class="sys-onlineUser-container">
<el-drawer v-model="state.isVisible" title="在线用户列表" size="35%">
<el-card shadow="hover" :body-style="{ paddingBottom: '0' }" style="margin: 8px">
<el-form :model="state.queryParams" ref="queryForm" :inline="true">
<el-form-item label="账号" prop="userName">
<el-input placeholder="账号" clearable @keyup.enter="handleQuery" v-model="state.queryParams.userName" />
</el-form-item>
<el-form-item label="姓名" prop="realName">
<el-input placeholder="姓名" clearable @keyup.enter="handleQuery" v-model="state.queryParams.realName" />
</el-form-item>
<el-form-item>
<el-button-group>
<el-button type="primary" icon="ele-Search" @click="handleQuery"> 查询 </el-button>
<el-button icon="ele-Refresh" @click="resetQuery"> 重置 </el-button>
</el-button-group>
</el-form-item>
<el-drawer v-model="state.isVisible" size="35%">
<template #header>
<div style="color: #fff">
<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-UserFilled /> </el-icon>
<span> 在线用户列表</span>
</div>
</template>
<el-card shadow="hover" :body-style="{ padding: '5px 5px 0 5px', display: 'flex', width: '100%', height: '100%', alignItems: 'start' }">
<el-form :model="state.queryParams" ref="queryForm" :show-message="false" :inlineMessage="true" :label-width="'60px'" style="flex: 1 1 0%">
<el-row :gutter="10">
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
<el-form-item label="账号" prop="userName">
<el-input v-model="state.queryParams.userName" placeholder="账号" clearable @keyup.enter.native="handleQuery(true)" />
</el-form-item>
</el-col>
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
<el-form-item label="姓名" prop="realName">
<el-input v-model="state.queryParams.realName" placeholder="姓名" clearable @keyup.enter.native="handleQuery(true)" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<el-divider style="height: calc(100% - 5px); margin: 0 10px" direction="vertical" />
<el-row>
<el-col>
<el-button-group>
<el-button type="primary" icon="ele-Search" @click="handleQuery(true)" :loading="options.loading"> 查询 </el-button>
<el-button icon="ele-Refresh" @click="resetQuery" :loading="options.loading"> 重置 </el-button>
</el-button-group>
</el-col>
</el-row>
</el-card>
<el-card shadow="hover" style="margin: 8px; padding-bottom: 15px">
<el-table :data="state.onlineUserList" style="width: 100%" v-loading="state.loading" border>
<el-table-column type="index" label="序号" width="55" align="center" />
<el-table-column prop="userName" label="账号" header-align="center" show-overflow-tooltip />
<el-table-column prop="realName" label="姓名" header-align="center" show-overflow-tooltip />
<el-table-column prop="ip" label="IP地址" min-width="100" header-align="center" show-overflow-tooltip />
<el-table-column prop="browser" label="浏览器" header-align="center" show-overflow-tooltip />
<!-- <el-table-column prop="connectionId" label="连接Id" show-overflow-tooltip></el-table-column> -->
<el-table-column prop="time" label="登录时间" min-width="120" header-align="center" show-overflow-tooltip />
<el-table-column label="操作" width="200" fixed="right" align="center" show-overflow-tooltip>
<template #default="scope">
<el-button icon="ele-Position" size="small" text type="primary" v-auth="'sysOnlineUser:forceOffline'" @click="openSendMessage(scope.row)"> 发送消息 </el-button>
<el-button icon="ele-CircleCloseFilled" size="small" text type="danger" v-auth="'sysOnlineUser:forceOffline'" @click="forceOffline(scope.row)"> 强制下线 </el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
v-model:currentPage="state.tableParams.page"
v-model:page-size="state.tableParams.pageSize"
:total="state.tableParams.total"
:page-sizes="[10, 20, 50, 100]"
small
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
layout="total, sizes, prev, pager, next, jumper"
/>
<el-card class="full-table" shadow="hover" style="margin-top: 5px">
<vxe-grid ref="xGrid" class="xGrid-style" v-bind="options" @sort-change="sortChange">
<template #toolbar_buttons> </template>
<template #toolbar_tools> </template>
<template #empty>
<el-empty :image-size="200" />
</template>
<template #row_buttons="{ row }">
<el-tooltip content="发送消息" placement="top">
<el-button icon="ele-Position" size="small" text type="primary" @click="openSendMessage(row)"> </el-button>
</el-tooltip>
<el-tooltip content="强制下线" placement="top">
<el-button icon="ele-CircleCloseFilled" text type="danger" v-auth="'sysOnlineUser:forceOffline'" @click="forceOffline(row)"> </el-button>
</el-tooltip>
</template>
<template #pager>
<vxe-pager
:loading="options.loading"
v-model:current-page="state.tableParams.page"
v-model:page-size="state.tableParams.pageSize"
:total="state.tableParams.total"
@page-change="pageChange"
/>
</template>
</vxe-grid>
</el-card>
</el-drawer>
<SendMessage ref="sendMessageRef" title="发送消息" />
</div>
</template>
@ -56,17 +69,19 @@
import { onMounted, reactive, ref } from 'vue';
import { ElMessageBox, ElNotification } from 'element-plus';
import { throttle } from 'lodash-es';
import { signalR } from './signalR';
import { VxeGridInstance, VxePagerEvents, VxePagerDefines } from 'vxe-table';
import { useVxeTable } from '/@/hooks/vxeTableOptionsHook';
import SendMessage from '/@/views/system/onlineUser/component/sendMessage.vue';
import { getAPI, clearAccessTokens } from '/@/utils/axios-utils';
import { SysOnlineUserApi, SysAuthApi } from '/@/api-services/api';
import { SysOnlineUser } from '/@/api-services/models';
import { signalR } from './signalR';
const xGrid = ref<VxeGridInstance>();
const sendMessageRef = ref<InstanceType<typeof SendMessage>>();
const state = reactive({
loading: false,
isVisible: false,
queryParams: {
userName: undefined,
@ -74,8 +89,11 @@ const state = reactive({
},
tableParams: {
page: 1,
pageSize: 10,
total: 1 as any,
pageSize: 50,
field: 'id', //
order: 'aes', //
descStr: 'desc', //
total: 0 as any,
},
onlineUserList: [] as Array<SysOnlineUser>, // 线
lastUserState: {
@ -84,6 +102,27 @@ const state = reactive({
}, //
});
//
const options = useVxeTable<SysOnlineUser>({
id: 'sysOnlineUser',
name: '在线用户',
columns: [
// { type: 'checkbox', width: 40, fixed: 'left' },
{ type: 'seq', title: '序号', width: 50, fixed: 'left' },
{ field: 'userName', title: '账号', minWidth: 110, showOverflow: 'tooltip' },
{ field: 'realName', title: '姓名', minWidth: 110, showOverflow: 'tooltip' },
{ field: 'ip', title: 'IP地址', minWidth: 100, showOverflow: 'tooltip' },
{ field: 'browser', title: '浏览器', minWidth: 160, showOverflow: 'tooltip' },
// { field: 'connectionId', title: 'Id', minWidth: 160, showOverflow: 'tooltip', sortable: true },
{ field: 'time', title: '登录时间', minWidth: 120, showOverflow: 'tooltip' },
{ title: '操作', fixed: 'right', width: 100, showOverflow: true, slots: { default: 'row_buttons' } },
],
enableExport: true,
searchCallback: () => handleQuery(),
queryAllCallback: () => fetchData({ pageSize: 99999 }),
});
//
onMounted(async () => {
// 线
signalR.off('OnlineUserList');
@ -95,7 +134,6 @@ onMounted(async () => {
};
notificationThrottle();
});
// 线
signalR.off('ForceOffline');
signalR.on('ForceOffline', async (data: any) => {
@ -131,13 +169,19 @@ const openDrawer = () => {
};
//
const handleQuery = async () => {
state.loading = true;
let params = Object.assign(state.queryParams, state.tableParams);
var res = await getAPI(SysOnlineUserApi).apiSysOnlineUserPagePost(params);
state.onlineUserList = res.data.result?.items ?? [];
const handleQuery = async (reset = false) => {
options.loading = true;
if (reset) state.tableParams.page = 1;
var res = await fetchData(null);
xGrid.value?.loadData(res.data.result?.items ?? []);
state.tableParams.total = res.data.result?.total;
state.loading = false;
options.loading = false;
};
//
const fetchData = async (tableParams: any) => {
let params = Object.assign(state.queryParams, state.tableParams, tableParams);
return getAPI(SysOnlineUserApi).apiSysOnlineUserPagePost(params);
};
//
@ -148,9 +192,9 @@ const resetQuery = () => {
};
//
const openSendMessage = (row: any)=>{
const openSendMessage = (row: any) => {
sendMessageRef.value?.openDialog(row);
}
};
// 线
const forceOffline = async (row: any) => {
@ -167,18 +211,38 @@ const forceOffline = async (row: any) => {
.catch(() => {});
};
//
const handleSizeChange = (val: number) => {
state.tableParams.pageSize = val;
//
const pageChange: VxePagerEvents.PageChange = ({ currentPage, pageSize }: VxePagerDefines.PageChangeEventParams) => {
state.tableParams.page = currentPage;
state.tableParams.pageSize = pageSize;
handleQuery();
};
//
const handleCurrentChange = (val: number) => {
state.tableParams.page = val;
//
const sortChange = (options: any) => {
state.tableParams.field = options.field;
state.tableParams.order = options.order;
handleQuery();
};
//
defineExpose({ openDrawer });
</script>
<style lang="scss" scoped>
:deep(.el-drawer__body) {
padding: 5px;
display: flex;
flex-direction: column;
height: 100%;
}
.full-table {
flex: 1;
:deep(.el-card__body) {
height: 100%;
display: flex;
flex-direction: column;
}
}
</style>

View File

@ -20,10 +20,12 @@ connection.serverTimeoutInMilliseconds = 30 * 60 * 1000; // 超时时间30m
connection.start().then(() => {
console.log('启动连接');
});
// 断开连接
connection.onclose(async () => {
console.log('断开连接');
});
// 重连中
connection.onreconnecting(() => {
ElNotification({
@ -33,6 +35,7 @@ connection.onreconnecting(() => {
position: 'bottom-right',
});
});
// 重连成功
connection.onreconnected(() => {
console.log('重连成功');
@ -41,7 +44,7 @@ connection.onreconnected(() => {
connection.on('OnlineUserList', () => {});
// 接收消息
connection.on("ReceiveMessage", (message: any)=>{
connection.on('ReceiveMessage', (message: any) => {
var tmpMsg = `${message.message}<br/>`;
tmpMsg += `<p style="color:#808080; font-size:12px">发送人员:${message.sendUserName}<p>`;
tmpMsg += `<p style="color:#808080; font-size:12px">发送时间:${message.sendTime}<p>`;
@ -52,7 +55,7 @@ connection.on("ReceiveMessage", (message: any)=>{
type: 'info',
position: 'top-right',
dangerouslyUseHTMLString: true,
duration: 0
duration: 0,
});
});