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

This commit is contained in:
YunaiV
2025-09-06 19:55:38 +08:00
parent 1d11ebad3a
commit 6d47871f02
5 changed files with 56 additions and 72 deletions

View File

@@ -78,35 +78,43 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{ {
field: 'id', field: 'id',
title: '日志编号', title: '日志编号',
minWidth: 100,
}, },
{ {
field: 'userName', field: 'userName',
title: '操作人', title: '操作人',
minWidth: 120,
}, },
{ {
field: 'type', field: 'type',
title: '操作模块', title: '操作模块',
minWidth: 120,
}, },
{ {
field: 'subType', field: 'subType',
title: '操作名', title: '操作名',
minWidth: 160,
}, },
{ {
field: 'action', field: 'action',
title: '操作内容', title: '操作内容',
minWidth: 200,
}, },
{ {
field: 'createTime', field: 'createTime',
title: '操作时间', title: '操作时间',
minWidth: 180,
formatter: 'formatDateTime', formatter: 'formatDateTime',
}, },
{ {
field: 'bizId', field: 'bizId',
title: '业务编号', title: '业务编号',
minWidth: 120,
}, },
{ {
field: 'userIp', field: 'userIp',
title: '操作 IP', title: '操作 IP',
minWidth: 120,
}, },
{ {
title: '操作', title: '操作',

View File

@@ -18,7 +18,7 @@ const [DetailModal, detailModalApi] = useVbenModal({
}); });
/** 刷新表格 */ /** 刷新表格 */
function onRefresh() { function handleRefresh() {
gridApi.query(); gridApi.query();
} }
@@ -54,6 +54,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
isHover: true,
}, },
toolbarConfig: { toolbarConfig: {
refresh: true, refresh: true,
@@ -69,7 +70,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="操作日志列表"> <Grid table-title="操作日志列表">
<template #toolbar-tools> <template #toolbar-tools>
<TableAction <TableAction

View File

@@ -1,14 +1,9 @@
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 { SystemOperateLogApi } from '#/api/system/operate-log';
import { useAccess } from '@vben/access';
import { getSimpleUserList } from '#/api/system/user'; import { getSimpleUserList } from '#/api/system/user';
import { getRangePickerDefaultProps } from '#/utils'; import { getRangePickerDefaultProps } from '#/utils';
const { hasAccessByCodes } = useAccess();
/** 列表的搜索表单 */ /** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] { export function useGridFormSchema(): VbenFormSchema[] {
return [ return [
@@ -75,9 +70,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
} }
/** 列表的字段 */ /** 列表的字段 */
export function useGridColumns<T = SystemOperateLogApi.OperateLog>( export function useGridColumns(): VxeTableGridOptions['columns'] {
onActionClick: OnActionClickFn<T>,
): VxeTableGridOptions['columns'] {
return [ return [
{ {
field: 'id', field: 'id',
@@ -121,26 +114,10 @@ export function useGridColumns<T = SystemOperateLogApi.OperateLog>(
minWidth: 120, minWidth: 120,
}, },
{ {
field: 'operation',
title: '操作', title: '操作',
minWidth: 120, width: 80,
align: 'center',
fixed: 'right', fixed: 'right',
cellRender: { slots: { default: 'actions' },
attrs: {
nameField: 'action',
nameTitle: '操作日志',
onClick: onActionClick,
},
name: 'CellOperation',
options: [
{
code: 'detail',
text: '详情',
show: hasAccessByCodes(['system:operate-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 { SystemOperateLogApi } from '#/api/system/operate-log'; import type { SystemOperateLogApi } from '#/api/system/operate-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 { exportOperateLog, getOperateLogPage } from '#/api/system/operate-log'; import { exportOperateLog, getOperateLogPage } from '#/api/system/operate-log';
import { $t } from '#/locales'; import { $t } from '#/locales';
@@ -24,40 +18,27 @@ const [DetailModal, detailModalApi] = useVbenModal({
}); });
/** 刷新表格 */ /** 刷新表格 */
function onRefresh() { function handleRefresh() {
gridApi.query(); gridApi.query();
} }
/** 导出表格 */ /** 导出表格 */
async function onExport() { async function handleExport() {
const data = await exportOperateLog(await gridApi.formApi.getValues()); const data = await exportOperateLog(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '操作日志.xls', source: data }); downloadFileFromBlobPart({ fileName: '操作日志.xls', source: data });
} }
/** 查看操作日志详情 */ /** 查看操作日志详情 */
function onDetail(row: SystemOperateLogApi.OperateLog) { function handleDetail(row: SystemOperateLogApi.OperateLog) {
detailModalApi.setData(row).open(); detailModalApi.setData(row).open();
} }
/** 表格操作按钮的回调函数 */
function onActionClick({
code,
row,
}: OnActionClickParams<SystemOperateLogApi.OperateLog>) {
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: {
@@ -73,6 +54,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
isHover: true,
}, },
toolbarConfig: { toolbarConfig: {
refresh: true, refresh: true,
@@ -88,18 +70,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="操作日志列表"> <Grid table-title="操作日志列表">
<template #toolbar-tools> <template #toolbar-tools>
<ElButton <TableAction
type="primary" :actions="[
class="ml-2" {
@click="onExport" label: $t('ui.actionTitle.export'),
v-access:code="['system:operate-log:export']" type: 'primary',
> icon: ACTION_ICON.DOWNLOAD,
<Download class="mr-2 size-5" /> auth: ['system:operate-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: ['system:operate-log:query'],
onClick: handleDetail.bind(null, row),
},
]"
/>
</template> </template>
</Grid> </Grid>
</Page> </Page>