【重构】V2 操作日志转正,基于注解的可使用变量、可以自定义函数的通用操作日志组件

This commit is contained in:
YunaiV 2024-04-04 01:21:27 +08:00
parent 757281ce34
commit c01571d11d
12 changed files with 93 additions and 137 deletions

View File

@ -2,30 +2,6 @@ import request from '@/config/axios'
export type OperateLogVO = { export type OperateLogVO = {
id: number id: number
userNickname: string
traceId: string
userId: number
module: string
name: string
type: number
content: string
exts: Map<String, Object>
requestMethod: string
requestUrl: string
userIp: string
userAgent: string
javaMethod: string
javaMethodArgs: string
startTime: Date
duration: number
resultCode: number
resultMsg: string
resultData: string
}
export type OperateLogV2VO = {
id: number
userNickname: string
traceId: string traceId: string
userType: number userType: number
userId: number userId: number
@ -42,11 +18,6 @@ export type OperateLogV2VO = {
creator: string creator: string
creatorName: string creatorName: string
createTime: Date createTime: Date
// 数据扩展,渲染时使用
title: string // 操作标题(如果为空则取 name 值)
colSize: number // 变更记录行数
contentStrList: string[]
tagsContentList: string[]
} }
// 查询操作日志列表 // 查询操作日志列表
@ -54,6 +25,6 @@ export const getOperateLogPage = (params: PageParam) => {
return request.get({ url: '/system/operate-log/page', params }) return request.get({ url: '/system/operate-log/page', params })
} }
// 导出操作日志 // 导出操作日志
export const exportOperateLog = (params) => { export const exportOperateLog = (params: any) => {
return request.download({ url: '/system/operate-log/export', params }) return request.download({ url: '/system/operate-log/export', params })
} }

View File

@ -23,7 +23,7 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { OperateLogV2VO } from '@/api/system/operatelog' import { OperateLogVO } from '@/api/system/operatelog'
import { formatDate } from '@/utils/formatTime' import { formatDate } from '@/utils/formatTime'
import { DICT_TYPE, getDictLabel, getDictObj } from '@/utils/dict' import { DICT_TYPE, getDictLabel, getDictObj } from '@/utils/dict'
import { ElTag } from 'element-plus' import { ElTag } from 'element-plus'
@ -31,7 +31,7 @@ import { ElTag } from 'element-plus'
defineOptions({ name: 'OperateLogV2' }) defineOptions({ name: 'OperateLogV2' })
interface Props { interface Props {
logList: OperateLogV2VO[] // logList: OperateLogVO[] //
} }
withDefaults(defineProps<Props>(), { withDefaults(defineProps<Props>(), {

View File

@ -64,7 +64,7 @@ import BusinessDetailsHeader from './BusinessDetailsHeader.vue'
import BusinessDetailsInfo from './BusinessDetailsInfo.vue' import BusinessDetailsInfo from './BusinessDetailsInfo.vue'
import PermissionList from '@/views/crm/permission/components/PermissionList.vue' // import PermissionList from '@/views/crm/permission/components/PermissionList.vue' //
import { BizTypeEnum } from '@/api/crm/permission' import { BizTypeEnum } from '@/api/crm/permission'
import { OperateLogV2VO } from '@/api/system/operatelog' import { OperateLogVO } from '@/api/system/operatelog'
import { getOperateLogPage } from '@/api/crm/operateLog' import { getOperateLogPage } from '@/api/crm/operateLog'
import BusinessForm from '@/views/crm/business/BusinessForm.vue' import BusinessForm from '@/views/crm/business/BusinessForm.vue'
import CrmTransferForm from '@/views/crm/permission/components/TransferForm.vue' import CrmTransferForm from '@/views/crm/permission/components/TransferForm.vue'
@ -113,7 +113,7 @@ const transfer = () => {
} }
/** 获取操作日志 */ /** 获取操作日志 */
const logList = ref<OperateLogV2VO[]>([]) // const logList = ref<OperateLogVO[]>([]) //
const getOperateLog = async (contactId: number) => { const getOperateLog = async (contactId: number) => {
if (!contactId) { if (!contactId) {
return return

View File

@ -57,7 +57,7 @@ import PermissionList from '@/views/crm/permission/components/PermissionList.vue
import CrmTransferForm from '@/views/crm/permission/components/TransferForm.vue' import CrmTransferForm from '@/views/crm/permission/components/TransferForm.vue'
import FollowUpList from '@/views/crm/followup/index.vue' import FollowUpList from '@/views/crm/followup/index.vue'
import { BizTypeEnum } from '@/api/crm/permission' import { BizTypeEnum } from '@/api/crm/permission'
import type { OperateLogV2VO } from '@/api/system/operatelog' import type { OperateLogVO } from '@/api/system/operatelog'
import { getOperateLogPage } from '@/api/crm/operateLog' import { getOperateLogPage } from '@/api/crm/operateLog'
defineOptions({ name: 'CrmClueDetail' }) defineOptions({ name: 'CrmClueDetail' })
@ -103,7 +103,7 @@ const handleTransform = async () => {
} }
/** 获取操作日志 */ /** 获取操作日志 */
const logList = ref<OperateLogV2VO[]>([]) // const logList = ref<OperateLogVO[]>([]) //
const getOperateLog = async () => { const getOperateLog = async () => {
const data = await getOperateLogPage({ const data = await getOperateLogPage({
bizType: BizTypeEnum.CRM_CLUE, bizType: BizTypeEnum.CRM_CLUE,

View File

@ -49,7 +49,7 @@ import ContactDetailsInfo from '@/views/crm/contact/detail/ContactDetailsInfo.vu
import BusinessList from '@/views/crm/business/components/BusinessList.vue' // import BusinessList from '@/views/crm/business/components/BusinessList.vue' //
import PermissionList from '@/views/crm/permission/components/PermissionList.vue' // import PermissionList from '@/views/crm/permission/components/PermissionList.vue' //
import { BizTypeEnum } from '@/api/crm/permission' import { BizTypeEnum } from '@/api/crm/permission'
import { OperateLogV2VO } from '@/api/system/operatelog' import { OperateLogVO } from '@/api/system/operatelog'
import { getOperateLogPage } from '@/api/crm/operateLog' import { getOperateLogPage } from '@/api/crm/operateLog'
import ContactForm from '@/views/crm/contact/ContactForm.vue' import ContactForm from '@/views/crm/contact/ContactForm.vue'
import CrmTransferForm from '@/views/crm/permission/components/TransferForm.vue' import CrmTransferForm from '@/views/crm/permission/components/TransferForm.vue'
@ -88,7 +88,7 @@ const transfer = () => {
} }
/** 获取操作日志 */ /** 获取操作日志 */
const logList = ref<OperateLogV2VO[]>([]) // const logList = ref<OperateLogVO[]>([]) //
const getOperateLog = async (contactId: number) => { const getOperateLog = async (contactId: number) => {
if (!contactId) { if (!contactId) {
return return

View File

@ -52,7 +52,7 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { useTagsViewStore } from '@/store/modules/tagsView' import { useTagsViewStore } from '@/store/modules/tagsView'
import { OperateLogV2VO } from '@/api/system/operatelog' import { OperateLogVO } from '@/api/system/operatelog'
import * as ContractApi from '@/api/crm/contract' import * as ContractApi from '@/api/crm/contract'
import ContractDetailsInfo from './ContractDetailsInfo.vue' import ContractDetailsInfo from './ContractDetailsInfo.vue'
import ContractDetailsHeader from './ContractDetailsHeader.vue' import ContractDetailsHeader from './ContractDetailsHeader.vue'
@ -94,7 +94,7 @@ const getContractData = async () => {
} }
/** 获取操作日志 */ /** 获取操作日志 */
const logList = ref<OperateLogV2VO[]>([]) // const logList = ref<OperateLogVO[]>([]) //
const getOperateLog = async (contractId: number) => { const getOperateLog = async (contractId: number) => {
if (!contractId) { if (!contractId) {
return return

View File

@ -93,7 +93,7 @@ import PermissionList from '@/views/crm/permission/components/PermissionList.vue
import CrmTransferForm from '@/views/crm/permission/components/TransferForm.vue' import CrmTransferForm from '@/views/crm/permission/components/TransferForm.vue'
import FollowUpList from '@/views/crm/followup/index.vue' import FollowUpList from '@/views/crm/followup/index.vue'
import { BizTypeEnum } from '@/api/crm/permission' import { BizTypeEnum } from '@/api/crm/permission'
import type { OperateLogV2VO } from '@/api/system/operatelog' import type { OperateLogVO } from '@/api/system/operatelog'
import { getOperateLogPage } from '@/api/crm/operateLog' import { getOperateLogPage } from '@/api/crm/operateLog'
import CustomerDistributeForm from '@/views/crm/customer/pool/CustomerDistributeForm.vue' import CustomerDistributeForm from '@/views/crm/customer/pool/CustomerDistributeForm.vue'
@ -185,7 +185,7 @@ const handlePutPool = async () => {
} }
/** 获取操作日志 */ /** 获取操作日志 */
const logList = ref<OperateLogV2VO[]>([]) // const logList = ref<OperateLogVO[]>([]) //
const getOperateLog = async () => { const getOperateLog = async () => {
if (!customerId.value) { if (!customerId.value) {
return return

View File

@ -13,7 +13,7 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { useTagsViewStore } from '@/store/modules/tagsView' import { useTagsViewStore } from '@/store/modules/tagsView'
import { OperateLogV2VO } from '@/api/system/operatelog' import { OperateLogVO } from '@/api/system/operatelog'
import * as ProductApi from '@/api/crm/product' import * as ProductApi from '@/api/crm/product'
import ProductDetailsHeader from '@/views/crm/product/detail/ProductDetailsHeader.vue' import ProductDetailsHeader from '@/views/crm/product/detail/ProductDetailsHeader.vue'
import ProductDetailsInfo from '@/views/crm/product/detail/ProductDetailsInfo.vue' import ProductDetailsInfo from '@/views/crm/product/detail/ProductDetailsInfo.vue'
@ -40,7 +40,7 @@ const getProductData = async (id: number) => {
} }
/** 获取操作日志 */ /** 获取操作日志 */
const logList = ref<OperateLogV2VO[]>([]) // const logList = ref<OperateLogVO[]>([]) //
const getOperateLog = async (productId: number) => { const getOperateLog = async (productId: number) => {
if (!productId) { if (!productId) {
return return

View File

@ -34,7 +34,7 @@ import ReceivableDetailsHeader from './ReceivableDetailsHeader.vue'
import ReceivableDetailsInfo from './ReceivableDetailsInfo.vue' import ReceivableDetailsInfo from './ReceivableDetailsInfo.vue'
import PermissionList from '@/views/crm/permission/components/PermissionList.vue' // import PermissionList from '@/views/crm/permission/components/PermissionList.vue' //
import { BizTypeEnum } from '@/api/crm/permission' import { BizTypeEnum } from '@/api/crm/permission'
import { OperateLogV2VO } from '@/api/system/operatelog' import { OperateLogVO } from '@/api/system/operatelog'
import { getOperateLogPage } from '@/api/crm/operateLog' import { getOperateLogPage } from '@/api/crm/operateLog'
import ReceivableForm from '@/views/crm/receivable/ReceivableForm.vue' import ReceivableForm from '@/views/crm/receivable/ReceivableForm.vue'
@ -66,7 +66,7 @@ const openForm = (type: string, id?: number) => {
} }
/** 获取操作日志 */ /** 获取操作日志 */
const logList = ref<OperateLogV2VO[]>([]) // const logList = ref<OperateLogVO[]>([]) //
const getOperateLog = async (receivableId: number) => { const getOperateLog = async (receivableId: number) => {
if (!receivableId) { if (!receivableId) {
return return

View File

@ -37,7 +37,7 @@ import ReceivablePlanDetailsHeader from './ReceivablePlanDetailsHeader.vue'
import ReceivablePlanDetailsInfo from './ReceivablePlanDetailsInfo.vue' import ReceivablePlanDetailsInfo from './ReceivablePlanDetailsInfo.vue'
import PermissionList from '@/views/crm/permission/components/PermissionList.vue' // import PermissionList from '@/views/crm/permission/components/PermissionList.vue' //
import { BizTypeEnum } from '@/api/crm/permission' import { BizTypeEnum } from '@/api/crm/permission'
import { OperateLogV2VO } from '@/api/system/operatelog' import { OperateLogVO } from '@/api/system/operatelog'
import { getOperateLogPage } from '@/api/crm/operateLog' import { getOperateLogPage } from '@/api/crm/operateLog'
import ReceivablePlanForm from '@/views/crm/receivable/plan/ReceivablePlanForm.vue' import ReceivablePlanForm from '@/views/crm/receivable/plan/ReceivablePlanForm.vue'
@ -70,7 +70,7 @@ const openForm = (type: string, id?: number) => {
} }
/** 获取操作日志 */ /** 获取操作日志 */
const logList = ref<OperateLogV2VO[]>([]) // const logList = ref<OperateLogVO[]>([]) //
const getOperateLog = async (receivablePlanId: number) => { const getOperateLog = async (receivablePlanId: number) => {
if (!receivablePlanId) { if (!receivablePlanId) {
return return

View File

@ -4,14 +4,14 @@
<el-descriptions-item label="日志主键" min-width="120"> <el-descriptions-item label="日志主键" min-width="120">
{{ detailData.id }} {{ detailData.id }}
</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="链路追踪"> <el-descriptions-item label="链路追踪" v-if="detailData.traceId">
{{ detailData.traceId }} {{ detailData.traceId }}
</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="操作人编号"> <el-descriptions-item label="操作人编号">
{{ detailData.userId }} {{ detailData.userId }}
</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="操作人名字"> <el-descriptions-item label="操作人名字">
{{ detailData.userNickname }} {{ detailData.userName }}
</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="操作人 IP"> <el-descriptions-item label="操作人 IP">
{{ detailData.userIp }} {{ detailData.userIp }}
@ -20,39 +20,25 @@
{{ detailData.userAgent }} {{ detailData.userAgent }}
</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="操作模块"> <el-descriptions-item label="操作模块">
{{ detailData.module }} {{ detailData.type }}
</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="操作名"> <el-descriptions-item label="操作名">
{{ detailData.name }} {{ detailData.subType }}
</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item v-if="detailData.content" label="操作内容"> <el-descriptions-item label="操作内容">
{{ detailData.content }} {{ detailData.action }}
</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item v-if="detailData.exts" label="操作拓展参数"> <el-descriptions-item v-if="detailData.extra" label="操作拓展参数">
{{ detailData.exts }} {{ detailData.extra }}
</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="请求 URL"> <el-descriptions-item label="请求 URL">
{{ detailData.requestMethod }} {{ detailData.requestUrl }} {{ detailData.requestMethod }} {{ detailData.requestUrl }}
</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="Java 方法名">
{{ detailData.javaMethod }}
</el-descriptions-item>
<el-descriptions-item label="Java 方法参数">
{{ detailData.javaMethodArgs }}
</el-descriptions-item>
<el-descriptions-item label="操作时间"> <el-descriptions-item label="操作时间">
{{ formatDate(detailData.startTime) }} {{ formatDate(detailData.createTime) }}
</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="执行时长">{{ detailData.duration }} ms</el-descriptions-item> <el-descriptions-item label="业务编号">
<el-descriptions-item label="操作结果"> {{ detailData.bizId }}
<div v-if="detailData.resultCode === 0">正常</div>
<div v-else>失败({{ detailData.resultCode }})</div>
</el-descriptions-item>
<el-descriptions-item v-if="detailData.resultCode === 0" label="操作结果">
{{ detailData.resultData }}
</el-descriptions-item>
<el-descriptions-item v-if="detailData.resultCode > 0" label="失败提示">
{{ detailData.resultMsg }}
</el-descriptions-item> </el-descriptions-item>
</el-descriptions> </el-descriptions>
</Dialog> </Dialog>

View File

@ -10,58 +10,65 @@
:inline="true" :inline="true"
label-width="68px" label-width="68px"
> >
<el-form-item label="系统模块" prop="module"> <el-form-item label="操作人" prop="userId">
<el-input
v-model="queryParams.module"
placeholder="请输入系统模块"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="操作人员" prop="userNickname">
<el-input
v-model="queryParams.userNickname"
placeholder="请输入操作人员"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="操作类型" prop="type">
<el-select <el-select
v-model="queryParams.type" v-model="queryParams.userId"
placeholder="请选择操作类型" multiple
clearable placeholder="请输入操作人员"
class="!w-240px" class="!w-240px"
> >
<el-option <el-option
v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_OPERATE_TYPE)" v-for="user in userList"
:key="dict.value" :key="user.id"
:label="dict.label" :label="user.nickname"
:value="dict.value" :value="user.id"
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="操作状态" prop="success"> <el-form-item label="操作模块" prop="type">
<el-select <el-input
v-model="queryParams.success" v-model="queryParams.type"
placeholder="请选择操作状态" placeholder="请输入操作模块"
clearable clearable
@keyup.enter="handleQuery"
class="!w-240px" class="!w-240px"
> />
<el-option key="true" label="成功" :value="true" />
<el-option key="false" label="失败" :value="false" />
</el-select>
</el-form-item> </el-form-item>
<el-form-item label="操作时间" prop="startTime"> <el-form-item label="操作模块" prop="subType">
<el-input
v-model="queryParams.subType"
placeholder="请输入操作模块"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="操作内容" prop="action">
<el-input
v-model="queryParams.action"
placeholder="请输入操作名"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="操作时间" prop="createTime">
<el-date-picker <el-date-picker
v-model="queryParams.startTime" v-model="queryParams.createTime"
value-format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss"
type="daterange" type="daterange"
start-placeholder="开始日期" start-placeholder="开始日期"
end-placeholder="结束日期" end-placeholder="结束日期"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
class="!w-220px"
/>
</el-form-item>
<el-form-item label="业务编号" prop="bizId">
<el-input
v-model="queryParams.bizId"
placeholder="请输入业务编号"
clearable
@keyup.enter="handleQuery"
class="!w-240px" class="!w-240px"
/> />
</el-form-item> </el-form-item>
@ -84,33 +91,21 @@
<!-- 列表 --> <!-- 列表 -->
<ContentWrap> <ContentWrap>
<el-table v-loading="loading" :data="list"> <el-table v-loading="loading" :data="list">
<el-table-column label="日志编号" align="center" prop="id" /> <el-table-column label="日志编号" align="center" prop="id" width="100" />
<el-table-column label="操作模块" align="center" prop="module" width="180" /> <el-table-column label="操作人" align="center" prop="userName" width="120" />
<el-table-column label="操作名" align="center" prop="name" width="180" /> <el-table-column label="操作模块" align="center" prop="type" width="120" />
<el-table-column label="操作类型" align="center" prop="type"> <el-table-column label="操作名" align="center" prop="subType" width="160" />
<template #default="scope"> <el-table-column label="操作内容" align="center" prop="action" />
<dict-tag :type="DICT_TYPE.SYSTEM_OPERATE_TYPE" :value="scope.row.type" />
</template>
</el-table-column>
<el-table-column label="操作人" align="center" prop="userNickname" />
<el-table-column label="操作结果" align="center" prop="status">
<template #default="scope">
<span>{{ scope.row.resultCode === 0 ? '成功' : '失败' }}</span>
</template>
</el-table-column>
<el-table-column <el-table-column
label="操作时间" label="操作时间"
align="center" align="center"
prop="startTime" prop="createTime"
width="180" width="180"
:formatter="dateFormatter" :formatter="dateFormatter"
/> />
<el-table-column label="执行时长" align="center" prop="startTime"> <el-table-column label="业务编号" align="center" prop="bizId" width="120" />
<template #default="scope"> <el-table-column label="IP" align="center" prop="userIp" width="120" />
<span>{{ scope.row.duration }} ms</span> <el-table-column label="操作" align="center" fixed="right" width="60">
</template>
</el-table-column>
<el-table-column label="操作" align="center">
<template #default="scope"> <template #default="scope">
<el-button <el-button
link link
@ -136,11 +131,12 @@
<OperateLogDetail ref="detailRef" /> <OperateLogDetail ref="detailRef" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime' import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download' import download from '@/utils/download'
import * as OperateLogApi from '@/api/system/operatelog' import * as OperateLogApi from '@/api/system/operatelog'
import OperateLogDetail from './OperateLogDetail.vue' import OperateLogDetail from './OperateLogDetail.vue'
import * as UserApi from '@/api/system/user'
const userList = ref<UserApi.UserVO[]>([]) //
defineOptions({ name: 'SystemOperateLog' }) defineOptions({ name: 'SystemOperateLog' })
@ -152,11 +148,12 @@ const list = ref([]) // 列表的数据
const queryParams = reactive({ const queryParams = reactive({
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
module: undefined, userId: undefined,
userNickname: undefined,
type: undefined, type: undefined,
success: undefined, subType: undefined,
startTime: [] action: undefined,
createTime: [],
bizId: undefined
}) })
const queryFormRef = ref() // const queryFormRef = ref() //
const exportLoading = ref(false) // const exportLoading = ref(false) //
@ -207,7 +204,9 @@ const handleExport = async () => {
} }
/** 初始化 **/ /** 初始化 **/
onMounted(() => { onMounted(async () => {
getList() await getList()
//
userList.value = await UserApi.getSimpleUserList()
}) })
</script> </script>