😎调整在线用户列表页面
This commit is contained in:
parent
4381baaed6
commit
8318a39c7e
@ -62,11 +62,11 @@ const openDialog = (row: any) => {
|
|||||||
|
|
||||||
var receiveUser = JSON.parse(JSON.stringify(row));
|
var receiveUser = JSON.parse(JSON.stringify(row));
|
||||||
state.ruleForm.receiveUserId = receiveUser.userId;
|
state.ruleForm.receiveUserId = receiveUser.userId;
|
||||||
state.ruleForm.receiveUserName = receiveUser.realName;
|
state.ruleForm.receiveUserName = receiveUser.realName;
|
||||||
state.ruleForm.connectionId = receiveUser.connectionId;
|
state.ruleForm.connectionId = receiveUser.connectionId;
|
||||||
|
|
||||||
state.ruleForm.sendUserId = userInfos.value.id;
|
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.ruleForm.sendTime = formatDate(new Date(), 'YYYY-mm-dd HH:MM:SS');
|
||||||
state.isShowDialog = true;
|
state.isShowDialog = true;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,54 +1,67 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="sys-onlineUser-container">
|
<div class="sys-onlineUser-container">
|
||||||
<el-drawer v-model="state.isVisible" title="在线用户列表" size="35%">
|
<el-drawer v-model="state.isVisible" size="35%">
|
||||||
<el-card shadow="hover" :body-style="{ paddingBottom: '0' }" style="margin: 8px">
|
<template #header>
|
||||||
<el-form :model="state.queryParams" ref="queryForm" :inline="true">
|
<div style="color: #fff">
|
||||||
<el-form-item label="账号" prop="userName">
|
<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-UserFilled /> </el-icon>
|
||||||
<el-input placeholder="账号" clearable @keyup.enter="handleQuery" v-model="state.queryParams.userName" />
|
<span> 在线用户列表</span>
|
||||||
</el-form-item>
|
</div>
|
||||||
<el-form-item label="姓名" prop="realName">
|
</template>
|
||||||
<el-input placeholder="姓名" clearable @keyup.enter="handleQuery" v-model="state.queryParams.realName" />
|
<el-card shadow="hover" :body-style="{ padding: '5px 5px 0 5px', display: 'flex', width: '100%', height: '100%', alignItems: 'start' }">
|
||||||
</el-form-item>
|
<el-form :model="state.queryParams" ref="queryForm" :show-message="false" :inlineMessage="true" :label-width="'60px'" style="flex: 1 1 0%">
|
||||||
<el-form-item>
|
<el-row :gutter="10">
|
||||||
<el-button-group>
|
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
|
||||||
<el-button type="primary" icon="ele-Search" @click="handleQuery"> 查询 </el-button>
|
<el-form-item label="账号" prop="userName">
|
||||||
<el-button icon="ele-Refresh" @click="resetQuery"> 重置 </el-button>
|
<el-input v-model="state.queryParams.userName" placeholder="账号" clearable @keyup.enter.native="handleQuery(true)" />
|
||||||
</el-button-group>
|
</el-form-item>
|
||||||
</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-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>
|
||||||
|
|
||||||
<el-card shadow="hover" style="margin: 8px; padding-bottom: 15px">
|
<el-card class="full-table" shadow="hover" style="margin-top: 5px">
|
||||||
<el-table :data="state.onlineUserList" style="width: 100%" v-loading="state.loading" border>
|
<vxe-grid ref="xGrid" class="xGrid-style" v-bind="options" @sort-change="sortChange">
|
||||||
<el-table-column type="index" label="序号" width="55" align="center" />
|
<template #toolbar_buttons> </template>
|
||||||
<el-table-column prop="userName" label="账号" header-align="center" show-overflow-tooltip />
|
<template #toolbar_tools> </template>
|
||||||
<el-table-column prop="realName" label="姓名" header-align="center" show-overflow-tooltip />
|
<template #empty>
|
||||||
<el-table-column prop="ip" label="IP地址" min-width="100" header-align="center" show-overflow-tooltip />
|
<el-empty :image-size="200" />
|
||||||
<el-table-column prop="browser" label="浏览器" header-align="center" show-overflow-tooltip />
|
</template>
|
||||||
<!-- <el-table-column prop="connectionId" label="连接Id" show-overflow-tooltip></el-table-column> -->
|
<template #row_buttons="{ row }">
|
||||||
<el-table-column prop="time" label="登录时间" min-width="120" header-align="center" show-overflow-tooltip />
|
<el-tooltip content="发送消息" placement="top">
|
||||||
<el-table-column label="操作" width="200" fixed="right" align="center" show-overflow-tooltip>
|
<el-button icon="ele-Position" size="small" text type="primary" @click="openSendMessage(row)"> </el-button>
|
||||||
<template #default="scope">
|
</el-tooltip>
|
||||||
<el-button icon="ele-Position" size="small" text type="primary" v-auth="'sysOnlineUser:forceOffline'" @click="openSendMessage(scope.row)"> 发送消息 </el-button>
|
<el-tooltip content="强制下线" placement="top">
|
||||||
<el-button icon="ele-CircleCloseFilled" size="small" text type="danger" v-auth="'sysOnlineUser:forceOffline'" @click="forceOffline(scope.row)"> 强制下线 </el-button>
|
<el-button icon="ele-CircleCloseFilled" text type="danger" v-auth="'sysOnlineUser:forceOffline'" @click="forceOffline(row)"> </el-button>
|
||||||
</template>
|
</el-tooltip>
|
||||||
</el-table-column>
|
</template>
|
||||||
</el-table>
|
<template #pager>
|
||||||
<el-pagination
|
<vxe-pager
|
||||||
v-model:currentPage="state.tableParams.page"
|
:loading="options.loading"
|
||||||
v-model:page-size="state.tableParams.pageSize"
|
v-model:current-page="state.tableParams.page"
|
||||||
:total="state.tableParams.total"
|
v-model:page-size="state.tableParams.pageSize"
|
||||||
:page-sizes="[10, 20, 50, 100]"
|
:total="state.tableParams.total"
|
||||||
small
|
@page-change="pageChange"
|
||||||
background
|
/>
|
||||||
@size-change="handleSizeChange"
|
</template>
|
||||||
@current-change="handleCurrentChange"
|
</vxe-grid>
|
||||||
layout="total, sizes, prev, pager, next, jumper"
|
|
||||||
/>
|
|
||||||
</el-card>
|
</el-card>
|
||||||
</el-drawer>
|
</el-drawer>
|
||||||
|
|
||||||
<SendMessage ref="sendMessageRef" title="发送消息" />
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -56,17 +69,19 @@
|
|||||||
import { onMounted, reactive, ref } from 'vue';
|
import { onMounted, reactive, ref } from 'vue';
|
||||||
import { ElMessageBox, ElNotification } from 'element-plus';
|
import { ElMessageBox, ElNotification } from 'element-plus';
|
||||||
import { throttle } from 'lodash-es';
|
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 SendMessage from '/@/views/system/onlineUser/component/sendMessage.vue';
|
||||||
|
|
||||||
import { getAPI, clearAccessTokens } from '/@/utils/axios-utils';
|
import { getAPI, clearAccessTokens } from '/@/utils/axios-utils';
|
||||||
import { SysOnlineUserApi, SysAuthApi } from '/@/api-services/api';
|
import { SysOnlineUserApi, SysAuthApi } from '/@/api-services/api';
|
||||||
import { SysOnlineUser } from '/@/api-services/models';
|
import { SysOnlineUser } from '/@/api-services/models';
|
||||||
|
|
||||||
import { signalR } from './signalR';
|
const xGrid = ref<VxeGridInstance>();
|
||||||
|
|
||||||
const sendMessageRef = ref<InstanceType<typeof SendMessage>>();
|
const sendMessageRef = ref<InstanceType<typeof SendMessage>>();
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
loading: false,
|
|
||||||
isVisible: false,
|
isVisible: false,
|
||||||
queryParams: {
|
queryParams: {
|
||||||
userName: undefined,
|
userName: undefined,
|
||||||
@ -74,8 +89,11 @@ const state = reactive({
|
|||||||
},
|
},
|
||||||
tableParams: {
|
tableParams: {
|
||||||
page: 1,
|
page: 1,
|
||||||
pageSize: 10,
|
pageSize: 50,
|
||||||
total: 1 as any,
|
field: 'id', // 默认的排序字段
|
||||||
|
order: 'aes', // 排序方向
|
||||||
|
descStr: 'desc', // 降序排序的关键字符
|
||||||
|
total: 0 as any,
|
||||||
},
|
},
|
||||||
onlineUserList: [] as Array<SysOnlineUser>, // 在线用户列表
|
onlineUserList: [] as Array<SysOnlineUser>, // 在线用户列表
|
||||||
lastUserState: {
|
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 () => {
|
onMounted(async () => {
|
||||||
// 在线用户列表
|
// 在线用户列表
|
||||||
signalR.off('OnlineUserList');
|
signalR.off('OnlineUserList');
|
||||||
@ -95,7 +134,6 @@ onMounted(async () => {
|
|||||||
};
|
};
|
||||||
notificationThrottle();
|
notificationThrottle();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 强制下线
|
// 强制下线
|
||||||
signalR.off('ForceOffline');
|
signalR.off('ForceOffline');
|
||||||
signalR.on('ForceOffline', async (data: any) => {
|
signalR.on('ForceOffline', async (data: any) => {
|
||||||
@ -131,13 +169,19 @@ const openDrawer = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 查询操作
|
// 查询操作
|
||||||
const handleQuery = async () => {
|
const handleQuery = async (reset = false) => {
|
||||||
state.loading = true;
|
options.loading = true;
|
||||||
let params = Object.assign(state.queryParams, state.tableParams);
|
if (reset) state.tableParams.page = 1;
|
||||||
var res = await getAPI(SysOnlineUserApi).apiSysOnlineUserPagePost(params);
|
var res = await fetchData(null);
|
||||||
state.onlineUserList = res.data.result?.items ?? [];
|
xGrid.value?.loadData(res.data.result?.items ?? []);
|
||||||
state.tableParams.total = res.data.result?.total;
|
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);
|
sendMessageRef.value?.openDialog(row);
|
||||||
}
|
};
|
||||||
|
|
||||||
// 强制下线
|
// 强制下线
|
||||||
const forceOffline = async (row: any) => {
|
const forceOffline = async (row: any) => {
|
||||||
@ -167,18 +211,38 @@ const forceOffline = async (row: any) => {
|
|||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
};
|
};
|
||||||
|
|
||||||
// 改变页面容量
|
// 改变页码序号或页面容量
|
||||||
const handleSizeChange = (val: number) => {
|
const pageChange: VxePagerEvents.PageChange = ({ currentPage, pageSize }: VxePagerDefines.PageChangeEventParams) => {
|
||||||
state.tableParams.pageSize = val;
|
state.tableParams.page = currentPage;
|
||||||
|
state.tableParams.pageSize = pageSize;
|
||||||
handleQuery();
|
handleQuery();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 改变页码序号
|
// 列排序
|
||||||
const handleCurrentChange = (val: number) => {
|
const sortChange = (options: any) => {
|
||||||
state.tableParams.page = val;
|
state.tableParams.field = options.field;
|
||||||
|
state.tableParams.order = options.order;
|
||||||
handleQuery();
|
handleQuery();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 导出对象
|
// 导出对象
|
||||||
defineExpose({ openDrawer });
|
defineExpose({ openDrawer });
|
||||||
</script>
|
</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>
|
||||||
|
|||||||
@ -20,10 +20,12 @@ connection.serverTimeoutInMilliseconds = 30 * 60 * 1000; // 超时时间30m
|
|||||||
connection.start().then(() => {
|
connection.start().then(() => {
|
||||||
console.log('启动连接');
|
console.log('启动连接');
|
||||||
});
|
});
|
||||||
|
|
||||||
// 断开连接
|
// 断开连接
|
||||||
connection.onclose(async () => {
|
connection.onclose(async () => {
|
||||||
console.log('断开连接');
|
console.log('断开连接');
|
||||||
});
|
});
|
||||||
|
|
||||||
// 重连中
|
// 重连中
|
||||||
connection.onreconnecting(() => {
|
connection.onreconnecting(() => {
|
||||||
ElNotification({
|
ElNotification({
|
||||||
@ -33,6 +35,7 @@ connection.onreconnecting(() => {
|
|||||||
position: 'bottom-right',
|
position: 'bottom-right',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 重连成功
|
// 重连成功
|
||||||
connection.onreconnected(() => {
|
connection.onreconnected(() => {
|
||||||
console.log('重连成功');
|
console.log('重连成功');
|
||||||
@ -41,7 +44,7 @@ connection.onreconnected(() => {
|
|||||||
connection.on('OnlineUserList', () => {});
|
connection.on('OnlineUserList', () => {});
|
||||||
|
|
||||||
// 接收消息
|
// 接收消息
|
||||||
connection.on("ReceiveMessage", (message: any)=>{
|
connection.on('ReceiveMessage', (message: any) => {
|
||||||
var tmpMsg = `${message.message}<br/>`;
|
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.sendUserName}<p>`;
|
||||||
tmpMsg += `<p style="color:#808080; font-size:12px">发送时间:${message.sendTime}<p>`;
|
tmpMsg += `<p style="color:#808080; font-size:12px">发送时间:${message.sendTime}<p>`;
|
||||||
@ -52,7 +55,7 @@ connection.on("ReceiveMessage", (message: any)=>{
|
|||||||
type: 'info',
|
type: 'info',
|
||||||
position: 'top-right',
|
position: 'top-right',
|
||||||
dangerouslyUseHTMLString: true,
|
dangerouslyUseHTMLString: true,
|
||||||
duration: 0
|
duration: 0,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user