reactor:【system 系统管理】infra 的 apiAccessLog 进一步统一代码风格

pull/210/head
YunaiV 2025-09-08 23:25:33 +08:00
parent 2e38b1906d
commit cec3b7ab1e
5 changed files with 53 additions and 68 deletions

View File

@ -79,14 +79,17 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{ {
field: 'id', field: 'id',
title: '日志编号', title: '日志编号',
minWidth: 100,
}, },
{ {
field: 'userId', field: 'userId',
title: '用户编号', title: '用户编号',
minWidth: 100,
}, },
{ {
field: 'userType', field: 'userType',
title: '用户类型', title: '用户类型',
minWidth: 120,
cellRender: { cellRender: {
name: 'CellDict', name: 'CellDict',
props: { type: DICT_TYPE.USER_TYPE }, props: { type: DICT_TYPE.USER_TYPE },
@ -95,28 +98,34 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{ {
field: 'applicationName', field: 'applicationName',
title: '应用名', title: '应用名',
minWidth: 150,
}, },
{ {
field: 'requestMethod', field: 'requestMethod',
title: '请求方法', title: '请求方法',
minWidth: 80,
}, },
{ {
field: 'requestUrl', field: 'requestUrl',
title: '请求地址', title: '请求地址',
minWidth: 300,
}, },
{ {
field: 'beginTime', field: 'beginTime',
title: '请求时间', title: '请求时间',
minWidth: 180,
formatter: 'formatDateTime', formatter: 'formatDateTime',
}, },
{ {
field: 'duration', field: 'duration',
title: '执行时长', title: '执行时长',
minWidth: 120,
formatter: ({ cellValue }) => `${cellValue} ms`, formatter: ({ cellValue }) => `${cellValue} ms`,
}, },
{ {
field: 'resultCode', field: 'resultCode',
title: '操作结果', title: '操作结果',
minWidth: 150,
formatter: ({ row }) => { formatter: ({ row }) => {
return row.resultCode === 0 ? '成功' : `失败(${row.resultMsg})`; return row.resultCode === 0 ? '成功' : `失败(${row.resultMsg})`;
}, },
@ -124,14 +133,17 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{ {
field: 'operateModule', field: 'operateModule',
title: '操作模块', title: '操作模块',
minWidth: 150,
}, },
{ {
field: 'operateName', field: 'operateName',
title: '操作名', title: '操作名',
minWidth: 220,
}, },
{ {
field: 'operateType', field: 'operateType',
title: '操作类型', title: '操作类型',
minWidth: 120,
cellRender: { cellRender: {
name: 'CellDict', name: 'CellDict',
props: { type: DICT_TYPE.INFRA_OPERATE_TYPE }, props: { type: DICT_TYPE.INFRA_OPERATE_TYPE },

View File

@ -21,7 +21,7 @@ const [DetailModal, detailModalApi] = useVbenModal({
}); });
/** 刷新表格 */ /** 刷新表格 */
function onRefresh() { function handleRefresh() {
gridApi.query(); gridApi.query();
} }
@ -57,6 +57,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
isHover: true,
}, },
toolbarConfig: { toolbarConfig: {
refresh: true, refresh: true,
@ -72,7 +73,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<DocAlert title="系统日志" url="https://doc.iocoder.cn/system-log/" /> <DocAlert title="系统日志" url="https://doc.iocoder.cn/system-log/" />
</template> </template>
<DetailModal @success="onRefresh" /> <DetailModal @success="handleRefresh" />
<Grid table-title="API 访"> <Grid table-title="API 访">
<template #toolbar-tools> <template #toolbar-tools>
<TableAction <TableAction

View File

@ -1,16 +1,11 @@
import type { VbenFormSchema } from '#/adapter/form'; import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { InfraApiAccessLogApi } from '#/api/infra/api-access-log';
import { useAccess } from '@vben/access';
import { DICT_TYPE } from '@vben/constants'; import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks'; import { getDictOptions } from '@vben/hooks';
import { getRangePickerDefaultProps } from '#/utils'; import { getRangePickerDefaultProps } from '#/utils';
const { hasAccessByCodes } = useAccess();
/** 列表的搜索表单 */ /** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] { export function useGridFormSchema(): VbenFormSchema[] {
return [ return [
@ -46,7 +41,6 @@ export function useGridFormSchema(): VbenFormSchema[] {
fieldName: 'beginTime', fieldName: 'beginTime',
label: '请求时间', label: '请求时间',
component: 'RangePicker', component: 'RangePicker',
// TODO @puhui999时间范围不太对。结束时间不是 23:59:59 这种哈
componentProps: { componentProps: {
...getRangePickerDefaultProps(), ...getRangePickerDefaultProps(),
clearable: true, clearable: true,
@ -74,9 +68,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
} }
/** 列表的字段 */ /** 列表的字段 */
export function useGridColumns<T = InfraApiAccessLogApi.ApiAccessLog>( export function useGridColumns(): VxeTableGridOptions['columns'] {
onActionClick: OnActionClickFn<T>,
): VxeTableGridOptions['columns'] {
return [ return [
{ {
field: 'id', field: 'id',
@ -152,26 +144,10 @@ export function useGridColumns<T = InfraApiAccessLogApi.ApiAccessLog>(
}, },
}, },
{ {
field: 'operation',
title: '操作', title: '操作',
minWidth: 80, width: 80,
align: 'center',
fixed: 'right', fixed: 'right',
cellRender: { slots: { default: 'actions' },
attrs: {
nameField: 'id',
nameTitle: 'API访问日志',
onClick: onActionClick,
},
name: 'CellOperation',
options: [
{
code: 'detail',
text: '详情',
show: hasAccessByCodes(['infra:api-access-log:query']),
},
],
},
}, },
]; ];
} }

View File

@ -1,17 +1,11 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { import type { VxeTableGridOptions } from '#/adapter/vxe-table';
OnActionClickParams,
VxeTableGridOptions,
} from '#/adapter/vxe-table';
import type { InfraApiAccessLogApi } from '#/api/infra/api-access-log'; import type { InfraApiAccessLogApi } from '#/api/infra/api-access-log';
import { DocAlert, Page, useVbenModal } from '@vben/common-ui'; import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { Download } from '@vben/icons';
import { downloadFileFromBlobPart } from '@vben/utils'; import { downloadFileFromBlobPart } from '@vben/utils';
import { ElButton } from 'element-plus'; import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { import {
exportApiAccessLog, exportApiAccessLog,
getApiAccessLogPage, getApiAccessLogPage,
@ -27,40 +21,27 @@ const [DetailModal, detailModalApi] = useVbenModal({
}); });
/** 刷新表格 */ /** 刷新表格 */
function onRefresh() { function handleRefresh() {
gridApi.query(); gridApi.query();
} }
/** 导出表格 */ /** 导出表格 */
async function onExport() { async function handleExport() {
const data = await exportApiAccessLog(await gridApi.formApi.getValues()); const data = await exportApiAccessLog(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: 'API 访问日志.xls', source: data }); downloadFileFromBlobPart({ fileName: 'API 访问日志.xls', source: data });
} }
/** 查看 API 访问日志详情 */ /** 查看 API 访问日志详情 */
function onDetail(row: InfraApiAccessLogApi.ApiAccessLog) { function handleDetail(row: InfraApiAccessLogApi.ApiAccessLog) {
detailModalApi.setData(row).open(); detailModalApi.setData(row).open();
} }
/** 表格操作按钮的回调函数 */
function onActionClick({
code,
row,
}: OnActionClickParams<InfraApiAccessLogApi.ApiAccessLog>) {
switch (code) {
case 'detail': {
onDetail(row);
break;
}
}
}
const [Grid, gridApi] = useVbenVxeGrid({ const [Grid, gridApi] = useVbenVxeGrid({
formOptions: { formOptions: {
schema: useGridFormSchema(), schema: useGridFormSchema(),
}, },
gridOptions: { gridOptions: {
columns: useGridColumns(onActionClick), columns: useGridColumns(),
height: 'auto', height: 'auto',
keepSource: true, keepSource: true,
proxyConfig: { proxyConfig: {
@ -76,6 +57,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
isHover: true,
}, },
toolbarConfig: { toolbarConfig: {
refresh: true, refresh: true,
@ -91,18 +73,34 @@ const [Grid, gridApi] = useVbenVxeGrid({
<DocAlert title="系统日志" url="https://doc.iocoder.cn/system-log/" /> <DocAlert title="系统日志" url="https://doc.iocoder.cn/system-log/" />
</template> </template>
<DetailModal @success="onRefresh" /> <DetailModal @success="handleRefresh" />
<Grid table-title="API 访"> <Grid table-title="API 访">
<template #toolbar-tools> <template #toolbar-tools>
<ElButton <TableAction
type="primary" :actions="[
class="ml-2" {
@click="onExport" label: $t('ui.actionTitle.export'),
v-access:code="['infra:api-access-log:export']" type: 'primary',
> icon: ACTION_ICON.DOWNLOAD,
<Download class="size-5" /> auth: ['infra:api-access-log:export'],
{{ $t('ui.actionTitle.export') }} onClick: handleExport,
</ElButton> },
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.detail'),
type: 'primary',
link: true,
icon: ACTION_ICON.VIEW,
auth: ['infra:api-access-log:query'],
onClick: handleDetail.bind(null, row),
},
]"
/>
</template> </template>
</Grid> </Grid>
</Page> </Page>

View File

@ -3,9 +3,7 @@ import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { InfraApiErrorLogApi } from '#/api/infra/api-error-log'; import type { InfraApiErrorLogApi } from '#/api/infra/api-error-log';
import { useAccess } from '@vben/access'; import { useAccess } from '@vben/access';
import { InfraApiErrorLogProcessStatusEnum } from '@vben/constants'; import { DICT_TYPE, InfraApiErrorLogProcessStatusEnum } from '@vben/constants';
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks'; import { getDictOptions } from '@vben/hooks';
import { getRangePickerDefaultProps } from '#/utils'; import { getRangePickerDefaultProps } from '#/utils';