From bfe8127ee8965f5961dc5708aeb68c2ff63bb7c9 Mon Sep 17 00:00:00 2001 From: 24kycj <1637269896@qq.com> Date: Sat, 15 Nov 2025 19:18:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BD=95=E5=88=B6=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/recorder.js | 23 ++++++++++++++----- .../components/recorder/ScreenRecorder.vue | 15 +++++++++--- src/renderer/components/work.vue | 1 + 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/main/recorder.js b/src/main/recorder.js index 6c9c064..a7370f9 100644 --- a/src/main/recorder.js +++ b/src/main/recorder.js @@ -45,7 +45,7 @@ class ScreenRecorder { } } - async stopRecording(videoData) { + async stopRecording(videoData, taskId = '') { if (!this.isRecording) { return { success: false, message: '当前没有进行录制' }; } @@ -62,9 +62,20 @@ class ScreenRecorder { fs.mkdirSync(videosDir, { recursive: true }); } - // 生成文件名:soonworker+时间戳 - const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, -5); - const fileName = `soonworker_${timestamp}.webm`; + // 生成文件名:任务ID_日期时间格式 (YYYYMMDD_HHmmss) + const now = new Date(); + const year = now.getFullYear(); + const month = String(now.getMonth() + 1).padStart(2, '0'); + const day = String(now.getDate()).padStart(2, '0'); + const hours = String(now.getHours()).padStart(2, '0'); + const minutes = String(now.getMinutes()).padStart(2, '0'); + const seconds = String(now.getSeconds()).padStart(2, '0'); + const dateTimeStr = `${year}${month}${day}_${hours}${minutes}${seconds}`; + + // 如果有任务ID,使用任务ID_日期时间,否则使用日期时间 + const fileName = taskId + ? `${taskId}_${dateTimeStr}.webm` + : `${dateTimeStr}.webm`; const filePath = path.join(videosDir, fileName); // 将base64数据转换为Buffer并保存 @@ -102,8 +113,8 @@ ipcMain.handle('start-recording', async () => { return await recorder.startRecording(); }); -ipcMain.handle('stop-recording', async (event, videoData) => { - return await recorder.stopRecording(videoData); +ipcMain.handle('stop-recording', async (event, videoData, taskId) => { + return await recorder.stopRecording(videoData, taskId); }); ipcMain.handle('get-videos-path', () => { diff --git a/src/renderer/components/recorder/ScreenRecorder.vue b/src/renderer/components/recorder/ScreenRecorder.vue index c4d0073..6047a5b 100644 --- a/src/renderer/components/recorder/ScreenRecorder.vue +++ b/src/renderer/components/recorder/ScreenRecorder.vue @@ -28,6 +28,12 @@ const { ipcRenderer } = require('electron'); export default { name: 'ScreenRecorder', + props: { + taskId: { + type: String, + default: '' + } + }, data() { return { isRecording: false, @@ -37,7 +43,8 @@ export default { startTime: null, recordingTime: '00:00', timer: null, - stream: null + stream: null, + currentTaskId: '' // 录屏开始时的任务ID }; }, methods: { @@ -99,6 +106,8 @@ export default { this.mediaRecorder.start(); this.isRecording = true; this.startTime = Date.now(); + // 保存录屏开始时的任务ID + this.currentTaskId = this.taskId || ''; this.startTimer(); this.$message.success(this.$t('recorder.recordingStarted') || '开始录制'); @@ -154,8 +163,8 @@ export default { reader.onloadend = async () => { const base64data = reader.result; - // 发送到主进程保存 - const result = await ipcRenderer.invoke('stop-recording', base64data); + // 发送到主进程保存,传递任务ID + const result = await ipcRenderer.invoke('stop-recording', base64data, this.currentTaskId); if (result.success) { this.$message.success(this.$t('recorder.savedSuccess') || `录制已保存: ${result.fileName}`); diff --git a/src/renderer/components/work.vue b/src/renderer/components/work.vue index 252a820..8fb9166 100644 --- a/src/renderer/components/work.vue +++ b/src/renderer/components/work.vue @@ -257,6 +257,7 @@