🔨 优化代码逻辑.

This commit is contained in:
lijiahangmax
2025-06-29 20:00:15 +08:00
parent 5b611f20c2
commit e1325b3128
20 changed files with 129 additions and 129 deletions

View File

@@ -0,0 +1,70 @@
import type { DataGrid, OrderDirection, Pagination } from '@/types/global';
import type { TableData } from '@arco-design/web-vue';
import axios from 'axios';
import qs from 'query-string';
/**
* 终端文件操作日志 查询请求
*/
export interface TerminalFileLogQueryRequest extends Pagination, OrderDirection {
userId?: number;
hostId?: number;
type?: string;
result?: number;
startTimeRange?: string[];
}
/**
* 终端文件操作日志 查询响应
*/
export interface TerminalFileLogQueryResponse extends TableData {
id: number;
userId: number;
username: number;
hostId: number;
hostName: string;
hostAddress: string;
address: string;
location: string;
userAgent: string;
paths: string[];
type: string;
result: string;
startTime: number;
extra: TerminalFileLogExtra;
}
/**
* 终端文件操作日志 拓展对象
*/
export interface TerminalFileLogExtra {
mod: number;
target: string;
maxCount: number;
}
/**
* 分页查询终端文件操作日志
*/
export function getTerminalFileLogPage(request: TerminalFileLogQueryRequest) {
return axios.post<DataGrid<TerminalFileLogQueryResponse>>('/terminal/terminal-file-log/query', request);
}
/**
* 查询终端文件操作日志数量
*/
export function getTerminalFileLogCount(request: TerminalFileLogQueryRequest) {
return axios.post<number>('/terminal/terminal-file-log/count', request);
}
/**
* 删除终端文件操作日志
*/
export function deleteTerminalFileLog(idList: Array<number>) {
return axios.delete('/terminal/terminal-file-log/delete', {
params: { idList },
paramsSerializer: params => {
return qs.stringify(params, { arrayFormat: 'comma' });
}
});
}

View File

@@ -1,74 +1,5 @@
import type { DataGrid, OrderDirection, Pagination } from '@/types/global';
import type { TableData } from '@arco-design/web-vue';
import { httpBaseUrl } from '@/utils/env'; import { httpBaseUrl } from '@/utils/env';
import axios from 'axios'; import axios from 'axios';
import qs from 'query-string';
/**
* SFTP 操作日志 查询请求
*/
export interface TerminalSftpLogQueryRequest extends Pagination, OrderDirection {
userId?: number;
hostId?: number;
type?: string;
result?: number;
startTimeRange?: string[];
}
/**
* SFTP 操作日志 查询响应
*/
export interface TerminalSftpLogQueryResponse extends TableData {
id: number;
userId: number;
username: number;
hostId: number;
hostName: string;
hostAddress: string;
address: string;
location: string;
userAgent: string;
paths: string[];
type: string;
result: string;
startTime: number;
extra: TerminalSftpLogExtra;
}
/**
* SFTP 操作日志 拓展对象
*/
export interface TerminalSftpLogExtra {
mod: number;
target: string;
maxCount: number;
}
/**
* 分页查询 SFTP 操作日志
*/
export function getTerminalSftpLogPage(request: TerminalSftpLogQueryRequest) {
return axios.post<DataGrid<TerminalSftpLogQueryResponse>>('/terminal/terminal-sftp/query-log', request);
}
/**
* 查询 SFTP 操作日志数量
*/
export function getTerminalSftpLogCount(request: TerminalSftpLogQueryRequest) {
return axios.post<number>('/terminal/terminal-sftp/log-count', request);
}
/**
* 删除 SFTP 操作日志
*/
export function deleteTerminalSftpLog(idList: Array<number>) {
return axios.delete('/terminal/terminal-sftp/delete-log', {
params: { idList },
paramsSerializer: params => {
return qs.stringify(params, { arrayFormat: 'comma' });
}
});
}
/** /**
* 获取 SFTP 文件内容 * 获取 SFTP 文件内容

View File

@@ -8,19 +8,19 @@ const ASSET_AUDIT: AppRouteRecordRaw[] = [
component: DEFAULT_LAYOUT, component: DEFAULT_LAYOUT,
children: [ children: [
{ {
name: 'connectLog', name: 'terminalConnectLog',
path: '/audit/connect-log', path: '/audit/terminal-connect-log',
component: () => import('@/views/asset-audit/connect-log/index.vue'), component: () => import('@/views/asset-audit/terminal-connect-log/index.vue'),
}, },
{ {
name: 'connectSession', name: 'terminalConnectSession',
path: '/audit/connect-session', path: '/audit/terminal-connect-session',
component: () => import('@/views/asset-audit/connect-session/index.vue'), component: () => import('@/views/asset-audit/terminal-connect-session/index.vue'),
}, },
{ {
name: 'sftpLog', name: 'terminalFileLog',
path: '/audit/sftp-log', path: '/audit/terminal-file-log',
component: () => import('@/views/asset-audit/sftp-log/index.vue'), component: () => import('@/views/asset-audit/terminal-file-log/index.vue'),
}, },
], ],
}, },

View File

@@ -1,20 +0,0 @@
// 表名称
export const TableName = 'sftp-log';
// sftp 操作类型
export const SftpOperatorType = {
SFTP_MOVE: 'terminal:sftp-move',
SFTP_CHMOD: 'terminal:sftp-chmod',
};
// 最大展示数量
export const showPathMaxCount = 5;
// sftp 操作类型 字典项
export const sftpOperatorTypeKey = 'sftpOperatorType';
// sftp 操作结果 字典项
export const sftpOperatorResultKey = 'operatorLogResult';
// 加载的字典值
export const dictKeys = [sftpOperatorTypeKey, sftpOperatorResultKey];

View File

@@ -14,7 +14,7 @@
<script lang="ts"> <script lang="ts">
export default { export default {
name: 'connectLog' name: 'terminalConnectLog'
}; };
</script> </script>

View File

@@ -46,7 +46,7 @@
<div class="table-left-bar-handle"> <div class="table-left-bar-handle">
<!-- 标题 --> <!-- 标题 -->
<div class="table-title"> <div class="table-title">
主机在线会话 终端在线会话
</div> </div>
</div> </div>
</template> </template>

View File

@@ -7,7 +7,7 @@
<script lang="ts"> <script lang="ts">
export default { export default {
name: 'connectSession' name: 'terminalConnectSession'
}; };
</script> </script>
@@ -18,7 +18,6 @@
import ConnectSessionTable from './components/connect-session-table.vue'; import ConnectSessionTable from './components/connect-session-table.vue';
const render = ref(false); const render = ref(false);
const eventDrawer = ref();
// //
onBeforeMount(async () => { onBeforeMount(async () => {

View File

@@ -24,14 +24,14 @@
<a-form-item field="type" label="操作类型"> <a-form-item field="type" label="操作类型">
<a-select v-model="formModel.type" <a-select v-model="formModel.type"
placeholder="请选择类型" placeholder="请选择类型"
:options="toOptions(sftpOperatorTypeKey)" :options="toOptions(terminalFileOperatorTypeKey)"
allow-clear /> allow-clear />
</a-form-item> </a-form-item>
<!-- 执行结果 --> <!-- 执行结果 -->
<a-form-item field="result" label="执行结果"> <a-form-item field="result" label="执行结果">
<a-select v-model="formModel.result" <a-select v-model="formModel.result"
placeholder="请选择执行结果" placeholder="请选择执行结果"
:options="toOptions(sftpOperatorResultKey)" :options="toOptions(operatorResultKey)"
allow-clear /> allow-clear />
</a-form-item> </a-form-item>
<!-- 开始时间 --> <!-- 开始时间 -->
@@ -50,7 +50,7 @@
<div class="table-left-bar-handle"> <div class="table-left-bar-handle">
<!-- 标题 --> <!-- 标题 -->
<div class="table-title"> <div class="table-title">
文件操作日志 终端文件日志
</div> </div>
</div> </div>
<!-- 右侧操作 --> <!-- 右侧操作 -->
@@ -61,7 +61,7 @@
position="br" position="br"
type="warning" type="warning"
@ok="deleteSelectedRows"> @ok="deleteSelectedRows">
<a-button v-permission="['infra:operator-log:delete', 'terminal:terminal-sftp-log:management:delete']" <a-button v-permission="['infra:operator-log:delete', 'terminal:terminal-file-log:management:delete']"
type="primary" type="primary"
status="danger" status="danger"
:disabled="selectedKeys.length === 0"> :disabled="selectedKeys.length === 0">
@@ -110,7 +110,7 @@
<!-- 操作类型 --> <!-- 操作类型 -->
<template #type="{ record }"> <template #type="{ record }">
<a-tag color="arcoblue"> <a-tag color="arcoblue">
{{ getDictValue(sftpOperatorTypeKey, record.type) }} {{ getDictValue(terminalFileOperatorTypeKey, record.type) }}
</a-tag> </a-tag>
</template> </template>
<!-- 文件数量 --> <!-- 文件数量 -->
@@ -127,11 +127,11 @@
{{ path }} {{ path }}
</span> </span>
<!-- 移动目标路径 --> <!-- 移动目标路径 -->
<span class="table-cell-sub-value" v-if="SftpOperatorType.SFTP_MOVE === record.type"> <span class="table-cell-sub-value" v-if="TerminalFileOperatorType.SFTP_MOVE === record.type">
移动到 {{ record.extra?.target }} 移动到 {{ record.extra?.target }}
</span> </span>
<!-- 提权信息 --> <!-- 提权信息 -->
<span class="table-cell-sub-value" v-if="SftpOperatorType.SFTP_CHMOD === record.type"> <span class="table-cell-sub-value" v-if="TerminalFileOperatorType.SFTP_CHMOD === record.type">
提权 {{ record.extra?.mod }} {{ permission10toString(record.extra?.mod as number) }} 提权 {{ record.extra?.mod }} {{ permission10toString(record.extra?.mod as number) }}
</span> </span>
</div> </div>
@@ -145,8 +145,8 @@
</template> </template>
<!-- 执行结果 --> <!-- 执行结果 -->
<template #result="{ record }"> <template #result="{ record }">
<a-tag :color="getDictValue(sftpOperatorResultKey, record.result, 'color')"> <a-tag :color="getDictValue(operatorResultKey, record.result, 'color')">
{{ getDictValue(sftpOperatorResultKey, record.result) }} {{ getDictValue(operatorResultKey, record.result) }}
</a-tag> </a-tag>
</template> </template>
<!-- 留痕地址 --> <!-- 留痕地址 -->
@@ -169,7 +169,7 @@
position="left" position="left"
type="warning" type="warning"
@ok="deleteRow(record)"> @ok="deleteRow(record)">
<a-button v-permission="['infra:operator-log:delete', 'terminal:terminal-sftp-log:management:delete']" <a-button v-permission="['infra:operator-log:delete', 'terminal:terminal-file-log:management:delete']"
type="text" type="text"
size="mini" size="mini"
status="danger"> status="danger">
@@ -184,15 +184,15 @@
<script lang="ts"> <script lang="ts">
export default { export default {
name: 'sftpLogTable' name: 'fileLogTable'
}; };
</script> </script>
<script lang="ts" setup> <script lang="ts" setup>
import type { TerminalSftpLogQueryRequest, TerminalSftpLogQueryResponse } from '@/api/terminal/terminal-sftp'; import type { TerminalFileLogQueryRequest, TerminalFileLogQueryResponse } from '@/api/terminal/terminal-file-log';
import { reactive, ref, onMounted } from 'vue'; import { reactive, ref, onMounted } from 'vue';
import { getTerminalSftpLogPage, deleteTerminalSftpLog } from '@/api/terminal/terminal-sftp'; import { getTerminalFileLogPage, deleteTerminalFileLog } from '@/api/terminal/terminal-file-log';
import { TableName, sftpOperatorTypeKey, sftpOperatorResultKey, SftpOperatorType, showPathMaxCount } from '../types/const'; import { TableName, terminalFileOperatorTypeKey, operatorResultKey, TerminalFileOperatorType, showPathMaxCount } from '../types/const';
import { useTablePagination, useRowSelection, useTableColumns } from '@/hooks/table'; import { useTablePagination, useRowSelection, useTableColumns } from '@/hooks/table';
import { useDictStore } from '@/store'; import { useDictStore } from '@/store';
import { Message } from '@arco-design/web-vue'; import { Message } from '@arco-design/web-vue';
@@ -212,9 +212,9 @@
const { loading, setLoading } = useLoading(); const { loading, setLoading } = useLoading();
const { toOptions, getDictValue } = useDictStore(); const { toOptions, getDictValue } = useDictStore();
const tableRenderData = ref<Array<TerminalSftpLogQueryResponse>>([]); const tableRenderData = ref<Array<TerminalFileLogQueryResponse>>([]);
const selectedKeys = ref<Array<number>>([]); const selectedKeys = ref<Array<number>>([]);
const formModel = reactive<TerminalSftpLogQueryRequest>({ const formModel = reactive<TerminalFileLogQueryRequest>({
userId: undefined, userId: undefined,
hostId: undefined, hostId: undefined,
type: undefined, type: undefined,
@@ -223,11 +223,11 @@
}); });
// //
const doFetchTableData = async (request: TerminalSftpLogQueryRequest) => { const doFetchTableData = async (request: TerminalFileLogQueryRequest) => {
try { try {
setLoading(true); setLoading(true);
// //
const { data } = await getTerminalSftpLogPage(queryOrder.markOrderly(request)); const { data } = await getTerminalFileLogPage(queryOrder.markOrderly(request));
// //
data.rows.forEach(s => { data.rows.forEach(s => {
s.extra.maxCount = showPathMaxCount; s.extra.maxCount = showPathMaxCount;
@@ -253,7 +253,7 @@
try { try {
setLoading(true); setLoading(true);
// //
await deleteTerminalSftpLog(selectedKeys.value); await deleteTerminalFileLog(selectedKeys.value);
Message.success(`成功删除 ${selectedKeys.value.length} 条数据`); Message.success(`成功删除 ${selectedKeys.value.length} 条数据`);
selectedKeys.value = []; selectedKeys.value = [];
// //
@@ -265,11 +265,11 @@
}; };
// //
const deleteRow = async (record: TerminalSftpLogQueryResponse) => { const deleteRow = async (record: TerminalFileLogQueryResponse) => {
try { try {
setLoading(true); setLoading(true);
// //
await deleteTerminalSftpLog([record.id]); await deleteTerminalFileLog([record.id]);
Message.success('删除成功'); Message.success('删除成功');
selectedKeys.value = []; selectedKeys.value = [];
// //

View File

@@ -1,13 +1,13 @@
<template> <template>
<div class="layout-container" v-if="render"> <div class="layout-container" v-if="render">
<!-- 列表-表格 --> <!-- 列表-表格 -->
<sftp-log-table /> <file-log-table />
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
export default { export default {
name: 'sftpLog' name: 'terminalFileLog'
}; };
</script> </script>
@@ -15,7 +15,7 @@
import { ref, onBeforeMount } from 'vue'; import { ref, onBeforeMount } from 'vue';
import { useDictStore } from '@/store'; import { useDictStore } from '@/store';
import { dictKeys } from './types/const'; import { dictKeys } from './types/const';
import SftpLogTable from './components/sftp-log-table.vue'; import FileLogTable from './components/file-log-table.vue';
const render = ref(false); const render = ref(false);

View File

@@ -0,0 +1,20 @@
// 表名称
export const TableName = 'file-log';
// 终端文件操作类型
export const TerminalFileOperatorType = {
SFTP_MOVE: 'terminal:sftp-move',
SFTP_CHMOD: 'terminal:sftp-chmod',
};
// 最大展示数量
export const showPathMaxCount = 5;
// 终端文件操作类型 字典项
export const terminalFileOperatorTypeKey = 'terminalFileOperatorType';
// 操作结果 字典项
export const operatorResultKey = 'operatorLogResult';
// 加载的字典值
export const dictKeys = [terminalFileOperatorTypeKey, operatorResultKey];

View File

@@ -30,7 +30,7 @@ const columns = [
title: '操作类型', title: '操作类型',
dataIndex: 'type', dataIndex: 'type',
slotName: 'type', slotName: 'type',
width: 116, width: 146,
align: 'left', align: 'left',
default: true, default: true,
}, { }, {

View File

@@ -6,7 +6,7 @@
<!-- 跳转 --> <!-- 跳转 -->
<span class="pointer span-blue" <span class="pointer span-blue"
title="详情" title="详情"
@click="router.push({ name: 'connectLog', query: { action: 'self' } })"> @click="router.push({ name: 'terminalConnectLog', query: { action: 'self' } })">
详情 详情
</span> </span>
</div> </div>

View File

@@ -99,7 +99,7 @@
background: isDark.value ? '#354276' : '#E8F3FF', background: isDark.value ? '#354276' : '#E8F3FF',
iconColor: isDark.value ? '#4A7FF7' : '#165DFF', iconColor: isDark.value ? '#4A7FF7' : '#165DFF',
}, },
go: () => router.push({ name: 'connectLog', query: { action: 'self' } }) go: () => router.push({ name: 'terminalConnectLog', query: { action: 'self' } })
}, { }, {
title: '今日批量执行次数', title: '今日批量执行次数',
value: props.data.exec?.todayExecCommandCount || 0, value: props.data.exec?.todayExecCommandCount || 0,