🔨 优化代码逻辑.

This commit is contained in:
lijiahangmax
2025-06-28 16:37:14 +08:00
parent da766f0b85
commit f1771ce676
9 changed files with 18 additions and 12 deletions

View File

@@ -331,7 +331,7 @@
// 查询未读消息 // 查询未读消息
pullHasUnreadMessage(); pullHasUnreadMessage();
// 注册未读消息轮询 // 注册未读消息轮询
messageIntervalId.value = setInterval(pullHasUnreadMessage, 30000); messageIntervalId.value = window.setInterval(pullHasUnreadMessage, 30000);
}); });
onUnmounted(() => { onUnmounted(() => {

View File

@@ -69,7 +69,7 @@
// 等待一秒后先查询一下状态 // 等待一秒后先查询一下状态
setTimeout(pullExecStatus, 1000); setTimeout(pullExecStatus, 1000);
// 注册状态轮询 // 注册状态轮询
pullIntervalId.value = setInterval(pullExecStatus, 5000); pullIntervalId.value = window.setInterval(pullExecStatus, 5000);
} }
// 打开日志 // 打开日志
nextTick(() => { nextTick(() => {

View File

@@ -172,11 +172,11 @@ export default class LogAppender implements ILogAppender {
}; };
this.client.onmessage = this.processMessage.bind(this); this.client.onmessage = this.processMessage.bind(this);
// 注册持久化 // 注册持久化
this.keepAliveTask = setInterval(() => { this.keepAliveTask = window.setInterval(() => {
if (this.client?.readyState === WebSocket.OPEN) { if (this.client?.readyState === WebSocket.OPEN) {
this.client?.send('p'); this.client?.send('p');
} }
}, 15000) as unknown as number; }, 15000);
} }
// 打开日志 // 打开日志

View File

@@ -2,6 +2,7 @@ import type { FileItem } from '@arco-design/web-vue';
import type { IFileUploader, ResponseMessageBody } from './const'; import type { IFileUploader, ResponseMessageBody } from './const';
import { UploadOperatorType, UploadReceiverType } from './const'; import { UploadOperatorType, UploadReceiverType } from './const';
import { openFileUploadChannel } from '@/api/system/upload'; import { openFileUploadChannel } from '@/api/system/upload';
import { closeFileReader } from '@/utils/file';
// 512 KB // 512 KB
export const PART_SIZE = 512 * 1024; export const PART_SIZE = 512 * 1024;
@@ -81,13 +82,14 @@ export default class FileUploader implements IFileUploader {
// 上传下一块数据 // 上传下一块数据
private async uploadNextPart() { private async uploadNextPart() {
let reader = undefined as unknown as FileReader;
try { try {
if (this.currentPart < this.totalPart) { if (this.currentPart < this.totalPart) {
// 有下一个分片则上传 // 有下一个分片则上传
const start = this.currentPart++ * PART_SIZE; const start = this.currentPart++ * PART_SIZE;
const end = Math.min(this.currentFile.size, start + PART_SIZE); const end = Math.min(this.currentFile.size, start + PART_SIZE);
const chunk = this.currentFile.slice(start, end); const chunk = this.currentFile.slice(start, end);
const reader = new FileReader(); reader = new FileReader();
// 读取数据 // 读取数据
const arrayBuffer = await new Promise((resolve, reject) => { const arrayBuffer = await new Promise((resolve, reject) => {
reader.onload = () => resolve(reader.result); reader.onload = () => resolve(reader.result);
@@ -107,11 +109,15 @@ export default class FileUploader implements IFileUploader {
})); }));
} }
} catch (e) { } catch (e) {
// 读取文件失败 // 发送读取文件失败
this.client?.send(JSON.stringify({ this.client?.send(JSON.stringify({
type: UploadOperatorType.ERROR, type: UploadOperatorType.ERROR,
fileId: this.currentFileItem.uid, fileId: this.currentFileItem.uid,
})); }));
// 释放资源
if (reader) {
closeFileReader(reader);
}
} }
} }

View File

@@ -278,7 +278,7 @@
// 设置轮询状态 // 设置轮询状态
onMounted(() => { onMounted(() => {
pullIntervalId.value = setInterval(pullTaskStatus, 5000); pullIntervalId.value = window.setInterval(pullTaskStatus, 5000);
}); });
// 卸载状态查询 // 卸载状态查询

View File

@@ -429,7 +429,7 @@
// 加载数据 // 加载数据
fetchTableData(); fetchTableData();
// 注册状态轮询 // 注册状态轮询
pullIntervalId.value = setInterval(pullExecStatus, 10000); pullIntervalId.value = window.setInterval(pullExecStatus, 10000);
}); });
onUnmounted(() => { onUnmounted(() => {

View File

@@ -417,7 +417,7 @@
// 加载数据 // 加载数据
fetchTableData(); fetchTableData();
// 注册状态轮询 // 注册状态轮询
pullIntervalId.value = setInterval(pullJobStatus, 10000); pullIntervalId.value = window.setInterval(pullJobStatus, 10000);
}); });
onUnmounted(() => { onUnmounted(() => {

View File

@@ -324,7 +324,7 @@
// 加载数据 // 加载数据
fetchTableData(); fetchTableData();
// 注册状态轮询 // 注册状态轮询
pullIntervalId.value = setInterval(pullTaskStatus, 10000); pullIntervalId.value = window.setInterval(pullTaskStatus, 10000);
}); });
onUnmounted(() => { onUnmounted(() => {

View File

@@ -23,7 +23,7 @@ export default class TerminalSessionManager implements ITerminalSessionManager {
public sessions: Array<ITerminalSession>; public sessions: Array<ITerminalSession>;
private readonly keepAliveTaskId?: any; private readonly keepAliveTaskId: number;
private readonly dispatchFitFn: () => void; private readonly dispatchFitFn: () => void;
@@ -33,7 +33,7 @@ export default class TerminalSessionManager implements ITerminalSessionManager {
// 注册 resize 事件 // 注册 resize 事件
addEventListen(window, 'resize', this.dispatchFitFn); addEventListen(window, 'resize', this.dispatchFitFn);
// 注册 ping 事件 // 注册 ping 事件
this.keepAliveTaskId = setInterval(this.dispatchPing.bind(this), 15000); this.keepAliveTaskId = window.setInterval(this.dispatchPing.bind(this), 15000);
} }
// 打开 ssh 会话 // 打开 ssh 会话