Commit 2371396a authored by liujiangnan's avatar liujiangnan

feat

parent 0a07f8d1
...@@ -138,21 +138,37 @@ ...@@ -138,21 +138,37 @@
<el-form label-width="70px" v-if="currentPage" style="padding: 10px;"> <el-form label-width="70px" v-if="currentPage" style="padding: 10px;">
<el-form-item label="页面时间"> <el-form-item label="页面时间">
<el-col :span="11"> <el-col :span="11">
<el-input-number <el-input
v-model="currentPage.start" v-model="currentPage.start"
:precision="2" size="small"
:step="0.1"
placeholder="开始时间"> placeholder="开始时间">
</el-input-number> <template slot="append">
<el-button
type="primary"
size="small"
@click="pickCurrentTime('pageStart')"
title="拾取当前时间">
<i class="el-icon-timer"></i>
</el-button>
</template>
</el-input>
</el-col> </el-col>
<el-col class="line" :span="2">-</el-col> <el-col class="line" :span="2">-</el-col>
<el-col :span="11"> <el-col :span="11">
<el-input-number <el-input
v-model="currentPage.end" v-model="currentPage.end"
:precision="2" size="small"
:step="0.1"
placeholder="结束时间"> placeholder="结束时间">
</el-input-number> <template slot="append">
<el-button
type="primary"
size="small"
@click="pickCurrentTime('pageEnd')"
title="拾取当前时间">
<i class="el-icon-timer"></i>
</el-button>
</template>
</el-input>
</el-col> </el-col>
</el-form-item> </el-form-item>
</el-form> </el-form>
...@@ -182,21 +198,37 @@ ...@@ -182,21 +198,37 @@
</el-form-item> </el-form-item>
<el-form-item label="时间范围"> <el-form-item label="时间范围">
<el-col :span="11"> <el-col :span="11">
<el-input-number <el-input
v-model="currentGroup.start" v-model="currentGroup.start"
:precision="2" size="small"
:step="0.1" placeholder="开始时间">
@change="updateAudioRegion"> <template slot="append">
</el-input-number> <el-button
type="primary"
size="small"
@click="pickCurrentTime('groupStart')"
title="拾取当前时间">
<i class="el-icon-timer"></i>
</el-button>
</template>
</el-input>
</el-col> </el-col>
<el-col class="line" :span="2">-</el-col> <el-col class="line" :span="2">-</el-col>
<el-col :span="11"> <el-col :span="11">
<el-input-number <el-input
v-model="currentGroup.end" v-model="currentGroup.end"
:precision="2" size="small"
:step="0.1" placeholder="结束时间">
@change="updateAudioRegion"> <template slot="append">
</el-input-number> <el-button
type="primary"
size="small"
@click="pickCurrentTime('groupEnd')"
title="拾取当前时间">
<i class="el-icon-timer"></i>
</el-button>
</template>
</el-input>
</el-col> </el-col>
</el-form-item> </el-form-item>
<el-form-item label="矩形列表"> <el-form-item label="矩形列表">
...@@ -208,11 +240,7 @@ ...@@ -208,11 +240,7 @@
@current-change="handleRectRowClick"> @current-change="handleRectRowClick">
<el-table-column label="文本内容"> <el-table-column label="文本内容">
<template slot-scope="scope"> <template slot-scope="scope">
<el-input <span>{{ scope.row.text }}</span>
v-model="scope.row.text"
size="mini"
@change="handleRectTextChange(scope.row.text, scope.$index)">
</el-input>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="操作" width="80"> <el-table-column label="操作" width="80">
......
...@@ -36,7 +36,7 @@ new Vue({ ...@@ -36,7 +36,7 @@ new Vue({
isFullscreen: false, isFullscreen: false,
fullscreenImageWidth: 0, fullscreenImageWidth: 0,
fullscreenImageHeight: 0, fullscreenImageHeight: 0,
fullscreenImageRect: null fullscreenImageRect: null,
}, },
mounted() { mounted() {
...@@ -129,6 +129,9 @@ new Vue({ ...@@ -129,6 +129,9 @@ new Vue({
this.wavesurfer.zoom(1); this.wavesurfer.zoom(1);
}); });
// 添加音频处理事件监听
this.wavesurfer.on('audioprocess', this.handleAudioProcess);
// 添加点击波形定位事件 // 添加点击波形定位事件
this.wavesurfer.on('click', (e, progress) => { this.wavesurfer.on('click', (e, progress) => {
// 保存当前位置作为后续缩放的锚点 // 保存当前位置作为后续缩放的锚点
...@@ -490,13 +493,19 @@ new Vue({ ...@@ -490,13 +493,19 @@ new Vue({
itemIndex: this.selectedItemIndex itemIndex: this.selectedItemIndex
}); });
} else if (this.isResizing) { } else if (this.isResizing) {
// 计算新尺寸,确保不超出图片边界 // 计算最小宽度和高度(5像素对应的相对值)
currentRect.width = Math.max(0.1, Math.min(1 - currentRect.x, this.originalRect.width + deltaX)); const minWidth = 5 / this.imageWidth;
currentRect.height = Math.max(0.1, Math.min(1 - currentRect.y, this.originalRect.height + deltaY)); const minHeight = 5 / this.imageHeight;
// 计算新尺寸,确保不超出图片边界且不小于5像素
currentRect.width = Math.max(minWidth, Math.min(1 - currentRect.x, this.originalRect.width + deltaX));
currentRect.height = Math.max(minHeight, Math.min(1 - currentRect.y, this.originalRect.height + deltaY));
console.log('Resizing:', { console.log('Resizing:', {
width: currentRect.width, width: currentRect.width,
height: currentRect.height, height: currentRect.height,
minWidth,
minHeight,
deltaX, deltaX,
deltaY, deltaY,
itemIndex: this.selectedItemIndex itemIndex: this.selectedItemIndex
...@@ -521,13 +530,17 @@ new Vue({ ...@@ -521,13 +530,17 @@ new Vue({
if (!this.currentGroup || this.selectedGroup === null) return; if (!this.currentGroup || this.selectedGroup === null) return;
try { try {
// 确保时间值是数字
const start = parseFloat(this.currentGroup.start) || 0;
const end = parseFloat(this.currentGroup.end) || 0;
const regionId = `${this.currentPageIndex - 1}-${this.selectedGroup}`; const regionId = `${this.currentPageIndex - 1}-${this.selectedGroup}`;
const region = this.audioRegions[regionId]; const region = this.audioRegions[regionId];
if (region) { if (region) {
region.update({ region.update({
start: this.currentGroup.start, start: start,
end: this.currentGroup.end end: end
}); });
} }
} catch (err) { } catch (err) {
...@@ -685,62 +698,6 @@ new Vue({ ...@@ -685,62 +698,6 @@ new Vue({
}); });
}, },
// 处理矩形文本变化
handleRectTextChange(newText, index) {
if (!this.currentGroup) return;
// 获取所有矩形框的文本
const texts = this.currentGroup.group.map(item => item.text);
// 更新英文句子
let sentence = this.currentGroup.sentence;
// 获取所有旧文本在句子中的位置
const positions = [];
let startPos = 0;
// 先找出所有文本在句子中的位置
texts.forEach((text, i) => {
if (i === index) return; // 跳过当前修改的文本
const pos = sentence.indexOf(text, startPos);
if (pos !== -1) {
positions.push({ text, pos, index: i });
startPos = pos + text.length;
}
});
// 按位置排序
positions.sort((a, b) => a.pos - b.pos);
// 找到当前修改文本在句子中的位置
const oldText = texts[index];
let replacePos = -1;
if (positions.length === 0) {
// 如果没有其他文本,直接查找
replacePos = sentence.indexOf(oldText);
} else {
// 在相邻位置之间查找
for (let i = 0; i <= positions.length; i++) {
const start = i === 0 ? 0 : positions[i-1].pos + positions[i-1].text.length;
const end = i === positions.length ? sentence.length : positions[i].pos;
const pos = sentence.slice(start, end).indexOf(oldText);
if (pos !== -1) {
replacePos = start + pos;
break;
}
}
}
// 如果找到位置,替换文本
if (replacePos !== -1) {
sentence = sentence.slice(0, replacePos) + newText + sentence.slice(replacePos + oldText.length);
this.currentGroup.sentence = sentence;
}
},
// 切换全屏模式 // 切换全屏模式
toggleFullscreen() { toggleFullscreen() {
this.isFullscreen = !this.isFullscreen; this.isFullscreen = !this.isFullscreen;
...@@ -834,7 +791,50 @@ new Vue({ ...@@ -834,7 +791,50 @@ new Vue({
width: actualWidth + 'px', width: actualWidth + 'px',
height: actualHeight + 'px' height: actualHeight + 'px'
}; };
} },
// 处理音频播放过程
handleAudioProcess(currentTime) {
if (!this.currentGroup && !this.currentPage) return;
// 格式化时间为两位小数
const formattedTime = currentTime.toFixed(2);
// 更新组时间
if (this.currentGroup) {
this.currentGroup.start = formattedTime;
this.currentGroup.end = formattedTime;
// 更新音频区域
this.updateAudioRegion();
}
// 更新页面时间
if (this.currentPage) {
this.currentPage.start = formattedTime;
this.currentPage.end = formattedTime;
}
},
// 拾取当前时间点
pickCurrentTime(target) {
if (!this.wavesurfer) return;
const currentTime = this.wavesurfer.getCurrentTime();
const formattedTime = currentTime.toFixed(2);
if (target === 'pageStart') {
this.currentPage.start = formattedTime;
} else if (target === 'pageEnd') {
this.currentPage.end = formattedTime;
} else if (target === 'groupStart' && this.currentGroup) {
this.currentGroup.start = formattedTime;
this.updateAudioRegion();
} else if (target === 'groupEnd' && this.currentGroup) {
this.currentGroup.end = formattedTime;
this.updateAudioRegion();
}
},
}, },
beforeDestroy() { beforeDestroy() {
......
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