Commit 1e3c2fff authored by liujiangnan's avatar liujiangnan

暂存换机器

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