Commit 1e3c2fff authored by liujiangnan's avatar liujiangnan

暂存换机器

parent 814989b2
...@@ -141,7 +141,8 @@ ...@@ -141,7 +141,8 @@
<el-input <el-input
v-model="currentPage.start" v-model="currentPage.start"
size="small" size="small"
placeholder="开始时间"> placeholder="开始时间"
@change="handlePageTimeChange('start', $event)">
<template slot="append"> <template slot="append">
<el-button <el-button
type="primary" type="primary"
...@@ -158,7 +159,8 @@ ...@@ -158,7 +159,8 @@
<el-input <el-input
v-model="currentPage.end" v-model="currentPage.end"
size="small" size="small"
placeholder="结束时间"> placeholder="结束时间"
@change="handlePageTimeChange('end', $event)">
<template slot="append"> <template slot="append">
<el-button <el-button
type="primary" type="primary"
...@@ -186,14 +188,16 @@ ...@@ -186,14 +188,16 @@
<el-input <el-input
type="textarea" type="textarea"
:rows="3" :rows="3"
v-model="currentGroup.sentence"> v-model="currentGroup.sentence"
@change="handleGroupTextChange('sentence', $event)">
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-form-item label="中文翻译"> <el-form-item label="中文翻译">
<el-input <el-input
type="textarea" type="textarea"
:rows="3" :rows="3"
v-model="currentGroup.sentence_cn"> v-model="currentGroup.sentence_cn"
@change="handleGroupTextChange('sentence_cn', $event)">
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-form-item label="时间范围"> <el-form-item label="时间范围">
......
...@@ -17,6 +17,8 @@ new Vue({ ...@@ -17,6 +17,8 @@ new Vue({
pages: [], pages: [],
currentPage: null, currentPage: null,
currentPageIndex: 0, currentPageIndex: 0,
// 做一个currentPage的备份
tempPage: null,
// 编辑相关 // 编辑相关
selectedGroup: null, selectedGroup: null,
...@@ -106,31 +108,10 @@ new Vue({ ...@@ -106,31 +108,10 @@ new Vue({
this.audioPoints = data.audio_points; this.audioPoints = data.audio_points;
this.pages = data.pages; this.pages = data.pages;
// 计算每个页面的时间范围
this.pages.forEach(page => {
if (page.groups && page.groups.length > 0) {
// 找出所有组的最早开始时间和最晚结束时间
const times = page.groups.reduce((acc, group) => {
if (group.start !== null && group.start !== undefined) {
acc.starts.push(group.start);
}
if (group.end !== null && group.end !== undefined) {
acc.ends.push(group.end);
}
return acc;
}, { starts: [], ends: [] });
if (times.starts.length > 0) {
page.start = Math.min(...times.starts);
}
if (times.ends.length > 0) {
page.end = Math.max(...times.ends);
}
}
});
this.currentPageIndex = 1; this.currentPageIndex = 1;
this.currentPage = this.pages[0]; this.currentPage = this.pages[0];
// 克隆currentPage
this.tempPage = JSON.parse(JSON.stringify(this.currentPage));
// 开始预加载图片 // 开始预加载图片
this.preloadImages(); this.preloadImages();
...@@ -405,6 +386,8 @@ new Vue({ ...@@ -405,6 +386,8 @@ new Vue({
this.currentPageIndex = pageIndex + 1; this.currentPageIndex = pageIndex + 1;
this.currentPage = this.pages[pageIndex]; this.currentPage = this.pages[pageIndex];
// 克隆currentPage
this.tempPage = JSON.parse(JSON.stringify(this.currentPage));
this.selectedGroup = null; this.selectedGroup = null;
this.currentGroup = null; this.currentGroup = null;
...@@ -448,6 +431,8 @@ new Vue({ ...@@ -448,6 +431,8 @@ new Vue({
// 更新页面索引 // 更新页面索引
this.currentPageIndex = pageIndex + 1; this.currentPageIndex = pageIndex + 1;
this.currentPage = this.pages[pageIndex]; this.currentPage = this.pages[pageIndex];
// 克隆currentPage
this.tempPage = JSON.parse(JSON.stringify(this.currentPage));
// 取消当前选中的组 // 取消当前选中的组
this.selectedGroup = null; this.selectedGroup = null;
...@@ -742,6 +727,8 @@ new Vue({ ...@@ -742,6 +727,8 @@ new Vue({
try { try {
const index = page - 1; const index = page - 1;
this.currentPage = this.pages[index]; this.currentPage = this.pages[index];
// 克隆currentPage
this.tempPage = JSON.parse(JSON.stringify(this.currentPage));
this.selectedGroup = null; this.selectedGroup = null;
this.currentGroup = null; this.currentGroup = null;
...@@ -921,6 +908,9 @@ new Vue({ ...@@ -921,6 +908,9 @@ new Vue({
const currentRect = this.currentGroup.group[this.selectedItemIndex].rect; const currentRect = this.currentGroup.group[this.selectedItemIndex].rect;
if (!currentRect) return; if (!currentRect) return;
// 激活保存按钮
this.isDataModified = true;
if (this.isDragging) { if (this.isDragging) {
// 计算鼠标相对于图片容器的位置 // 计算鼠标相对于图片容器的位置
const mouseX = event.clientX - imageRect.left; const mouseX = event.clientX - imageRect.left;
...@@ -933,7 +923,6 @@ new Vue({ ...@@ -933,7 +923,6 @@ new Vue({
// 限制在图片范围内 // 限制在图片范围内
newX = Math.max(0, Math.min(1 - currentRect.width, newX)); newX = Math.max(0, Math.min(1 - currentRect.width, newX));
newY = Math.max(0, Math.min(1 - currentRect.height, newY)); newY = Math.max(0, Math.min(1 - currentRect.height, newY));
// 更新位置 // 更新位置
this.$set(currentRect, 'x', newX); this.$set(currentRect, 'x', newX);
this.$set(currentRect, 'y', newY); this.$set(currentRect, 'y', newY);
...@@ -962,6 +951,8 @@ new Vue({ ...@@ -962,6 +951,8 @@ new Vue({
this.dragOffsetX = null; this.dragOffsetX = null;
this.dragOffsetY = null; this.dragOffsetY = null;
this.originalRect = null; this.originalRect = null;
this.pages[this.currentPageIndex - 1] = this.currentPage;
} }
}, },
...@@ -1030,6 +1021,8 @@ new Vue({ ...@@ -1030,6 +1021,8 @@ new Vue({
// 选中新创建的分组 // 选中新创建的分组
this.selectGroup(newIndex); this.selectGroup(newIndex);
this.isDataModified = true;
this.pages[this.currentPageIndex - 1] = this.currentPage;
} catch (err) { } catch (err) {
console.error('Error adding new rectangle:', err); console.error('Error adding new rectangle:', err);
this.$message.error('添加新矩形框失败'); this.$message.error('添加新矩形框失败');
...@@ -1109,6 +1102,9 @@ new Vue({ ...@@ -1109,6 +1102,9 @@ new Vue({
// 重新创建所有区域以更新索引 // 重新创建所有区域以更新索引
this.createAllAudioRegions(); this.createAllAudioRegions();
// 激活保存按钮
this.isDataModified = true;
this.$message.success('删除成功'); this.$message.success('删除成功');
} catch (err) { } catch (err) {
console.error('Error deleting group:', err); console.error('Error deleting group:', err);
...@@ -1251,6 +1247,9 @@ new Vue({ ...@@ -1251,6 +1247,9 @@ new Vue({
pickCurrentTime(target) { pickCurrentTime(target) {
if (!this.wavesurfer || this.isPreviewMode) return; if (!this.wavesurfer || this.isPreviewMode) return;
// 激活保存按钮
this.isDataModified = true;
const currentTime = this.wavesurfer.getCurrentTime(); const currentTime = this.wavesurfer.getCurrentTime();
const formattedTime = currentTime.toFixed(2); const formattedTime = currentTime.toFixed(2);
...@@ -1726,19 +1725,27 @@ new Vue({ ...@@ -1726,19 +1725,27 @@ new Vue({
end: this.currentPage.end end: this.currentPage.end
}); });
} }
this.isDataModified = true;
this.pages[this.currentPageIndex - 1] = this.currentPage;
},
handleGroupTextChange(type, value) {
this.isDataModified = true;
}, },
// 处理页面时间变化 // 处理页面时间变化
handlePageTimeChange(type, value) { handlePageTimeChange(type, value) {
if (!this.currentPage || !this.wavesurfer) return; if (!this.currentPage || !this.wavesurfer) return;
try { try {
// 确保时间值有效 // 确保时间值有效
const newTime = Number(value.toFixed(3)); const newTime = Number(Number(value).toFixed(2));
const duration = this.wavesurfer.getDuration(); const duration = this.wavesurfer.getDuration();
if (newTime < 0 || newTime > duration) { if (newTime < 0 || newTime > duration) {
this.$message.warning('时间值超出范围'); this.$message.warning('时间值超出范围');
this.currentPage.start = this.tempPage.start;
this.currentPage.end = this.tempPage.end;
return; return;
} }
...@@ -1746,21 +1753,29 @@ new Vue({ ...@@ -1746,21 +1753,29 @@ new Vue({
if (type === 'start') { if (type === 'start') {
if (newTime >= this.currentPage.end) { if (newTime >= this.currentPage.end) {
this.$message.warning('开始时间不能大于或等于结束时间'); this.$message.warning('开始时间不能大于或等于结束时间');
this.currentPage.start = this.tempPage.start;
this.currentPage.end = this.tempPage.end;
return; return;
} }
this.currentPage.start = newTime; this.currentPage.start = newTime;
this.tempPage.start = newTime;
} else { } else {
if (newTime <= this.currentPage.start) { if (newTime <= this.currentPage.start) {
this.$message.warning('结束时间不能小于或等于开始时间'); this.$message.warning('结束时间不能小于或等于开始时间');
this.currentPage.start = this.tempPage.start;
this.currentPage.end = this.tempPage.end;
return; return;
} }
this.currentPage.end = newTime; this.currentPage.end = newTime;
this.tempPage.end = newTime;
} }
// 更新页面时间范围(这会同步更新区间和锁定标记) // 更新页面时间范围(这会同步更新区间和锁定标记)
this.updatePageTimeRange(); this.updatePageTimeRange();
} catch (err) { } catch (err) {
console.error('Error handling page time change:', err); console.error('Error handling page time change:', err);
this.currentPage.start = this.tempPage.start;
this.currentPage.end = this.tempPage.end;
this.$message.error('时间调整失败'); this.$message.error('时间调整失败');
} }
}, },
...@@ -1972,6 +1987,8 @@ new Vue({ ...@@ -1972,6 +1987,8 @@ new Vue({
if (targetIndex !== this.currentPageIndex) { if (targetIndex !== this.currentPageIndex) {
this.currentPageIndex = targetIndex; this.currentPageIndex = targetIndex;
this.currentPage = targetPage; this.currentPage = targetPage;
// 克隆currentPage
this.tempPage = JSON.parse(JSON.stringify(this.currentPage));
} }
} }
}, },
...@@ -2007,6 +2024,7 @@ new Vue({ ...@@ -2007,6 +2024,7 @@ new Vue({
save() { save() {
if (!this.isDataModified) return; if (!this.isDataModified) return;
// console.log('----save--:'+this.currentPageIndex+':--:'+this.pages[this.currentPageIndex - 1].start);
let data = { let data = {
audio_points: this.audioPoints, audio_points: this.audioPoints,
pages: this.pages pages: this.pages
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment