feat: 在线用户
This commit is contained in:
parent
4ebd4821e2
commit
6e807a3653
@ -1,6 +1,6 @@
|
|||||||
import type { OnlineUser } from './model';
|
import type { OnlineUser } from './model';
|
||||||
|
|
||||||
import type { PageQuery } from '#/api/common';
|
import type { PageQuery, PageResult } from '#/api/common';
|
||||||
|
|
||||||
import { requestClient } from '#/api/request';
|
import { requestClient } from '#/api/request';
|
||||||
|
|
||||||
@ -14,11 +14,11 @@ enum Api {
|
|||||||
* @returns OnlineUser[]
|
* @returns OnlineUser[]
|
||||||
*/
|
*/
|
||||||
export function onlineDeviceList() {
|
export function onlineDeviceList() {
|
||||||
return requestClient.get<OnlineUser[]>(Api.root);
|
return requestClient.get<PageResult<OnlineUser>>(Api.root);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onlineList(params?: PageQuery) {
|
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
|
* @returns void
|
||||||
*/
|
*/
|
||||||
export function forceLogout(tokenId: string) {
|
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
|
* @returns void
|
||||||
*/
|
*/
|
||||||
export function forceLogout2(tokenId: string) {
|
export function forceLogout2(tokenId: string) {
|
||||||
return requestClient.post<void>(`${Api.root}/${tokenId}`);
|
return requestClient.postWithMsg<void>(`${Api.root}/${tokenId}`);
|
||||||
}
|
}
|
||||||
|
@ -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 = () => [
|
export const querySchema: FormSchemaGetter = () => [
|
||||||
{
|
{
|
||||||
@ -12,3 +18,66 @@ export const querySchema: FormSchemaGetter = () => [
|
|||||||
label: '用户账号',
|
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,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
@ -1,36 +1,68 @@
|
|||||||
<script setup lang="ts">
|
<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({
|
import { columns, querySchema } from './data';
|
||||||
// 默认展开
|
|
||||||
collapsed: false,
|
const formOptions: VbenFormProps = {
|
||||||
// 所有表单项共用,可单独在表单内覆盖
|
schema: querySchema(),
|
||||||
commonConfig: {
|
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
|
||||||
// 所有表单项
|
};
|
||||||
componentProps: {
|
|
||||||
class: 'w-full',
|
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(),
|
rowConfig: {
|
||||||
// 是否可展开
|
isHover: true,
|
||||||
showCollapseButton: true,
|
keyField: 'tokenId',
|
||||||
submitButtonOptions: {
|
|
||||||
text: '查询',
|
|
||||||
},
|
},
|
||||||
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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Page>
|
<Page :auto-content-height="true">
|
||||||
<Card>
|
<BasicTable>
|
||||||
<QueryForm />
|
<template #toolbar-actions>
|
||||||
</Card>
|
<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>
|
</Page>
|
||||||
</template>
|
</template>
|
||||||
|
2650
pnpm-lock.yaml
2650
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user