优化录制文件名
This commit is contained in:
+17
-6
@@ -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', () => {
|
||||
|
||||
@@ -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}`);
|
||||
|
||||
@@ -257,6 +257,7 @@
|
||||
<!-- 屏幕录制按钮 -->
|
||||
<screen-recorder
|
||||
ref="screenRecorder"
|
||||
:task-id="upload_disk"
|
||||
@recording-started="onRecordingStarted"
|
||||
@recording-stopped="onRecordingStopped"
|
||||
@recording-saved="onRecordingSaved"
|
||||
|
||||
Reference in New Issue
Block a user