😎调整在线用户页面
This commit is contained in:
parent
d1089b50f7
commit
323c1aa8d6
@ -12,12 +12,12 @@
|
|||||||
<el-row :gutter="10">
|
<el-row :gutter="10">
|
||||||
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
|
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
|
||||||
<el-form-item label="账号" prop="userName">
|
<el-form-item label="账号" prop="userName">
|
||||||
<el-input v-model="state.queryParams.userName" placeholder="账号" clearable @keyup.enter.native="handleQuery(true)" />
|
<el-input v-model="state.queryParams.userName" placeholder="账号" clearable @keyup.enter.native="handleQuery" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
|
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
|
||||||
<el-form-item label="姓名" prop="realName">
|
<el-form-item label="姓名" prop="realName">
|
||||||
<el-input v-model="state.queryParams.realName" placeholder="姓名" clearable @keyup.enter.native="handleQuery(true)" />
|
<el-input v-model="state.queryParams.realName" placeholder="姓名" clearable @keyup.enter.native="handleQuery" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
@ -28,7 +28,7 @@
|
|||||||
<el-row>
|
<el-row>
|
||||||
<el-col>
|
<el-col>
|
||||||
<el-button-group>
|
<el-button-group>
|
||||||
<el-button type="primary" icon="ele-Search" @click="handleQuery(true)" :loading="options.loading"> 查询 </el-button>
|
<el-button type="primary" icon="ele-Search" @click="handleQuery" :loading="options.loading"> 查询 </el-button>
|
||||||
<el-button icon="ele-Refresh" @click="resetQuery" :loading="options.loading"> 重置 </el-button>
|
<el-button icon="ele-Refresh" @click="resetQuery" :loading="options.loading"> 重置 </el-button>
|
||||||
</el-button-group>
|
</el-button-group>
|
||||||
</el-col>
|
</el-col>
|
||||||
@ -36,7 +36,7 @@
|
|||||||
</el-card>
|
</el-card>
|
||||||
|
|
||||||
<el-card class="full-table" shadow="hover" style="margin-top: 5px">
|
<el-card class="full-table" shadow="hover" style="margin-top: 5px">
|
||||||
<vxe-grid ref="xGrid" class="xGrid-style" v-bind="options" @sort-change="sortChange">
|
<vxe-grid ref="xGrid" class="xGrid-style" v-bind="options" v-on="gridEvents">
|
||||||
<template #toolbar_buttons> </template>
|
<template #toolbar_buttons> </template>
|
||||||
<template #toolbar_tools> </template>
|
<template #toolbar_tools> </template>
|
||||||
<template #empty>
|
<template #empty>
|
||||||
@ -50,15 +50,6 @@
|
|||||||
<el-button icon="ele-CircleCloseFilled" text type="danger" v-auth="'sysOnlineUser:forceOffline'" @click="forceOffline(row)"> </el-button>
|
<el-button icon="ele-CircleCloseFilled" text type="danger" v-auth="'sysOnlineUser:forceOffline'" @click="forceOffline(row)"> </el-button>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
</template>
|
</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>
|
</vxe-grid>
|
||||||
</el-card>
|
</el-card>
|
||||||
</el-drawer>
|
</el-drawer>
|
||||||
@ -72,14 +63,15 @@ 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 { signalR } from './signalR';
|
||||||
import { VxeGridInstance, VxePagerEvents, VxePagerDefines } from 'vxe-table';
|
import { VxeGridInstance, VxeGridListeners, VxeGridPropTypes } from 'vxe-table';
|
||||||
import { useVxeTable } from '/@/hooks/vxeTableOptionsHook';
|
import { useVxeTable } from '/@/hooks/useVxeTableOptionsHook';
|
||||||
|
import { Local } from '/@/utils/storage';
|
||||||
|
|
||||||
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, PageOnlineUserInput } from '/@/api-services/models';
|
||||||
|
|
||||||
const xGrid = ref<VxeGridInstance>();
|
const xGrid = ref<VxeGridInstance>();
|
||||||
const sendMessageRef = ref<InstanceType<typeof SendMessage>>();
|
const sendMessageRef = ref<InstanceType<typeof SendMessage>>();
|
||||||
@ -89,13 +81,9 @@ const state = reactive({
|
|||||||
userName: undefined,
|
userName: undefined,
|
||||||
realName: undefined,
|
realName: undefined,
|
||||||
},
|
},
|
||||||
tableParams: {
|
localPageParam: {
|
||||||
page: 1,
|
pageSize: 50 as number,
|
||||||
pageSize: 50,
|
defaultSort: { field: 'orderNo', order: 'asc', descStr: 'desc' },
|
||||||
field: 'id', // 默认的排序字段
|
|
||||||
order: 'aes', // 排序方向
|
|
||||||
descStr: 'desc', // 降序排序的关键字符
|
|
||||||
total: 0 as any,
|
|
||||||
},
|
},
|
||||||
onlineUserList: [] as Array<SysOnlineUser>, // 在线用户列表
|
onlineUserList: [] as Array<SysOnlineUser>, // 在线用户列表
|
||||||
lastUserState: {
|
lastUserState: {
|
||||||
@ -104,28 +92,41 @@ const state = reactive({
|
|||||||
}, // 最后接收的用户变更状态信息
|
}, // 最后接收的用户变更状态信息
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 本地存储参数
|
||||||
|
const localPageParamKey = 'localPageParam:sysOnlineUser';
|
||||||
// 表格参数配置
|
// 表格参数配置
|
||||||
const options = useVxeTable<SysOnlineUser>({
|
const options = useVxeTable<SysOnlineUser>(
|
||||||
id: 'sysOnlineUser',
|
{
|
||||||
name: '在线用户',
|
id: 'sysOnlineUser',
|
||||||
columns: [
|
name: '在线用户',
|
||||||
// { type: 'checkbox', width: 40, fixed: 'left' },
|
columns: [
|
||||||
{ type: 'seq', title: '序号', width: 50, fixed: 'left' },
|
// { type: 'checkbox', width: 40, fixed: 'left' },
|
||||||
{ field: 'userName', title: '账号', minWidth: 110, showOverflow: 'tooltip' },
|
{ type: 'seq', title: '序号', width: 50, fixed: 'left' },
|
||||||
{ field: 'realName', title: '姓名', minWidth: 110, showOverflow: 'tooltip' },
|
{ field: 'userName', title: '账号', minWidth: 110, showOverflow: 'tooltip' },
|
||||||
{ field: 'ip', title: 'IP地址', minWidth: 100, showOverflow: 'tooltip' },
|
{ field: 'realName', title: '姓名', minWidth: 110, showOverflow: 'tooltip' },
|
||||||
{ field: 'browser', title: '浏览器', minWidth: 160, showOverflow: 'tooltip' },
|
{ field: 'ip', title: 'IP地址', minWidth: 100, showOverflow: 'tooltip' },
|
||||||
// { field: 'connectionId', title: '连接Id', minWidth: 160, showOverflow: 'tooltip', sortable: true },
|
{ field: 'browser', title: '浏览器', minWidth: 160, showOverflow: 'tooltip' },
|
||||||
{ field: 'time', title: '登录时间', minWidth: 120, showOverflow: 'tooltip' },
|
// { field: 'connectionId', title: '连接Id', minWidth: 160, showOverflow: 'tooltip', sortable: true },
|
||||||
{ title: '操作', fixed: 'right', width: 100, showOverflow: true, slots: { default: 'row_buttons' } },
|
{ 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 }),
|
// vxeGrid配置参数(此处可覆写任何参数),参考vxe-table官方文档
|
||||||
});
|
{
|
||||||
|
// 代理配置
|
||||||
|
proxyConfig: { autoLoad: true, ajax: { query: ({ page, sort }) => handleQueryApi(page, sort) } },
|
||||||
|
// 排序配置
|
||||||
|
sortConfig: { defaultSort: Local.get(localPageParamKey)?.defaultSort || state.localPageParam.defaultSort },
|
||||||
|
// 分页配置
|
||||||
|
pagerConfig: { pageSize: Local.get(localPageParamKey)?.pageSize || state.localPageParam.pageSize },
|
||||||
|
// 工具栏配置
|
||||||
|
toolbarConfig: { export: false },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// 页面初始化
|
// 页面初始化
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
state.localPageParam = Local.get(localPageParamKey) || state.localPageParam;
|
||||||
// 在线用户列表
|
// 在线用户列表
|
||||||
signalR.off('OnlineUserList');
|
signalR.off('OnlineUserList');
|
||||||
signalR.on('OnlineUserList', (data: any) => {
|
signalR.on('OnlineUserList', (data: any) => {
|
||||||
@ -170,20 +171,15 @@ const openDrawer = () => {
|
|||||||
handleQuery();
|
handleQuery();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 查询操作
|
// 查询api
|
||||||
const handleQuery = async (reset = false) => {
|
const handleQueryApi = async (page: VxeGridPropTypes.ProxyAjaxQueryPageParams, sort: VxeGridPropTypes.ProxyAjaxQuerySortCheckedParams) => {
|
||||||
options.loading = true;
|
const params = Object.assign(state.queryParams, { page: page.currentPage, pageSize: page.pageSize, field: sort.field, order: sort.order, descStr: 'desc' }) as PageOnlineUserInput;
|
||||||
if (reset) state.tableParams.page = 1;
|
return getAPI(SysOnlineUserApi).apiSysOnlineUserPagePost(params);
|
||||||
var res = await fetchData(null);
|
|
||||||
xGrid.value?.loadData(res.data.result?.items ?? []);
|
|
||||||
state.tableParams.total = res.data.result?.total;
|
|
||||||
options.loading = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 获取数据
|
// 查询操作
|
||||||
const fetchData = async (tableParams: any) => {
|
const handleQuery = async () => {
|
||||||
let params = Object.assign(state.queryParams, state.tableParams, tableParams);
|
await xGrid.value?.commitProxy('query');
|
||||||
return getAPI(SysOnlineUserApi).apiSysOnlineUserPagePost(params);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 重置操作
|
// 重置操作
|
||||||
@ -213,18 +209,18 @@ const forceOffline = async (row: any) => {
|
|||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
};
|
};
|
||||||
|
|
||||||
// 改变页码序号或页面容量
|
// 表格事件
|
||||||
const pageChange: VxePagerEvents.PageChange = ({ currentPage, pageSize }: VxePagerDefines.PageChangeEventParams) => {
|
const gridEvents: VxeGridListeners<SysOnlineUser> = {
|
||||||
state.tableParams.page = currentPage;
|
// 只对 pager-config 配置时有效,分页发生改变时会触发该事件
|
||||||
state.tableParams.pageSize = pageSize;
|
async pageChange({ pageSize }) {
|
||||||
handleQuery();
|
state.localPageParam.pageSize = pageSize;
|
||||||
};
|
Local.set(localPageParamKey, state.localPageParam);
|
||||||
|
},
|
||||||
// 列排序
|
// 当排序条件发生变化时会触发该事件
|
||||||
const sortChange = (options: any) => {
|
async sortChange({ field, order }) {
|
||||||
state.tableParams.field = options.field;
|
state.localPageParam.defaultSort = { field: field, order: order!, descStr: 'desc' };
|
||||||
state.tableParams.order = options.order;
|
Local.set(localPageParamKey, state.localPageParam);
|
||||||
handleQuery();
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// 导出对象
|
// 导出对象
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user