🎨 修改批量执行模块格式.

This commit is contained in:
lijiahangmax
2024-04-11 00:21:42 +08:00
parent bcef835de3
commit ac6ccd5830
10 changed files with 24 additions and 121 deletions

View File

@@ -1,74 +0,0 @@
import type { TableData } from '@arco-design/web-vue/es/table/interface';
import axios from 'axios';
import qs from 'query-string';
/**
* 执行记录查询响应
*/
export interface ExecLogQueryResponse extends TableData, ExecLogQueryExtraResponse {
id: number;
userId: number;
username: string;
description: string;
command: string;
parameterSchema: string;
timeout: number;
status: string;
startTime: number;
finishTime: number;
hostIdList: Array<number>;
hosts: Array<ExecHostLogQueryResponse>;
}
/**
* 执行记录查询响应 拓展
*/
export interface ExecLogQueryExtraResponse {
hosts: Array<ExecHostLogQueryResponse>;
}
/**
* 主机执行记录查询响应
*/
export interface ExecHostLogQueryResponse extends TableData {
id: number;
logId: number;
hostId: number;
hostName: string;
hostAddress: string;
status: string;
command: string;
parameter: string;
exitStatus: number;
errorMessage: string;
startTime: number;
finishTime: number;
}
/**
* 执行状态查询响应
*/
export interface ExecStatusResponse {
logList: Array<ExecLogQueryResponse>;
hostList: Array<ExecHostLogQueryResponse>;
}
/**
* 查询执行记录
*/
export function getExecLog(id: number) {
return axios.get<ExecLogQueryResponse>('/asset/exec-log/get', { params: { id } });
}
/**
* 查询命令执行状态
*/
export function getExecLogStatus(idList: Array<number>) {
return axios.get<ExecStatusResponse>('/asset/exec-log/status', {
params: { idList },
paramsSerializer: params => {
return qs.stringify(params, { arrayFormat: 'comma' });
}
});
}

View File

@@ -1,23 +0,0 @@
import axios from 'axios';
/**
* 中断命令请求
*/
export interface ExecTailRequest {
execId?: number;
hostExecIdList?: Array<number>;
}
/**
* 查看执行日志
*/
export function getExecLogTailToken(request: ExecTailRequest) {
return axios.post<string>('/asset/exec/tail-log', request);
}
/**
* 下载执行日志文件
*/
export function downloadExecLogFile(id: number) {
return axios.get('/asset/exec/download-log', { unwrap: true, params: { id } });
}

View File

@@ -32,7 +32,7 @@
import useVisible from '@/hooks/visible';
import useLoading from '@/hooks/loading';
import { nextTick, ref } from 'vue';
import { getExecLog } from '@/api/exec/exec-log';
import { getExecCommandLog } from '@/api/exec/exec-command-log';
import ExecLogPanel from '../panel/index.vue';
const { visible, setVisible } = useVisible();
@@ -46,7 +46,7 @@
setLoading(true);
try {
// 获取执行日志
const { data } = await getExecLog(id);
const { data } = await getExecCommandLog(id);
// 打开日志
await nextTick(() => {
setTimeout(() => {

View File

@@ -41,14 +41,14 @@
</script>
<script lang="ts" setup>
import type { ExecHostLogQueryResponse } from '@/api/exec/exec-log';
import type { ExecCommandHostLogQueryResponse } from '@/api/exec/exec-command-log';
import { useDictStore } from '@/store';
import { execHostStatusKey } from './const';
const props = defineProps<{
visibleBack: boolean;
current: number;
hosts: Array<ExecHostLogQueryResponse>;
hosts: Array<ExecCommandHostLogQueryResponse>;
}>();
const emits = defineEmits(['back', 'selected']);

View File

@@ -23,10 +23,10 @@
</script>
<script lang="ts" setup>
import type { ExecLogQueryResponse } from '@/api/exec/exec-log';
import type { ExecCommandLogQueryResponse } from '@/api/exec/exec-command-log';
import type { ILogAppender } from './const';
import { onUnmounted, ref, nextTick, onMounted } from 'vue';
import { getExecLogStatus } from '@/api/exec/exec-log';
import { getExecCommandLogStatus } from '@/api/exec/exec-command-log';
import { dictKeys, execHostStatus, execStatus } from './const';
import ExecHost from './exec-host.vue';
import LogView from './log-view.vue';
@@ -43,11 +43,11 @@
const currentHostExecId = ref();
const statusIntervalId = ref();
const finishIntervalId = ref();
const execLog = ref<ExecLogQueryResponse>();
const execLog = ref<ExecCommandLogQueryResponse>();
const appender = ref<ILogAppender>();
// 打开
const open = (record: ExecLogQueryResponse) => {
const open = (record: ExecCommandLogQueryResponse) => {
appender.value = new LogAppender({ execId: record.id });
execLog.value = record;
currentHostExecId.value = record.hosts[0].id;
@@ -71,7 +71,7 @@
return;
}
// 加载状态
const { data: { logList, hostList } } = await getExecLogStatus([execLog.value.id]);
const { data: { logList, hostList } } = await getExecCommandLogStatus([execLog.value.id]);
if (logList.length) {
execLog.value.status = logList[0].status;
execLog.value.startTime = logList[0].startTime;

View File

@@ -1,7 +1,7 @@
import type { ILogAppender, LogAddons, LogAppenderConf, LogDomRef } from './const';
import { AppenderOptions } from './const';
import type { ExecTailRequest } from '@/api/exec/exec';
import { getExecLogTailToken } from '@/api/exec/exec';
import type { ExecCommandLogTailRequest } from '@/api/exec/exec-command-log';
import { getExecCommandLogTailToken } from '@/api/exec/exec-command-log';
import { webSocketBaseUrl } from '@/utils/env';
import { Message } from '@arco-design/web-vue';
import { createWebSocket } from '@/utils';
@@ -21,7 +21,7 @@ export default class LogAppender implements ILogAppender {
private client?: WebSocket;
private readonly config: ExecTailRequest;
private readonly config: ExecCommandLogTailRequest;
private readonly appenderRel: Record<string, LogAppenderConf>;
@@ -29,7 +29,7 @@ export default class LogAppender implements ILogAppender {
private readonly fitAllFn: () => {};
constructor(config: ExecTailRequest) {
constructor(config: ExecCommandLogTailRequest) {
this.current = undefined as unknown as LogAppenderConf;
this.config = config;
this.appenderRel = {};
@@ -142,7 +142,7 @@ export default class LogAppender implements ILogAppender {
// 初始化 client
async openClient() {
// 获取 token
const { data } = await getExecLogTailToken(this.config);
const { data } = await getExecCommandLogTailToken(this.config);
// 打开会话
try {
this.client = await createWebSocket(`${webSocketBaseUrl}/exec/log/${data}`);

View File

@@ -160,19 +160,19 @@
</script>
<script lang="ts" setup>
import type { ExecHostLogQueryResponse } from '@/api/exec/exec-log';
import type { ExecCommandHostLogQueryResponse } from '@/api/exec/exec-command-log';
import type { ILogAppender } from './const';
import { ref } from 'vue';
import { execHostStatus, execHostStatusKey } from './const';
import { formatDuration } from '@/utils';
import { useDictStore } from '@/store';
import { downloadExecLogFile } from '@/api/exec/exec';
import { downloadExecCommandLogFile } from '@/api/exec/exec-command-log';
import { downloadFile } from '@/utils/file';
import XtermSearchModal from '@/components/xtrem/search-modal/index.vue';
import 'xterm/css/xterm.css';
const props = defineProps<{
host: ExecHostLogQueryResponse;
host: ExecCommandHostLogQueryResponse;
appender: ILogAppender
}>();
@@ -204,7 +204,7 @@
// 下载文件
const downloadLogFile = async (id: number) => {
const data = await downloadExecLogFile(id);
const data = await downloadExecCommandLogFile(id);
downloadFile(data);
};

View File

@@ -18,14 +18,14 @@
<script lang="ts" setup>
import type { VNodeRef } from 'vue';
import type { ExecHostLogQueryResponse } from '@/api/exec/exec-log';
import type { ExecCommandHostLogQueryResponse } from '@/api/exec/exec-command-log';
import type { LogDomRef, ILogAppender } from './const';
import { nextTick, ref, watch } from 'vue';
import LogItem from './log-item.vue';
const props = defineProps<{
current: number;
hosts: Array<ExecHostLogQueryResponse>;
hosts: Array<ExecCommandHostLogQueryResponse>;
appender: ILogAppender;
}>();

View File

@@ -15,7 +15,7 @@
<script lang="ts" setup>
import { onMounted, ref, nextTick } from 'vue';
import { useRoute } from 'vue-router';
import { getExecLog } from '@/api/exec/exec-log';
import { getExecCommandLog } from '@/api/exec/exec-command-log';
import ExecLogPanel from '@/components/exec/log/panel/index.vue';
const route = useRoute();
@@ -24,7 +24,7 @@
// 初始化
const init = async (id: number) => {
// 获取执行日志
const { data } = await getExecLog(id);
const { data } = await getExecCommandLog(id);
// 打开日志
await nextTick(() => {
setTimeout(() => {

View File

@@ -110,8 +110,8 @@
import { useDictStore } from '@/store';
import { useExpandable } from '@/types/table';
import { dateFormat, formatDuration } from '@/utils';
import { downloadExecLogFile } from '@/api/exec/exec';
import { interruptHostExecCommand } from '@/api/exec/exec-command';
import { downloadExecCommandLogFile } from '@/api/exec/exec-command-log';
import { copy } from '@/hooks/copy';
import { downloadFile } from '@/utils/file';
@@ -127,7 +127,7 @@
// 下载文件
const downloadLogFile = async (id: number) => {
const data = await downloadExecLogFile(id);
const data = await downloadExecCommandLogFile(id);
downloadFile(data);
};