mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat:对接日志管理
This commit is contained in:
208
src/views/monitor/oper-log/index.vue
Normal file
208
src/views/monitor/oper-log/index.vue
Normal file
@ -0,0 +1,208 @@
|
||||
<script setup lang="tsx">
|
||||
import { NButton } from 'naive-ui';
|
||||
import { fetchBatchDeleteOperLog, fetchCleanOperLog, fetchGetOperLogList } from '@/service/api/monitor/oper-log';
|
||||
import { $t } from '@/locales';
|
||||
import { useAuth } from '@/hooks/business/auth';
|
||||
import { useAppStore } from '@/store/modules/app';
|
||||
import { useDownload } from '@/hooks/business/download';
|
||||
import { useTable, useTableOperate } from '@/hooks/common/table';
|
||||
import DictTag from '@/components/custom/dict-tag.vue';
|
||||
import { useDict } from '@/hooks/business/dict';
|
||||
import OperLogViewDrawer from './modules/oper-log-view-drawer.vue';
|
||||
import OperLogSearch from './modules/oper-log-search.vue';
|
||||
defineOptions({
|
||||
name: 'OperLogList'
|
||||
});
|
||||
|
||||
useDict('sys_common_status');
|
||||
useDict('sys_oper_type');
|
||||
|
||||
const appStore = useAppStore();
|
||||
const { download } = useDownload();
|
||||
const { hasAuth } = useAuth();
|
||||
|
||||
const {
|
||||
columns,
|
||||
columnChecks,
|
||||
data,
|
||||
getData,
|
||||
getDataByPage,
|
||||
loading,
|
||||
mobilePagination,
|
||||
searchParams,
|
||||
resetSearchParams
|
||||
} = useTable({
|
||||
apiFn: fetchGetOperLogList,
|
||||
apiParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
// if you want to use the searchParams in Form, you need to define the following properties, and the value is null
|
||||
// the value can not be undefined, otherwise the property in Form will not be reactive
|
||||
title: null,
|
||||
businessType: null,
|
||||
operName: null,
|
||||
operIp: null,
|
||||
status: null,
|
||||
operTime: null
|
||||
},
|
||||
columns: () => [
|
||||
{
|
||||
type: 'selection',
|
||||
align: 'center',
|
||||
width: 48
|
||||
},
|
||||
{
|
||||
key: 'index',
|
||||
title: $t('common.index'),
|
||||
align: 'center',
|
||||
width: 64
|
||||
},
|
||||
{
|
||||
key: 'title',
|
||||
title: '系统模块',
|
||||
align: 'center',
|
||||
minWidth: 120
|
||||
},
|
||||
{
|
||||
key: 'businessType',
|
||||
title: '操作类型',
|
||||
align: 'center',
|
||||
minWidth: 120,
|
||||
render(row) {
|
||||
return <DictTag size="small" value={row.businessType} dictCode="sys_oper_type" />;
|
||||
}
|
||||
},
|
||||
{
|
||||
key: 'operName',
|
||||
title: '操作人员',
|
||||
align: 'center',
|
||||
minWidth: 120
|
||||
},
|
||||
{
|
||||
key: 'operIp',
|
||||
title: '操作IP',
|
||||
align: 'center',
|
||||
minWidth: 120
|
||||
},
|
||||
{
|
||||
key: 'operLocation',
|
||||
title: '操作地点',
|
||||
align: 'center',
|
||||
minWidth: 120
|
||||
},
|
||||
{
|
||||
key: 'status',
|
||||
title: '操作状态',
|
||||
align: 'center',
|
||||
minWidth: 120,
|
||||
render(row) {
|
||||
return <DictTag size="small" value={row.status} dictCode="sys_common_status" />;
|
||||
}
|
||||
},
|
||||
{
|
||||
key: 'operTime',
|
||||
title: '操作时间',
|
||||
align: 'center',
|
||||
minWidth: 120
|
||||
},
|
||||
{
|
||||
key: 'costTime',
|
||||
title: '消耗时间',
|
||||
align: 'center',
|
||||
minWidth: 120,
|
||||
render(row) {
|
||||
return `${row.costTime} ms`;
|
||||
}
|
||||
},
|
||||
{
|
||||
key: 'operate',
|
||||
title: $t('common.operate'),
|
||||
align: 'center',
|
||||
width: 130,
|
||||
render: row => {
|
||||
const viewBtn = () => {
|
||||
return (
|
||||
<NButton type="primary" ghost size="small" onClick={() => view(row.operId!)}>
|
||||
详情
|
||||
</NButton>
|
||||
);
|
||||
};
|
||||
return <div class="flex-center gap-8px">{viewBtn()}</div>;
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
const { drawerVisible, editingData, handleEdit, checkedRowKeys, onBatchDeleted } = useTableOperate(data, getData);
|
||||
|
||||
async function handleBatchDelete() {
|
||||
// request
|
||||
const { error } = await fetchBatchDeleteOperLog(checkedRowKeys.value);
|
||||
if (error) return;
|
||||
onBatchDeleted();
|
||||
}
|
||||
async function view(operId: CommonType.IdType) {
|
||||
handleEdit('operId', operId);
|
||||
}
|
||||
|
||||
async function handleExport() {
|
||||
download('/monitor/operlog/export', searchParams, `操作日志_${new Date().getTime()}.xlsx`);
|
||||
}
|
||||
|
||||
async function handleCleanOperLog() {
|
||||
const { error } = await fetchCleanOperLog();
|
||||
if (error) return;
|
||||
window.$message?.success('清理成功');
|
||||
await getData();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
|
||||
<OperLogSearch v-model:model="searchParams" @reset="resetSearchParams" @search="getDataByPage" />
|
||||
<NCard title="操作日志列表" :bordered="false" size="small" class="sm:flex-1-hidden card-wrapper">
|
||||
<template #header-extra>
|
||||
<NSpace>
|
||||
<NPopconfirm v-if="hasAuth('monitor:operlog:remove')" @positive-click="() => handleCleanOperLog()">
|
||||
<template #trigger>
|
||||
<NButton type="warning" ghost size="small">
|
||||
<template #icon>
|
||||
<icon-ic-round-delete class="text-icon" />
|
||||
</template>
|
||||
清空
|
||||
</NButton>
|
||||
</template>
|
||||
确认清空操作日志?
|
||||
</NPopconfirm>
|
||||
<TableHeaderOperation
|
||||
v-model:columns="columnChecks"
|
||||
:disabled-delete="checkedRowKeys.length === 0"
|
||||
:loading="loading"
|
||||
:show-add="false"
|
||||
:show-delete="hasAuth('monitor:operlog:remove')"
|
||||
:show-export="hasAuth('monitor:operlog:export')"
|
||||
@delete="handleBatchDelete"
|
||||
@export="handleExport"
|
||||
@refresh="getData"
|
||||
/>
|
||||
</NSpace>
|
||||
</template>
|
||||
<NDataTable
|
||||
v-model:checked-row-keys="checkedRowKeys"
|
||||
:columns="columns"
|
||||
:data="data"
|
||||
size="small"
|
||||
:flex-height="!appStore.isMobile"
|
||||
:scroll-x="962"
|
||||
:loading="loading"
|
||||
remote
|
||||
:row-key="row => row.operId"
|
||||
:pagination="mobilePagination"
|
||||
class="sm:h-full"
|
||||
/>
|
||||
<OperLogViewDrawer v-model:visible="drawerVisible" :row-data="editingData" />
|
||||
</NCard>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
88
src/views/monitor/oper-log/modules/oper-log-search.vue
Normal file
88
src/views/monitor/oper-log/modules/oper-log-search.vue
Normal file
@ -0,0 +1,88 @@
|
||||
<script setup lang="ts">
|
||||
import { $t } from '@/locales';
|
||||
import { useNaiveForm } from '@/hooks/common/form';
|
||||
import { useDict } from '@/hooks/business/dict';
|
||||
defineOptions({
|
||||
name: 'OperLogSearch'
|
||||
});
|
||||
|
||||
useDict('sys_oper_type');
|
||||
useDict('sys_common_status');
|
||||
|
||||
interface Emits {
|
||||
(e: 'reset'): void;
|
||||
(e: 'search'): void;
|
||||
}
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const { formRef, validate, restoreValidation } = useNaiveForm();
|
||||
|
||||
const model = defineModel<Api.Monitor.OperLogSearchParams>('model', { required: true });
|
||||
|
||||
async function reset() {
|
||||
await restoreValidation();
|
||||
emit('reset');
|
||||
}
|
||||
|
||||
async function search() {
|
||||
await validate();
|
||||
emit('search');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NCard :bordered="false" size="small" class="card-wrapper">
|
||||
<NCollapse>
|
||||
<NCollapseItem :title="$t('common.search')" name="user-search">
|
||||
<NForm ref="formRef" :model="model" label-placement="left" :label-width="80">
|
||||
<NGrid responsive="screen" item-responsive>
|
||||
<NFormItemGi span="24 s:12 m:6" label="系统模块" path="title" class="pr-24px">
|
||||
<NInput v-model:value="model.title" placeholder="请输入系统模块" />
|
||||
</NFormItemGi>
|
||||
<NFormItemGi span="24 s:12 m:6" label="操作类型" path="businessType" class="pr-24px">
|
||||
<DictSelect
|
||||
v-model:value="model.businessType"
|
||||
placeholder="请选择操作类型"
|
||||
dict-code="sys_oper_type"
|
||||
clearable
|
||||
/>
|
||||
</NFormItemGi>
|
||||
<NFormItemGi span="24 s:12 m:6" label="操作人员" path="operName" class="pr-24px">
|
||||
<NInput v-model:value="model.operName" placeholder="请输入操作人员" />
|
||||
</NFormItemGi>
|
||||
<NFormItemGi span="24 s:12 m:6" label="操作IP" path="operIp" class="pr-24px">
|
||||
<NInput v-model:value="model.operIp" placeholder="请输入操作IP" />
|
||||
</NFormItemGi>
|
||||
<NFormItemGi span="24 s:12 m:6" label="操作状态" path="status" class="pr-24px">
|
||||
<DictSelect
|
||||
v-model:value="model.status"
|
||||
placeholder="请选择操作状态"
|
||||
dict-code="sys_common_status"
|
||||
clearable
|
||||
/>
|
||||
</NFormItemGi>
|
||||
<NFormItemGi span="24" class="pr-24px">
|
||||
<NSpace class="w-full" justify="end">
|
||||
<NButton @click="reset">
|
||||
<template #icon>
|
||||
<icon-ic-round-refresh class="text-icon" />
|
||||
</template>
|
||||
{{ $t('common.reset') }}
|
||||
</NButton>
|
||||
<NButton type="primary" ghost @click="search">
|
||||
<template #icon>
|
||||
<icon-ic-round-search class="text-icon" />
|
||||
</template>
|
||||
{{ $t('common.search') }}
|
||||
</NButton>
|
||||
</NSpace>
|
||||
</NFormItemGi>
|
||||
</NGrid>
|
||||
</NForm>
|
||||
</NCollapseItem>
|
||||
</NCollapse>
|
||||
</NCard>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
71
src/views/monitor/oper-log/modules/oper-log-view-drawer.vue
Normal file
71
src/views/monitor/oper-log/modules/oper-log-view-drawer.vue
Normal file
@ -0,0 +1,71 @@
|
||||
<script setup lang="tsx">
|
||||
import { NDescriptions, NDescriptionsItem, NTag } from 'naive-ui';
|
||||
import { $t } from '@/locales';
|
||||
import DictTag from '@/components/custom/dict-tag.vue';
|
||||
import { getRequestMethodTagType } from '@/utils/format';
|
||||
defineOptions({
|
||||
name: 'OperLogViewDrawer'
|
||||
});
|
||||
|
||||
interface Props {
|
||||
/** the edit row data */
|
||||
rowData: Api.Monitor.OperLog | null;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const visible = defineModel<boolean>('visible', {
|
||||
default: false
|
||||
});
|
||||
const title = '操作日志详情';
|
||||
|
||||
function closeDrawer() {
|
||||
visible.value = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NDrawer v-model:show="visible" :title="title" display-directive="show" :width="800" class="max-w-90%">
|
||||
<NDrawerContent :title="title" :native-scrollbar="false" closable>
|
||||
<NDescriptions label-class="min-w-100px" :column="1" size="small" bordered label-placement="left">
|
||||
<NDescriptionsItem label="日志编号">{{ props.rowData?.operId }}</NDescriptionsItem>
|
||||
<NDescriptionsItem label="操作状态">
|
||||
<DictTag size="small" :value="props.rowData?.status" dict-code="sys_common_status" />
|
||||
</NDescriptionsItem>
|
||||
<NDescriptionsItem label="系统模块">
|
||||
<NSpace>
|
||||
<NTag size="small" type="primary">{{ props.rowData?.title }}模块</NTag>
|
||||
<DictTag size="small" :value="props.rowData?.businessType" dict-code="sys_oper_type" />
|
||||
</NSpace>
|
||||
</NDescriptionsItem>
|
||||
<NDescriptionsItem label="操作信息">
|
||||
{{ props.rowData?.operName }} | {{ props.rowData?.deptName }} | {{ props.rowData?.operIp }} |
|
||||
{{ props.rowData?.operLocation }}
|
||||
</NDescriptionsItem>
|
||||
<NDescriptionsItem label="请求信息">
|
||||
<NSpace>
|
||||
<NTag size="small" :type="getRequestMethodTagType(props.rowData?.requestMethod ?? '')">
|
||||
{{ `${props.rowData?.requestMethod?.toUpperCase()}请求` }}
|
||||
</NTag>
|
||||
{{ props.rowData?.operUrl }}
|
||||
</NSpace>
|
||||
</NDescriptionsItem>
|
||||
<NDescriptionsItem label="操作时间">{{ props.rowData?.operTime }}</NDescriptionsItem>
|
||||
<NDescriptionsItem label="请求参数">
|
||||
<JsonPreview :data="props.rowData?.operParam" />
|
||||
</NDescriptionsItem>
|
||||
<NDescriptionsItem label="返回参数">
|
||||
<JsonPreview :data="props.rowData?.jsonResult" />
|
||||
</NDescriptionsItem>
|
||||
<NDescriptionsItem label="消耗时间">
|
||||
{{ `${props.rowData?.costTime} ms` }}
|
||||
</NDescriptionsItem>
|
||||
<NDescriptionsItem label="错误消息">{{ props.rowData?.errorMsg }}</NDescriptionsItem>
|
||||
</NDescriptions>
|
||||
<template #footer>
|
||||
<NSpace :size="16">
|
||||
<NButton @click="closeDrawer">{{ $t('common.close') }}</NButton>
|
||||
</NSpace>
|
||||
</template>
|
||||
</NDrawerContent>
|
||||
</NDrawer>
|
||||
</template>
|
Reference in New Issue
Block a user