Commit 9e17fad3 authored by liujiangnan's avatar liujiangnan

feat: 可以定位页内的时间段了

parent 065fc7f4
......@@ -171,13 +171,13 @@ html, body {
overflow: hidden;
}
#wave-timeline {
height: 20px !important;
position: absolute;
left: 0px;
right: 0px;
bottom: 0px;
overflow: visible;
.time-display {
display: inline-block;
margin-left: 10px;
font-size: 14px;
color: #606266;
min-width: 60px;
text-align: center;
}
.audio-controls {
......@@ -225,25 +225,6 @@ html, body {
margin-left: 10px;
}
/* 时间调整控件样式 */
.time-adjust-controls {
display: flex;
align-items: center;
margin-left: 20px;
padding-left: 20px;
border-left: 1px solid #DCDFE6;
}
.time-label {
font-size: 14px;
color: #606266;
margin-right: 5px;
}
.time-adjust-controls .el-input-number {
margin: 0 5px;
}
/* 确保滑块和按钮在最上层 */
.el-slider {
position: relative;
......@@ -571,33 +552,35 @@ html, body {
}
/* 组区间样式 */
.wavesurfer-region:not([data-id^="page-"]) {
background-color: rgba(64, 158, 255, 0.2);
border: 2px solid rgba(64, 158, 255, 0.5);
.wavesurfer-region[data-id^="group-"] {
background-color: rgba(255, 165, 0, 0.3) !important;
border: 1px solid rgba(255, 165, 0, 0.5) !important;
z-index: 2 !important;
cursor: pointer !important;
}
.wavesurfer-region:not([data-id^="page-"]):hover {
background-color: rgba(64, 158, 255, 0.3) !important;
.wavesurfer-region[data-id^="group-"]:hover {
background-color: rgba(255, 165, 0, 0.4) !important;
}
/* 锁定状态下的标记样式 */
.wavesurfer-region[data-id$="-start"] {
background-color: rgba(0, 255, 0, 0.8) !important;
/* width: 1px !important; */
width: 1px !important;
z-index: 5 !important;
}
.wavesurfer-region[data-id$="-end"] {
background-color: rgba(255, 0, 0, 0.8) !important;
/* width: 1px !important; */
width: 1px !important;
z-index: 5 !important;
}
/* 锁定状态下隐藏非当前页面的区间 */
.page-locked .wavesurfer-region:not([data-id*="-start"]):not([data-id*="-end"]):not([data-id$="-${currentPageIndex-1}"]) {
display: none !important;
.page-locked .wavesurfer-region[data-id^="group-"] {
display: block !important;
background-color: rgba(255, 165, 0, 0.3) !important;
border: 1px solid rgba(255, 165, 0, 0.5) !important;
}
/* 锁定状态下禁用区间拖动 */
......
......@@ -282,7 +282,6 @@
<!-- 波形图区域 -->
<div class="waveform-wrapper" :class="{ 'page-locked': isPageLocked }">
<div id="waveform"></div>
<div id="wave-timeline"></div>
</div>
<!-- 控制按钮区域 -->
......@@ -297,6 +296,8 @@
</el-button>
</el-button-group>
<span class="time-display">{{ currentTime.toFixed(2) }}s</span>
<el-button-group style="margin-left: 10px;">
<el-button size="small" @click="handleZoomOut" :disabled="audioLoading">
<i class="el-icon-zoom-out"></i>
......@@ -316,34 +317,6 @@
{{ isPageLocked ? '解锁页面' : '锁定页面' }}
</el-button>
</div>
<!-- 添加时间调整控件 -->
<div class="time-adjust-controls" v-if="currentGroup">
<span class="time-label">开始时间:</span>
<el-input-number
v-model="currentGroup.start"
:min="0"
:max="currentGroup.end"
:step="0.1"
:precision="3"
size="small"
:disabled="isPageLocked"
@change="handleTimeChange('start', $event)"
style="width: 120px">
</el-input-number>
<span class="time-label" style="margin-left: 10px">结束时间:</span>
<el-input-number
v-model="currentGroup.end"
:min="currentGroup.start"
:max="wavesurfer ? wavesurfer.getDuration() : 999999"
:step="0.1"
:precision="3"
size="small"
:disabled="isPageLocked"
@change="handleTimeChange('end', $event)"
style="width: 120px">
</el-input-number>
</div>
</div>
</div>
</div>
......
......@@ -9,6 +9,7 @@ new Vue({
maxZoom: 500,
zoomStep: 20, // 每次放大/缩小的步长
audioRegions: {},
currentTime: 0, // 添加当前时间
// 数据相关
audioPoints: null,
......@@ -211,18 +212,6 @@ new Vue({
plugins: [
WaveSurfer.regions.create({
dragSelection: false // 禁用拖动选择,避免与我们的区域交互冲突
}),
WaveSurfer.timeline.create({
container: '#wave-timeline',
height: 20,
notchPercentHeight: 50,
primaryFontColor: '#666',
secondaryFontColor: '#888',
primaryColor: '#666',
secondaryColor: '#888',
timeInterval: 0.1,
primaryLabelInterval: 1,
secondaryLabelInterval: 0.5
})
]
});
......@@ -273,28 +262,27 @@ new Vue({
this.currentProgress = progress;
});
// 添加播放进度监听
// 添加时间更新事件监听
this.wavesurfer.on('audioprocess', () => {
this.currentTime = this.wavesurfer.getCurrentTime();
if (this.isPageLocked) {
const currentTime = this.wavesurfer.getCurrentTime();
if (currentTime < this.lockedPageStart) {
// 如果播放位置在锁定区间之前,跳转到区间开始
if (this.currentTime < this.lockedPageStart) {
this.wavesurfer.seekTo(this.lockedPageStart / this.wavesurfer.getDuration());
} else if (currentTime > this.lockedPageEnd) {
// 如果播放位置超过区间结束,停止播放
} else if (this.currentTime > this.lockedPageEnd) {
this.wavesurfer.pause();
this.isPlaying = false;
}
}
});
// 添加定位完成事件监听
// 添加 seek 事件监听,更新时间显示
this.wavesurfer.on('seek', () => {
this.currentTime = this.wavesurfer.getCurrentTime();
if (this.isPageLocked) {
const currentTime = this.wavesurfer.getCurrentTime();
if (currentTime < this.lockedPageStart || currentTime > this.lockedPageEnd) {
// 如果定位到锁定区间外,重置到区间内
if (currentTime < this.lockedPageStart) {
if (this.currentTime < this.lockedPageStart || this.currentTime > this.lockedPageEnd) {
if (this.currentTime < this.lockedPageStart) {
this.wavesurfer.seekTo(this.lockedPageStart / this.wavesurfer.getDuration());
} else {
this.wavesurfer.seekTo(this.lockedPageEnd / this.wavesurfer.getDuration());
......@@ -440,11 +428,32 @@ new Vue({
// 添加区间更新事件处理
region.on('update-end', () => {
// 检查是否与其他区间重叠
const isOverlapping = this.checkOverlap(region, groupIndex);
// 检查是否超出页面范围
const isOutOfBounds = region.start < this.lockedPageStart || region.end > this.lockedPageEnd;
if (isOverlapping || isOutOfBounds) {
// 如果有重叠或超出范围,恢复到原始位置
region.update({
start: group.start,
end: group.end
});
if (isOverlapping) {
this.$message.warning('区间不能重叠');
} else {
this.$message.warning('不能超出页面范围');
}
return;
}
// 更新组的时间范围
group.start = Number(region.start.toFixed(3));
group.end = Number(region.end.toFixed(3));
// 如果当前选中的就是这个组,更新编辑器中的值
if (this.selectedGroup === groupIndex && this.currentPageIndex - 1 === pageIndex) {
if (this.selectedGroup === groupIndex) {
this.currentGroup = group;
}
});
......@@ -457,6 +466,91 @@ new Vue({
}
});
// 重新创建组区间,使用与页面区间相似的样式
if (this.currentPage.groups) {
this.currentPage.groups.forEach((group, groupIndex) => {
if (typeof group.start === 'number' && typeof group.end === 'number') {
const groupRegionId = `group-${groupIndex}`;
const region = this.wavesurfer.addRegion({
id: groupRegionId,
start: group.start,
end: group.end,
color: 'rgba(255, 165, 0, 0.3)',
drag: true, // 允许拖动
resize: true, // 允许调整大小
attributes: {
label: `Group ${groupIndex + 1}`
}
});
if (region) {
this.audioRegions[groupRegionId] = region;
// 修改点击事件处理
const handleClick = (event) => {
event.stopPropagation();
event.preventDefault();
// 定位到区间开始位置
const duration = this.wavesurfer.getDuration();
this.wavesurfer.seekTo(group.start / duration);
// 选中对应的组
this.selectedGroup = groupIndex;
this.currentGroup = group;
// 如果有第一个矩形,选中它
if (group.group && group.group.length > 0) {
this.selectedItemIndex = 0;
}
};
region.element.removeEventListener('click', handleClick);
region.element.addEventListener('click', handleClick);
// 添加区间更新事件处理
region.on('update-end', () => {
// 检查是否与其他区间重叠
const isOverlapping = this.checkOverlap(region, groupIndex);
// 检查是否超出页面范围
const isOutOfBounds = region.start < this.lockedPageStart || region.end > this.lockedPageEnd;
if (isOverlapping || isOutOfBounds) {
// 如果有重叠或超出范围,恢复到原始位置
region.update({
start: group.start,
end: group.end
});
if (isOverlapping) {
this.$message.warning('区间不能重叠');
} else {
this.$message.warning('不能超出页面范围');
}
return;
}
// 更新组的时间范围
group.start = Number(region.start.toFixed(3));
group.end = Number(region.end.toFixed(3));
// 如果当前选中的就是这个组,更新编辑器中的值
if (this.selectedGroup === groupIndex) {
this.currentGroup = group;
}
});
// 确保区间样式正确
this.$nextTick(() => {
if (region.element) {
region.element.style.backgroundColor = 'rgba(255, 165, 0, 0.3)';
region.element.style.border = '1px solid rgba(255, 165, 0, 0.5)';
}
});
}
}
});
}
} catch (err) {
console.error('Error in createAllAudioRegions:', err);
}
......@@ -1400,32 +1494,86 @@ new Vue({
});
}
// 重新创建组区间
// 重新创建组区间,使用与页面区间相似的样式
if (this.currentPage.groups) {
this.currentPage.groups.forEach((group, groupIndex) => {
if (typeof group.start === 'number' && typeof group.end === 'number') {
const groupRegionId = `${this.currentPageIndex - 1}-${groupIndex}`;
const groupRegionId = `group-${groupIndex}`;
const region = this.wavesurfer.addRegion({
id: groupRegionId,
start: group.start,
end: group.end,
color: 'rgba(64, 158, 255, 0.4)',
drag: false,
resize: false,
opacity: 1
color: 'rgba(255, 165, 0, 0.3)',
drag: true, // 允许拖动
resize: true, // 允许调整大小
attributes: {
label: `Group ${groupIndex + 1}`
}
});
if (region) {
this.audioRegions[groupRegionId] = region;
// 添加点击事件
// 修改点击事件处理
const handleClick = (event) => {
event.stopPropagation();
event.preventDefault();
this.startRegionPlayback(group.start, group.end, groupRegionId);
// 定位到区间开始位置
const duration = this.wavesurfer.getDuration();
this.wavesurfer.seekTo(group.start / duration);
// 选中对应的组
this.selectedGroup = groupIndex;
this.currentGroup = group;
// 如果有第一个矩形,选中它
if (group.group && group.group.length > 0) {
this.selectedItemIndex = 0;
}
};
region.element.removeEventListener('click', handleClick);
region.element.addEventListener('click', handleClick);
// 添加区间更新事件处理
region.on('update-end', () => {
// 检查是否与其他区间重叠
const isOverlapping = this.checkOverlap(region, groupIndex);
// 检查是否超出页面范围
const isOutOfBounds = region.start < this.lockedPageStart || region.end > this.lockedPageEnd;
if (isOverlapping || isOutOfBounds) {
// 如果有重叠或超出范围,恢复到原始位置
region.update({
start: group.start,
end: group.end
});
if (isOverlapping) {
this.$message.warning('区间不能重叠');
} else {
this.$message.warning('不能超出页面范围');
}
return;
}
// 更新组的时间范围
group.start = Number(region.start.toFixed(3));
group.end = Number(region.end.toFixed(3));
// 如果当前选中的就是这个组,更新编辑器中的值
if (this.selectedGroup === groupIndex) {
this.currentGroup = group;
}
});
// 确保区间样式正确
this.$nextTick(() => {
if (region.element) {
region.element.style.backgroundColor = 'rgba(255, 165, 0, 0.3)';
region.element.style.border = '1px solid rgba(255, 165, 0, 0.5)';
}
});
}
}
});
......@@ -1682,6 +1830,18 @@ new Vue({
}
}
},
// 添加检查区间重叠的方法
checkOverlap(currentRegion, currentIndex) {
if (!this.currentPage || !this.currentPage.groups) return false;
return this.currentPage.groups.some((group, index) => {
if (index === currentIndex) return false; // 跳过当前区间
// 检查是否有重叠
return (currentRegion.start < group.end && currentRegion.end > group.start);
});
},
},
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