😎调整在线用户页面

This commit is contained in:
zuohuaijun 2024-07-11 00:48:37 +08:00
parent d1089b50f7
commit 323c1aa8d6

View File

@ -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(); },
}; };
// //