优化录制文件名
This commit is contained in:
+17
-6
@@ -45,7 +45,7 @@ class ScreenRecorder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async stopRecording(videoData) {
|
async stopRecording(videoData, taskId = '') {
|
||||||
if (!this.isRecording) {
|
if (!this.isRecording) {
|
||||||
return { success: false, message: '当前没有进行录制' };
|
return { success: false, message: '当前没有进行录制' };
|
||||||
}
|
}
|
||||||
@@ -62,9 +62,20 @@ class ScreenRecorder {
|
|||||||
fs.mkdirSync(videosDir, { recursive: true });
|
fs.mkdirSync(videosDir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成文件名:soonworker+时间戳
|
// 生成文件名:任务ID_日期时间格式 (YYYYMMDD_HHmmss)
|
||||||
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, -5);
|
const now = new Date();
|
||||||
const fileName = `soonworker_${timestamp}.webm`;
|
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);
|
const filePath = path.join(videosDir, fileName);
|
||||||
|
|
||||||
// 将base64数据转换为Buffer并保存
|
// 将base64数据转换为Buffer并保存
|
||||||
@@ -102,8 +113,8 @@ ipcMain.handle('start-recording', async () => {
|
|||||||
return await recorder.startRecording();
|
return await recorder.startRecording();
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('stop-recording', async (event, videoData) => {
|
ipcMain.handle('stop-recording', async (event, videoData, taskId) => {
|
||||||
return await recorder.stopRecording(videoData);
|
return await recorder.stopRecording(videoData, taskId);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('get-videos-path', () => {
|
ipcMain.handle('get-videos-path', () => {
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ const { ipcRenderer } = require('electron');
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ScreenRecorder',
|
name: 'ScreenRecorder',
|
||||||
|
props: {
|
||||||
|
taskId: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
isRecording: false,
|
isRecording: false,
|
||||||
@@ -37,7 +43,8 @@ export default {
|
|||||||
startTime: null,
|
startTime: null,
|
||||||
recordingTime: '00:00',
|
recordingTime: '00:00',
|
||||||
timer: null,
|
timer: null,
|
||||||
stream: null
|
stream: null,
|
||||||
|
currentTaskId: '' // 录屏开始时的任务ID
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@@ -99,6 +106,8 @@ export default {
|
|||||||
this.mediaRecorder.start();
|
this.mediaRecorder.start();
|
||||||
this.isRecording = true;
|
this.isRecording = true;
|
||||||
this.startTime = Date.now();
|
this.startTime = Date.now();
|
||||||
|
// 保存录屏开始时的任务ID
|
||||||
|
this.currentTaskId = this.taskId || '';
|
||||||
this.startTimer();
|
this.startTimer();
|
||||||
|
|
||||||
this.$message.success(this.$t('recorder.recordingStarted') || '开始录制');
|
this.$message.success(this.$t('recorder.recordingStarted') || '开始录制');
|
||||||
@@ -154,8 +163,8 @@ export default {
|
|||||||
reader.onloadend = async () => {
|
reader.onloadend = async () => {
|
||||||
const base64data = reader.result;
|
const base64data = reader.result;
|
||||||
|
|
||||||
// 发送到主进程保存
|
// 发送到主进程保存,传递任务ID
|
||||||
const result = await ipcRenderer.invoke('stop-recording', base64data);
|
const result = await ipcRenderer.invoke('stop-recording', base64data, this.currentTaskId);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
this.$message.success(this.$t('recorder.savedSuccess') || `录制已保存: ${result.fileName}`);
|
this.$message.success(this.$t('recorder.savedSuccess') || `录制已保存: ${result.fileName}`);
|
||||||
|
|||||||
@@ -257,6 +257,7 @@
|
|||||||
<!-- 屏幕录制按钮 -->
|
<!-- 屏幕录制按钮 -->
|
||||||
<screen-recorder
|
<screen-recorder
|
||||||
ref="screenRecorder"
|
ref="screenRecorder"
|
||||||
|
:task-id="upload_disk"
|
||||||
@recording-started="onRecordingStarted"
|
@recording-started="onRecordingStarted"
|
||||||
@recording-stopped="onRecordingStopped"
|
@recording-stopped="onRecordingStopped"
|
||||||
@recording-saved="onRecordingSaved"
|
@recording-saved="onRecordingSaved"
|
||||||
|
|||||||
Reference in New Issue
Block a user