fix: 🐛 操作日志不显示userName (#141)

[skip ci]

Co-authored-by: tk <fiyne1a@dingtalk.com>
This commit is contained in:
2024-06-12 21:47:08 +08:00
committed by GitHub
parent a3ab97019d
commit 705d027da4
19 changed files with 216 additions and 222 deletions

View File

@ -130,11 +130,14 @@ export default {
<style scoped>
.sc-select-filter {
width: 100%;
display: flex;
flex-wrap: wrap;
}
.sc-select-filter__item {
display: flex;
align-items: baseline;
width: 50%;
}
.sc-select-filter__item-title {

View File

@ -15,7 +15,7 @@
<el-icon-full-screen />
</el-icon>
</div>
<div @click="tasks" class="tasks panel-item">
<div v-auth="'sys/job/userbar'" @click="tasks" class="tasks panel-item">
<el-icon>
<sc-icon-ScheduledJob />
</el-icon>

View File

@ -47,6 +47,9 @@ export default {
global.enums = preloads[2]?.data
global.numbers = preloads[3]?.data
global.chars = preloads[4]?.data
global.permissions = tool.recursiveFindProperty(preloads[0]?.data, 'type', 'button').map((x) => x.tag)
global.permissions =
global.user?.roles.findIndex((x) => x.ignorePermissionControl) >= 0
? ['*/*/*']
: tool.recursiveFindProperty(preloads[0]?.data, 'type', 'button').map((x) => x.tag)
},
}

View File

@ -23,21 +23,9 @@
:controls="[
{
type: 'input',
field: ['dy', 'id'],
placeholder: '日志编号',
style: 'width:15rem',
},
{
type: 'input',
field: ['dy', 'extraData'],
placeholder: '登录名',
style: 'width:15rem',
},
{
type: 'input',
field: ['dy', 'createdClientIp'],
placeholder: '客户端IP',
style: 'width:15rem',
field: ['root', 'keywords'],
placeholder: '日志编号 / 登录名 / 客户端IP',
style: 'width:25rem',
},
]"
:vue="this"
@ -54,7 +42,7 @@
<sc-table
v-loading="loading"
:apiObj="$API.sys_log.pagedQuery"
:context-menus="['id', 'httpStatusCode', 'extraData', 'createdClientIp', 'os', 'createdUserAgent', 'createdTime']"
:context-menus="['id', 'httpStatusCode', 'createdClientIp', 'createdUserAgent', 'createdTime']"
:context-opers="['view']"
:default-sort="{ prop: 'createdTime', order: 'descending' }"
:params="query"
@ -73,13 +61,13 @@
{{ scope.row.httpStatusCode === 200 ? '成功' : '失败' }}
</template>
</el-table-column>
<el-table-column :label="$t('登录名')" prop="extraData" sortable="custom" width="200" />
<el-table-column :label="$t('客户端IP')" prop="createdClientIp" sortable="custom" width="200">
<el-table-column :label="$t('登录名')" prop="loginName" width="150" />
<el-table-column :label="$t('客户端IP')" prop="createdClientIp" show-overflow-tooltip sortable="custom" width="200">
<template #default="scope">
<na-ip :ip="scope.row.createdClientIp"></na-ip>
</template>
</el-table-column>
<el-table-column :label="$t('操作系统')" prop="os" width="150" />
<el-table-column :label="$t('操作系统')" align="center" prop="os" width="150" />
<el-table-column :label="$t('用户代理')" prop="createdUserAgent" show-overflow-tooltip sortable="custom" />
</sc-table>
</el-main>
@ -120,7 +108,11 @@ export default {
},
}
},
mounted() {
async mounted() {
if (this.keywords) {
this.$refs.search.form.root.keywords = this.keywords
this.$refs.search.keepKeywords = this.keywords
}
this.$refs.search.form.dy.apiId = 'api/sys/user/login.by.pwd'
this.$refs.search.form.dy.createdTime = this.$refs.search.keepCreatedTime = [
`${tool.dateFormat(new Date(), 'yyyy-MM-dd')} 00:00:00`,
@ -128,6 +120,9 @@ export default {
]
},
created() {
if (this.keywords) {
this.query.keywords = this.keywords
}
this.query.dynamicFilter.filters.push({
field: 'apiId',
operator: 'eq',
@ -157,41 +152,6 @@ export default {
value: form.dy.createdTime.map((x) => x.replace(/ 00:00:00$/, '')),
})
}
if (form.dy.httpStatusCode) {
this.query.dynamicFilter.filters.push({
field: 'httpStatusCode',
operator: 'range',
value: form.dy.httpStatusCode,
})
}
if (form.dy.apiId) {
this.query.dynamicFilter.filters.push({
field: 'apiId',
operator: 'contains',
value: form.dy.apiId,
})
}
if (form.dy.id) {
this.query.dynamicFilter.filters.push({
field: 'id',
operator: 'eq',
value: form.dy.id,
})
}
if (form.dy.extraData) {
this.query.dynamicFilter.filters.push({
field: 'extraData',
operator: 'contains',
value: form.dy.extraData,
})
}
if (form.dy.createdClientIp) {
this.query.dynamicFilter.filters.push({
field: 'createdClientIp',
operator: 'contains',
value: form.dy.createdClientIp,
})
}
if (typeof form.dy.loginResult === 'boolean') {
this.query.dynamicFilter.filters.push(
form.dy.loginResult
@ -207,7 +167,6 @@ export default {
},
)
}
this.$refs.table.upData()
},

View File

@ -1,15 +1,26 @@
<template>
<el-container>
<el-header style="height: auto; padding: 0 1rem">
<sc-select-filter
:data="[
{
title: $t('操作结果'),
key: 'operationResult',
options: [
{ label: $t('全部'), value: '' },
{ label: $t('成功'), value: true },
{ label: $t('失败'), value: false },
],
},
]"
:label-width="6"
@on-change="filterChange"
ref="selectFilter"></sc-select-filter>
</el-header>
<el-header>
<div class="left-panel">
<na-search
:controls="[
{
type: 'input',
field: ['filter', 'id'],
placeholder: '日志编号',
style: 'width:12rem',
},
{
multiple: true,
type: 'select',
@ -34,18 +45,13 @@
},
{
type: 'input',
field: ['dy', 'createdUserName'],
placeholder: '用户名',
style: 'width:12rem',
},
{
type: 'input',
field: ['dy', 'createdClientIp'],
placeholder: '客户端IP',
style: 'width:12rem',
field: ['root', 'keywords'],
placeholder: '日志编号 / 用户 / 客户端IP',
style: 'width:25rem',
},
]"
:vue="this"
@reset="Object.entries(this.$refs.selectFilter.selected).forEach(([key, _]) => (this.$refs.selectFilter.selected[key] = ['']))"
@search="onSearch"
dateFormat="YYYY-MM-DD HH:mm:ss"
dateType="datetimerange"
@ -57,19 +63,18 @@
<el-main class="nopadding">
<sc-table
:apiObj="$API.sys_log.pagedQuery"
:context-menus="['id', 'httpStatusCode', 'apiId', 'createdUserName', 'method', 'duration', 'createdClientIp', 'os', 'createdTime']"
:context-menus="['id', 'httpStatusCode', 'apiId', 'userId', 'method', 'duration', 'createdClientIp', 'createdTime']"
:context-opers="[]"
:default-sort="{ prop: 'createdTime', order: 'descending' }"
:params="query"
:vue="this"
@row-click="rowClick"
ref="table"
remoteFilter
remoteSort
remote-filter
remote-sort
row-key="id"
stripe>
<el-table-column :label="$t('日志编号')" prop="id" sortable="custom" width="150"> </el-table-column
><el-table-column :label="$t('创建时间')" prop="createdTime" sortable="custom" width="170" />
<el-table-column :label="$t('日志编号')" prop="id" sortable="custom" width="150" />
<el-table-column :label="$t('创建时间')" prop="createdTime" sortable="custom" width="170" />
<el-table-column :label="$t('响应码')" align="center" prop="httpStatusCode" sortable="custom" width="100">
<template #default="{ row }">
<sc-status-indicator :type="row.httpStatusCode >= 200 && row.httpStatusCode < 300 ? 'success' : 'danger'" />
@ -96,20 +101,33 @@
align="right"
prop="duration"
sortable="custom"
width="120">
width="90">
</el-table-column>
</el-table-column>
<el-table-column :label="$t('用户名')" prop="createdUserName" sortable="custom" width="150">
<template #default="scope">
{{ scope.row.apiId === 'api/sys/user/pwd.login' ? scope.row.extraData : scope.row.createdUserName }}
</template>
</el-table-column>
<na-col-user
v-auth="'sys/log/operation/user'"
header-align="center"
label="用户"
nestProp="user.userName"
nestProp2="user.id"
prop="userId"
sortable="custom"
width="170"></na-col-user>
<el-table-column :label="$t('客户端IP')" prop="createdClientIp" show-overflow-tooltip sortable="custom" width="200">
<template #default="scope">
<na-ip :ip="scope.row.createdClientIp"></na-ip>
</template>
</el-table-column>
<el-table-column :label="$t('操作系统')" align="center" prop="os" width="150" />
<na-col-operation
:buttons="[
{
icon: 'el-icon-view',
click: rowClick,
},
]"
:vue="this"
width="70" />
</sc-table>
</el-main>
</el-container>
@ -124,7 +142,6 @@ import ScTable from '@/components/scTable/index.vue'
import ScStatusIndicator from '@/components/scMini/scStatusIndicator.vue'
export default {
inject: ['reload'],
computed: {
tool() {
return tool
@ -136,6 +153,7 @@ export default {
naInfo,
},
watch: {},
inject: ['reload'],
data() {
return {
query: {
@ -155,13 +173,28 @@ export default {
},
}
},
mounted() {
async mounted() {
if (this.keywords) {
this.$refs.search.form.root.keywords = this.keywords
this.$refs.search.keepKeywords = this.keywords
}
this.$refs.search.form.dy.createdTime = this.$refs.search.keepCreatedTime = [
`${tool.dateFormat(new Date(), 'yyyy-MM-dd')} 00:00:00`,
`${tool.dateFormat(new Date(), 'yyyy-MM-dd')} 00:00:00`,
]
},
created() {
if (this.keywords) {
this.query.keywords = this.keywords
}
},
methods: {
filterChange(data) {
Object.entries(data).forEach(([key, value]) => {
this.$refs.search.form.dy[key] = value === 'true' ? true : value === 'false' ? false : value
})
this.$refs.search.search()
},
//搜索
onSearch(form) {
if (Array.isArray(form.dy.createdTime)) {
@ -186,19 +219,20 @@ export default {
value: form.dy.apiId,
})
}
if (typeof form.dy.createdUserName === 'string' && form.dy.createdUserName.trim() !== '') {
this.query.dynamicFilter.filters.push({
field: 'createdUserName',
operator: 'eq',
value: form.dy.createdUserName,
})
}
if (typeof form.dy.createdClientIp === 'string' && form.dy.createdClientIp.trim() !== '') {
this.query.dynamicFilter.filters.push({
field: 'createdClientIp',
operator: 'eq',
value: form.dy.createdClientIp,
})
if (typeof form.dy.operationResult === 'boolean') {
this.query.dynamicFilter.filters.push(
form.dy.operationResult
? {
field: 'httpStatusCode',
operator: 'range',
value: '200,299',
}
: {
field: 'httpStatusCode',
operator: 'range',
value: '300,999',
},
)
}
this.$refs.table.upData()
},