feat: 操作日志
This commit is contained in:
parent
82e63dbcf6
commit
51c63c1b69
@ -4,6 +4,8 @@ import { setupVbenVxeTable, useVbenVxeGrid } from '@vben/plugins/vxe-table';
|
|||||||
|
|
||||||
import { Button, Image } from 'ant-design-vue';
|
import { Button, Image } from 'ant-design-vue';
|
||||||
|
|
||||||
|
import { renderDict } from '#/utils/render';
|
||||||
|
|
||||||
import { useVbenForm } from './form';
|
import { useVbenForm } from './form';
|
||||||
|
|
||||||
setupVbenVxeTable({
|
setupVbenVxeTable({
|
||||||
@ -16,15 +18,15 @@ setupVbenVxeTable({
|
|||||||
proxyConfig: {
|
proxyConfig: {
|
||||||
autoLoad: true,
|
autoLoad: true,
|
||||||
response: {
|
response: {
|
||||||
result: 'items',
|
result: 'rows',
|
||||||
total: 'total',
|
total: 'total',
|
||||||
list: 'items',
|
list: 'rows',
|
||||||
},
|
},
|
||||||
showActiveMsg: true,
|
showActiveMsg: true,
|
||||||
showResponseMsg: false,
|
showResponseMsg: false,
|
||||||
},
|
},
|
||||||
round: true,
|
round: true,
|
||||||
size: 'small',
|
size: 'medium',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -48,6 +50,23 @@ setupVbenVxeTable({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表格dict渲染 必传 props: { field: 参数名, dictName: 字典名 }
|
||||||
|
*/
|
||||||
|
vxeUI.renderer.add('DictTag', {
|
||||||
|
renderDefault(renderOpts, params) {
|
||||||
|
const { props } = renderOpts;
|
||||||
|
const field = props?.field;
|
||||||
|
const dictName = props?.dictName;
|
||||||
|
if (!field || !dictName) {
|
||||||
|
console.warn('DictTag: field or dictName is not provided');
|
||||||
|
return 'error';
|
||||||
|
}
|
||||||
|
const { row } = params;
|
||||||
|
return renderDict(row[field], dictName);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// 这里可以自行扩展 vxe-table 的全局配置,比如自定义格式化
|
// 这里可以自行扩展 vxe-table 的全局配置,比如自定义格式化
|
||||||
// vxeUI.formats.add
|
// vxeUI.formats.add
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import type { ColumnType } from 'ant-design-vue/es/table';
|
import type { FormSchemaGetter, VxeGridProps } from '#/adapter';
|
||||||
|
|
||||||
import type { FormSchemaGetter } from '#/adapter';
|
|
||||||
import type { DescItem } from '#/components/description';
|
import type { DescItem } from '#/components/description';
|
||||||
|
|
||||||
import { DictEnum } from '@vben/constants';
|
import { DictEnum } from '@vben/constants';
|
||||||
@ -50,66 +48,48 @@ export const querySchema: FormSchemaGetter = () => [
|
|||||||
component: 'RangePicker',
|
component: 'RangePicker',
|
||||||
fieldName: 'createTime',
|
fieldName: 'createTime',
|
||||||
label: '操作时间',
|
label: '操作时间',
|
||||||
|
componentProps: {
|
||||||
|
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export const columns: ColumnType[] = [
|
export const columns: VxeGridProps['columns'] = [
|
||||||
|
{ type: 'checkbox', width: 60 },
|
||||||
|
{ field: 'title', title: '系统模块' },
|
||||||
{
|
{
|
||||||
align: 'center',
|
|
||||||
dataIndex: 'title',
|
|
||||||
title: '系统模块',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
align: 'center',
|
|
||||||
customRender({ value }) {
|
|
||||||
return renderDict(value, DictEnum.SYS_OPER_TYPE);
|
|
||||||
},
|
|
||||||
dataIndex: 'businessType',
|
|
||||||
title: '操作类型',
|
title: '操作类型',
|
||||||
},
|
field: 'businessType',
|
||||||
{
|
cellRender: {
|
||||||
align: 'center',
|
name: 'DictTag',
|
||||||
dataIndex: 'operName',
|
props: { field: 'businessType', dictName: DictEnum.SYS_OPER_TYPE },
|
||||||
title: '操作人员',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
align: 'center',
|
|
||||||
dataIndex: 'operIp',
|
|
||||||
title: 'IP地址',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
align: 'center',
|
|
||||||
dataIndex: 'operLocation',
|
|
||||||
title: 'IP信息',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
align: 'center',
|
|
||||||
customRender({ value }) {
|
|
||||||
return renderDict(value, DictEnum.SYS_COMMON_STATUS);
|
|
||||||
},
|
},
|
||||||
dataIndex: 'status',
|
},
|
||||||
|
{ field: 'operName', title: '操作人员' },
|
||||||
|
{ field: 'operIp', title: 'IP地址' },
|
||||||
|
{ field: 'operLocation', title: 'IP信息' },
|
||||||
|
{
|
||||||
|
field: 'status',
|
||||||
title: '操作状态',
|
title: '操作状态',
|
||||||
},
|
cellRender: {
|
||||||
{
|
name: 'DictTag',
|
||||||
align: 'center',
|
props: { field: 'status', dictName: DictEnum.SYS_COMMON_STATUS },
|
||||||
dataIndex: 'operTime',
|
|
||||||
sorter: true,
|
|
||||||
title: '操作日期',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
align: 'center',
|
|
||||||
customRender({ text }) {
|
|
||||||
return `${text} ms`;
|
|
||||||
},
|
},
|
||||||
dataIndex: 'costTime',
|
},
|
||||||
sorter: true,
|
{ field: 'operTime', title: '操作日期' },
|
||||||
|
{
|
||||||
|
field: 'costTime',
|
||||||
title: '操作耗时',
|
title: '操作耗时',
|
||||||
|
formatter({ cellValue }) {
|
||||||
|
return `${cellValue} ms`;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
align: 'center',
|
field: 'action',
|
||||||
dataIndex: 'action',
|
|
||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
|
slots: { default: 'action' },
|
||||||
title: '操作',
|
title: '操作',
|
||||||
|
width: 120,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -3,70 +3,160 @@ import type { Recordable } from '@vben/types';
|
|||||||
|
|
||||||
import type { OperationLog } from '#/api/monitor/operlog/model';
|
import type { OperationLog } from '#/api/monitor/operlog/model';
|
||||||
|
|
||||||
import { onMounted, ref } from 'vue';
|
import { computed } from 'vue';
|
||||||
|
|
||||||
import { Page, useVbenDrawer } from '@vben/common-ui';
|
import { Page, useVbenDrawer, type VbenFormProps } from '@vben/common-ui';
|
||||||
import { $t } from '@vben/locales';
|
import { $t } from '@vben/locales';
|
||||||
|
|
||||||
import { Card, Table } from 'ant-design-vue';
|
import { Modal, Space } from 'ant-design-vue';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
import { useVbenForm } from '#/adapter';
|
import { useVbenVxeGrid, type VxeGridProps } from '#/adapter';
|
||||||
import { operLogList } from '#/api/monitor/operlog';
|
import {
|
||||||
|
operLogClean,
|
||||||
|
operLogDelete,
|
||||||
|
operLogExport,
|
||||||
|
operLogList,
|
||||||
|
} from '#/api/monitor/operlog';
|
||||||
|
import { downloadExcel } from '#/utils/file/download';
|
||||||
|
import { confirmDeleteModal } from '#/utils/modal';
|
||||||
|
|
||||||
import { columns, querySchema } from './data';
|
import { columns, querySchema } from './data';
|
||||||
import operationPreviewDrawer from './OperationPreviewDrawer.vue';
|
import operationPreviewDrawer from './OperationPreviewDrawer.vue';
|
||||||
|
|
||||||
const [QueryForm] = useVbenForm({
|
const formOptions: VbenFormProps = {
|
||||||
// 默认展开
|
schema: querySchema(),
|
||||||
collapsed: false,
|
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
|
||||||
// 所有表单项共用,可单独在表单内覆盖
|
};
|
||||||
commonConfig: {
|
|
||||||
// 所有表单项
|
const gridOptions: VxeGridProps<OperationLog> = {
|
||||||
componentProps: {
|
checkboxConfig: {
|
||||||
class: 'w-full',
|
// 高亮
|
||||||
|
highlight: true,
|
||||||
|
// 翻页时保留选中状态
|
||||||
|
reserve: true,
|
||||||
|
// 点击行选中
|
||||||
|
trigger: 'row',
|
||||||
|
},
|
||||||
|
columns,
|
||||||
|
height: 'auto',
|
||||||
|
keepSource: true,
|
||||||
|
pagerConfig: {},
|
||||||
|
proxyConfig: {
|
||||||
|
ajax: {
|
||||||
|
query: async ({ page }, formValues) => {
|
||||||
|
// 区间选择器处理
|
||||||
|
if (formValues?.createTime) {
|
||||||
|
formValues.params = {
|
||||||
|
beginTime: dayjs(formValues.createTime[0]).format(
|
||||||
|
'YYYY-MM-DD 00:00:00',
|
||||||
|
),
|
||||||
|
endTime: dayjs(formValues.createTime[1]).format(
|
||||||
|
'YYYY-MM-DD 23:59:59',
|
||||||
|
),
|
||||||
|
};
|
||||||
|
Reflect.deleteProperty(formValues, 'createTime');
|
||||||
|
} else {
|
||||||
|
Reflect.deleteProperty(formValues, 'params');
|
||||||
|
}
|
||||||
|
return await operLogList({
|
||||||
|
pageNum: page.currentPage,
|
||||||
|
pageSize: page.pageSize,
|
||||||
|
...formValues,
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
schema: querySchema(),
|
rowConfig: {
|
||||||
// 是否可展开
|
isHover: true,
|
||||||
showCollapseButton: true,
|
keyField: 'operId',
|
||||||
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 dataSource = ref<OperationLog[]>([]);
|
const [BasicTable, tableApi] = useVbenVxeGrid({ formOptions, gridOptions });
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
const resp = await operLogList({ pageNum: 1, pageSize: 30 });
|
|
||||||
dataSource.value = resp.rows;
|
|
||||||
});
|
|
||||||
|
|
||||||
const [OperationPreviewDrawer, drawerApi] = useVbenDrawer({
|
const [OperationPreviewDrawer, drawerApi] = useVbenDrawer({
|
||||||
connectedComponent: operationPreviewDrawer,
|
connectedComponent: operationPreviewDrawer,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 预览
|
||||||
|
* @param record 操作日志记录
|
||||||
|
*/
|
||||||
function handlePreview(record: Recordable<any>) {
|
function handlePreview(record: Recordable<any>) {
|
||||||
drawerApi.setData({ record });
|
drawerApi.setData({ record });
|
||||||
drawerApi.open();
|
drawerApi.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空全部日志
|
||||||
|
*/
|
||||||
|
function handleClear() {
|
||||||
|
confirmDeleteModal({
|
||||||
|
onValidated: async () => {
|
||||||
|
await operLogClean();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: 选中条件的判断
|
||||||
|
*/
|
||||||
|
const checked = computed(() => {
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除日志
|
||||||
|
*/
|
||||||
|
async function handleDelete() {
|
||||||
|
const rows = tableApi.grid.getCheckboxRecords();
|
||||||
|
const ids = rows.map((row: any) => row.operId);
|
||||||
|
Modal.confirm({
|
||||||
|
title: '提示',
|
||||||
|
okType: 'danger',
|
||||||
|
content: `确认删除选中的${ids.length}条操作日志吗?`,
|
||||||
|
onOk: async () => {
|
||||||
|
await operLogDelete(ids);
|
||||||
|
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>
|
||||||
<div class="bg-background"></div>
|
|
||||||
<Table :columns="columns" :data-source="dataSource">
|
|
||||||
<template #bodyCell="{ record, column }">
|
|
||||||
<template v-if="column.dataIndex === 'action'">
|
|
||||||
<a-button size="small" type="link" @click="handlePreview(record)">
|
|
||||||
{{ $t('pages.common.preview') }}
|
|
||||||
</a-button>
|
|
||||||
</template>
|
|
||||||
</template>
|
</template>
|
||||||
</Table>
|
<template #toolbar-tools>
|
||||||
|
<Space>
|
||||||
|
<a-button @click="handleClear">
|
||||||
|
{{ $t('pages.common.clear') }}
|
||||||
|
</a-button>
|
||||||
|
<a-button @click="downloadExcel(operLogExport, '操作日志', {})">
|
||||||
|
{{ $t('pages.common.export') }}
|
||||||
|
</a-button>
|
||||||
|
<a-button
|
||||||
|
:disabled="!checked"
|
||||||
|
danger
|
||||||
|
type="primary"
|
||||||
|
@click="handleDelete"
|
||||||
|
>
|
||||||
|
{{ $t('pages.common.delete') }}
|
||||||
|
</a-button>
|
||||||
|
</Space>
|
||||||
|
</template>
|
||||||
|
<template #action="{ row }">
|
||||||
|
<a-button size="small" type="link" @click="handlePreview(row)">
|
||||||
|
{{ $t('pages.common.preview') }}
|
||||||
|
</a-button>
|
||||||
|
</template>
|
||||||
|
</BasicTable>
|
||||||
<OperationPreviewDrawer />
|
<OperationPreviewDrawer />
|
||||||
</Page>
|
</Page>
|
||||||
</template>
|
</template>
|
||||||
|
4528
pnpm-lock.yaml
4528
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user