From 2574cd53873be14fff75d3eb7a4c6f403bdba94e Mon Sep 17 00:00:00 2001 From: chaoszhu Date: Tue, 22 Jul 2025 00:02:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=89=B9=E9=87=8F=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E9=80=BB=E8=BE=91=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/app/controller/onekey.js | 2 +- server/app/socket/onekey.js | 5 ++-- web/src/views/onekey/index.vue | 45 +++++++++++++++++++++++++-------- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/server/app/controller/onekey.js b/server/app/controller/onekey.js index 05a4795..7488146 100644 --- a/server/app/controller/onekey.js +++ b/server/app/controller/onekey.js @@ -6,7 +6,7 @@ async function getOnekeyRecord({ res }) { data = data.map(item => { return { ...item, id: item._id } }) - data?.sort((a, b) => Number(b.date) - Number(a.date)) + data?.sort((a, b) => Number(b.startDate) - Number(a.startDate)) res.success({ data }) } diff --git a/server/app/socket/onekey.js b/server/app/socket/onekey.js index fcff047..2c90e52 100644 --- a/server/app/socket/onekey.js +++ b/server/app/socket/onekey.js @@ -52,7 +52,7 @@ function execShell(socket, sshClient, curRes, resolve) { // arrayBuffers: (memoryUsage.arrayBuffers / 1024 / 1024).toFixed(2) + ' MB' // Memory allocated for ArrayBuffer and SharedArrayBuffer, including all Node.js Buffers // } // console.log(formattedMemoryUsage) - }, 500) // 防止内存爆破 + }, 1000) // 防止内存爆破 sshClient.exec(curRes.command, function(err, stream) { if (err) { console.log(curRes.host, '命令执行失败:', err) @@ -134,7 +134,7 @@ module.exports = (httpServer) => { return new Promise(async (resolve, reject) => { setTimeout(() => reject('执行超时'), timeout * 1000) let { host, port, jumpHosts } = hostInfo - let curRes = { command, host, port, name: hostInfo.name, result: '', status: execStatusEnum.connecting, date: Date.now() - (targetHostsInfo.length - index) } + let curRes = { command, host, port, name: hostInfo.name, result: '', status: execStatusEnum.connecting, startDate: Date.now() + index } execResult.push(curRes) let jumpSshClients = [] try { @@ -218,6 +218,7 @@ module.exports = (httpServer) => { if (reason !== 'server namespace disconnect' && ![execSuccess, execFail, execTimeout, connectFail].includes(item.status)) { item.status = execStatusEnum.socketInterrupt } + item.endDate = Date.now() }) await onekeyDB.insertAsync(execResult) isExecuting = false diff --git a/web/src/views/onekey/index.vue b/web/src/views/onekey/index.vue index 616d2a1..bec58a0 100644 --- a/web/src/views/onekey/index.vue +++ b/web/src/views/onekey/index.vue @@ -9,6 +9,14 @@ > {{ isExecuting ? `执行中,剩余${timeRemaining}秒` : '批量下发指令' }} + @@ -54,6 +62,26 @@ {{ row.command }} + + + + + + { }) }) const expandRows = computed(() => { - let rows = tableData.value.filter(item => item.pending).map(item => item.id) + let rows = tableData.value.filter(item => item.pending).map(item => item.startDate) return rows }) @@ -281,11 +309,7 @@ const createExecShell = (hostIds = [], command = 'ls', timeout = 60) => { message: reason, type: 'error' }) - if (Array.isArray(result) && result.length > 0) { - // console.log('output', result) - result = result.map(item => ({ ...item, pending: true })) - pendingRecord.value = result - } + getOnekeyRecord() }) socket.value.on('token_verify_fail', () => { @@ -299,6 +323,7 @@ const createExecShell = (hostIds = [], command = 'ls', timeout = 60) => { message: '执行完成', type: 'success' }) + getOnekeyRecord() }) }) @@ -365,6 +390,7 @@ let getOnekeyRecord = async () => { loading.value = true let { data } = await $api.getOnekeyRecord() recordList.value = data + pendingRecord.value = [] loading.value = false } @@ -443,9 +469,6 @@ onActivated(async () => { display: flex; align-items: center; justify-content: end; - position: sticky; - top: 0; - z-index: 1; } .detail_content_box { max-height: 200px;