feat: 在线用户

This commit is contained in:
dap 2024-10-05 13:44:02 +08:00
parent 4ebd4821e2
commit 6e807a3653
4 changed files with 369 additions and 2440 deletions

View File

@ -1,6 +1,6 @@
import type { OnlineUser } from './model';
import type { PageQuery } from '#/api/common';
import type { PageQuery, PageResult } from '#/api/common';
import { requestClient } from '#/api/request';
@ -14,11 +14,11 @@ enum Api {
* @returns OnlineUser[]
*/
export function onlineDeviceList() {
return requestClient.get<OnlineUser[]>(Api.root);
return requestClient.get<PageResult<OnlineUser>>(Api.root);
}
export function onlineList(params?: PageQuery) {
return requestClient.get<OnlineUser[]>(Api.onlineList, { params });
return requestClient.get<PageResult<OnlineUser>>(Api.onlineList, { params });
}
/**
@ -27,7 +27,7 @@ export function onlineList(params?: PageQuery) {
* @returns void
*/
export function forceLogout(tokenId: string) {
return requestClient.delete<void>(`${Api.root}/${tokenId}`);
return requestClient.deleteWithMsg<void>(`${Api.root}/${tokenId}`);
}
/**
@ -36,5 +36,5 @@ export function forceLogout(tokenId: string) {
* @returns void
*/
export function forceLogout2(tokenId: string) {
return requestClient.post<void>(`${Api.root}/${tokenId}`);
return requestClient.postWithMsg<void>(`${Api.root}/${tokenId}`);
}

View File

@ -1,4 +1,10 @@
import type { FormSchemaGetter } from '#/adapter';
import type { FormSchemaGetter, VxeGridProps } from '#/adapter';
import type { VNode } from 'vue';
import dayjs from 'dayjs';
import { renderBrowserIcon, renderOsIcon } from '#/utils/render';
export const querySchema: FormSchemaGetter = () => [
{
@ -12,3 +18,66 @@ export const querySchema: FormSchemaGetter = () => [
label: '用户账号',
},
];
export const columns: VxeGridProps['columns'] = [
{
title: '登录平台',
field: 'deviceType',
},
{
title: '登录账号',
field: 'userName',
},
{
title: '部门名称',
field: 'deptName',
},
{
title: 'IP地址',
field: 'ipaddr',
},
{
title: '登录地址',
field: 'loginLocation',
},
{
title: '浏览器',
field: 'browser',
slots: {
default: ({ row }) => {
return renderBrowserIcon(row.browser, true) as VNode;
},
},
},
{
title: '系统',
field: 'os',
slots: {
default: ({ row }) => {
// Windows 10 or Windows Server 2016 太长了 分割一下 详情依旧能看到详细的
let value = row.os;
if (value) {
const split = value.split(' or ');
if (split.length === 2) {
value = split[0];
}
}
return renderOsIcon(value, true) as VNode;
},
},
},
{
title: '登录时间',
field: 'loginTime',
formatter: ({ cellValue }) => {
return dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss');
},
},
{
field: 'action',
fixed: 'right',
slots: { default: 'action' },
title: '操作',
width: 120,
},
];

View File

@ -1,36 +1,68 @@
<script setup lang="ts">
import { Page } from '@vben/common-ui';
import type { Recordable } from '@vben/types';
import { Card } from 'ant-design-vue';
import { Page, type VbenFormProps } from '@vben/common-ui';
import { useVbenForm } from '#/adapter';
import { Popconfirm } from 'ant-design-vue';
import { querySchema } from './data';
import { useVbenVxeGrid, type VxeGridProps } from '#/adapter';
import { forceLogout, onlineList } from '#/api/monitor/online';
const [QueryForm] = useVbenForm({
//
collapsed: false,
//
commonConfig: {
//
componentProps: {
class: 'w-full',
import { columns, querySchema } from './data';
const formOptions: VbenFormProps = {
schema: querySchema(),
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
};
const gridOptions: VxeGridProps = {
columns,
height: 'auto',
keepSource: true,
pagerConfig: {},
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await onlineList({
pageNum: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
schema: querySchema(),
//
showCollapseButton: true,
submitButtonOptions: {
text: '查询',
rowConfig: {
isHover: true,
keyField: 'tokenId',
},
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
});
round: true,
align: 'center',
showOverflow: true,
};
const [BasicTable, tableApi] = useVbenVxeGrid({ formOptions, gridOptions });
async function handleForceOffline(row: Recordable<any>) {
await forceLogout(row.tokenId);
await tableApi.reload();
}
</script>
<template>
<Page>
<Card>
<QueryForm />
</Card>
<Page :auto-content-height="true">
<BasicTable>
<template #toolbar-actions>
<span class="pl-[7px] text-[16px]">操作日志列表</span>
</template>
<template #action="{ row }">
<Popconfirm
:title="`确认强制下线[${row.userName}]?`"
placement="left"
@confirm="handleForceOffline(row)"
>
<a-button danger size="small" type="link">强制下线</a-button>
</Popconfirm>
</template>
</BasicTable>
</Page>
</template>

File diff suppressed because it is too large Load Diff