Commit 0177e9da authored by liujiangnan's avatar liujiangnan

feat:

parent e9c2dd1d
...@@ -178,6 +178,25 @@ html, body { ...@@ -178,6 +178,25 @@ html, body {
z-index: 4; z-index: 4;
} }
/* 添加时间调整控件样式 */
.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;
}
/* 分页器样式 */ /* 分页器样式 */
.pagination-container { .pagination-container {
position: fixed; position: fixed;
...@@ -327,7 +346,28 @@ html, body { ...@@ -327,7 +346,28 @@ html, body {
cursor: pointer !important; cursor: pointer !important;
} }
/* 区间拖拽手柄样式 */
.wavesurfer-handle { .wavesurfer-handle {
display: block !important;
position: absolute !important;
height: 100% !important;
width: 8px !important;
top: 0 !important;
cursor: ew-resize !important;
z-index: 3 !important;
background: transparent !important;
}
.wavesurfer-handle-start {
left: 0 !important;
}
.wavesurfer-handle-end {
right: 0 !important;
}
/* 禁用状态下的手柄样式 */
.wavesurfer-region[data-drag="false"] .wavesurfer-handle {
display: none !important; display: none !important;
} }
......
...@@ -307,6 +307,34 @@ ...@@ -307,6 +307,34 @@
<i :class="isPageLocked ? 'el-icon-lock' : 'el-icon-unlock'"></i> <i :class="isPageLocked ? 'el-icon-lock' : 'el-icon-unlock'"></i>
{{ isPageLocked ? '解锁页面' : '锁定页面' }} {{ isPageLocked ? '解锁页面' : '锁定页面' }}
</el-button> </el-button>
<!-- 添加时间调整控件 -->
<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> </div>
</el-card> </el-card>
......
...@@ -314,7 +314,6 @@ new Vue({ ...@@ -314,7 +314,6 @@ new Vue({
if (page.groups && page.groups.length > 0) { if (page.groups && page.groups.length > 0) {
// 找出所有有效的时间点 // 找出所有有效的时间点
const validTimes = page.groups.reduce((acc, group) => { const validTimes = page.groups.reduce((acc, group) => {
// 确保时间值是有效的数字且精确到小数点后3位
if (typeof group.start === 'number' && !isNaN(group.start)) { if (typeof group.start === 'number' && !isNaN(group.start)) {
acc.starts.push(Number(group.start.toFixed(3))); acc.starts.push(Number(group.start.toFixed(3)));
} }
...@@ -325,11 +324,9 @@ new Vue({ ...@@ -325,11 +324,9 @@ new Vue({
}, { starts: [], ends: [] }); }, { starts: [], ends: [] });
if (validTimes.starts.length > 0 && validTimes.ends.length > 0) { if (validTimes.starts.length > 0 && validTimes.ends.length > 0) {
// 使用精确的最小和最大值
const start = Math.min(...validTimes.starts); const start = Math.min(...validTimes.starts);
const end = Math.max(...validTimes.ends); const end = Math.max(...validTimes.ends);
// 确保开始时间小于结束时间
if (start < end) { if (start < end) {
pageRanges.push({ pageRanges.push({
pageIndex, pageIndex,
...@@ -354,8 +351,8 @@ new Vue({ ...@@ -354,8 +351,8 @@ new Vue({
start: range.start, start: range.start,
end: range.end, end: range.end,
color: 'rgba(255, 192, 203, 0.3)', color: 'rgba(255, 192, 203, 0.3)',
drag: false, drag: !this.isPageLocked,
resize: false, resize: !this.isPageLocked,
attributes: { attributes: {
label: `Page ${range.pageIndex + 1}` label: `Page ${range.pageIndex + 1}`
} }
...@@ -366,35 +363,25 @@ new Vue({ ...@@ -366,35 +363,25 @@ new Vue({
// 添加点击事件处理 // 添加点击事件处理
const handleClick = (event) => { const handleClick = (event) => {
// 阻止事件冒泡
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
// 检查页面锁定状态
if (this.isPageLocked && range.pageIndex !== this.currentPageIndex - 1) { if (this.isPageLocked && range.pageIndex !== this.currentPageIndex - 1) {
this.$message.warning('页面已锁定,请先解锁'); this.$message.warning('页面已锁定,请先解锁');
return; return;
} }
// 切换到对应的页面
this.currentPageIndex = range.pageIndex + 1; this.currentPageIndex = range.pageIndex + 1;
this.currentPage = this.pages[range.pageIndex]; this.currentPage = this.pages[range.pageIndex];
// 取消当前选中的组
this.selectedGroup = null; this.selectedGroup = null;
this.currentGroup = null; this.currentGroup = null;
// 将区域滚动到视图中心并播放
this.$nextTick(() => { this.$nextTick(() => {
// 开始播放
this.startRegionPlayback(range.start, range.end, pageRegionId); this.startRegionPlayback(range.start, range.end, pageRegionId);
// 更新所有区域的样式
this.updateRegionsStyle(); this.updateRegionsStyle();
}); });
}; };
// 确保事件监听器只添加一次
region.element.removeEventListener('click', handleClick); region.element.removeEventListener('click', handleClick);
region.element.addEventListener('click', handleClick); region.element.addEventListener('click', handleClick);
} }
...@@ -407,7 +394,6 @@ new Vue({ ...@@ -407,7 +394,6 @@ new Vue({
this.pages.forEach((page, pageIndex) => { this.pages.forEach((page, pageIndex) => {
if (page.groups) { if (page.groups) {
page.groups.forEach((group, groupIndex) => { page.groups.forEach((group, groupIndex) => {
// 确保时间值是有效的数字且精确到小数点后3位
const start = typeof group.start === 'number' && !isNaN(group.start) ? const start = typeof group.start === 'number' && !isNaN(group.start) ?
Number(group.start.toFixed(3)) : null; Number(group.start.toFixed(3)) : null;
const end = typeof group.end === 'number' && !isNaN(group.end) ? const end = typeof group.end === 'number' && !isNaN(group.end) ?
...@@ -418,31 +404,65 @@ new Vue({ ...@@ -418,31 +404,65 @@ new Vue({
const isCurrentPage = pageIndex === this.currentPageIndex - 1; const isCurrentPage = pageIndex === this.currentPageIndex - 1;
try { try {
// 更新区间创建逻辑,添加左右边界拖拽功能
const region = this.wavesurfer.addRegion({ const region = this.wavesurfer.addRegion({
id: groupRegionId, id: groupRegionId,
start: start, start: start,
end: end, end: end,
color: isCurrentPage ? 'rgba(64, 158, 255, 0.2)' : 'rgba(144, 147, 153, 0.1)', color: isCurrentPage ? 'rgba(64, 158, 255, 0.2)' : 'rgba(144, 147, 153, 0.1)',
drag: isCurrentPage, drag: isCurrentPage && !this.isPageLocked,
resize: isCurrentPage resize: isCurrentPage && !this.isPageLocked,
dragLeft: isCurrentPage && !this.isPageLocked, // 允许拖动左边界
dragRight: isCurrentPage && !this.isPageLocked, // 允许拖动右边界
opacity: (!this.isPageLocked || isCurrentPage) ? 1 : 0.3,
handleStyle: {
left: {
backgroundColor: '#409EFF',
width: '8px',
height: '100%',
cursor: 'ew-resize'
},
right: {
backgroundColor: '#409EFF',
width: '8px',
height: '100%',
cursor: 'ew-resize'
}
}
}); });
if (region) { if (region) {
this.audioRegions[groupRegionId] = region; this.audioRegions[groupRegionId] = region;
// 为组区间添加点击播放功能
const handleGroupClick = (event) => { const handleGroupClick = (event) => {
// 阻止事件冒泡
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
// 开始播放 // 锁定状态下只允许播放当前页面的区间
if (this.isPageLocked && !isCurrentPage) {
this.$message.warning('页面已锁定,只能播放当前页面的区间');
return;
}
this.startRegionPlayback(start, end, groupRegionId); this.startRegionPlayback(start, end, groupRegionId);
}; };
// 确保事件监听器只添加一次
region.element.removeEventListener('click', handleGroupClick); region.element.removeEventListener('click', handleGroupClick);
region.element.addEventListener('click', handleGroupClick); region.element.addEventListener('click', handleGroupClick);
// 添加区间更新事件处理
region.on('update-end', () => {
const group = this.currentPage.groups[groupIndex];
if (group) {
group.start = Number(region.start.toFixed(3));
group.end = Number(region.end.toFixed(3));
// 如果当前选中的就是这个组,更新编辑器中的值
if (this.selectedGroup === groupIndex) {
this.currentGroup = group;
}
}
});
} }
} catch (err) { } catch (err) {
console.error(`Error creating group region ${groupRegionId}:`, err); console.error(`Error creating group region ${groupRegionId}:`, err);
...@@ -1231,14 +1251,21 @@ new Vue({ ...@@ -1231,14 +1251,21 @@ new Vue({
// 如果正在播放,先停止 // 如果正在播放,先停止
this.stopCurrentPlayback(); this.stopCurrentPlayback();
// 获取区间的最新时间值
const region = this.audioRegions[regionId];
if (!region) return;
const currentStart = region.start;
const currentEnd = region.end;
// 开始新的播放 // 开始新的播放
this.wavesurfer.seekTo(start / this.wavesurfer.getDuration()); this.wavesurfer.seekTo(currentStart / this.wavesurfer.getDuration());
this.wavesurfer.play(); this.wavesurfer.play();
this.isPlaying = true; this.isPlaying = true;
this.currentPlayingRegion = regionId; this.currentPlayingRegion = regionId;
// 设置新的定时器 // 设置新的定时器
const playDuration = (end - start) * 1000; // 转换为毫秒 const playDuration = (currentEnd - currentStart) * 1000; // 转换为毫秒
this.playTimer = setTimeout(() => { this.playTimer = setTimeout(() => {
if (this.isPlaying && this.currentPlayingRegion === regionId) { if (this.isPlaying && this.currentPlayingRegion === regionId) {
this.wavesurfer.pause(); this.wavesurfer.pause();
...@@ -1299,9 +1326,8 @@ new Vue({ ...@@ -1299,9 +1326,8 @@ new Vue({
region.update({ region.update({
color: 'rgba(255, 192, 203, 0.3)', color: 'rgba(255, 192, 203, 0.3)',
drag: false, drag: !this.isPageLocked, // 锁定状态下不可拖动
resize: false, resize: !this.isPageLocked, // 锁定状态下不可调整大小
// 锁定状态下,非当前页区间变暗
opacity: (!this.isPageLocked || isCurrentPage) ? 1 : 0.3 opacity: (!this.isPageLocked || isCurrentPage) ? 1 : 0.3
}); });
...@@ -1324,6 +1350,98 @@ new Vue({ ...@@ -1324,6 +1350,98 @@ new Vue({
}); });
}); });
}, },
// 新增:更新页面时间范围
updatePageTimeRange(type, value) {
if (!this.currentPage || this.isPageLocked) return;
const time = Number(value);
if (isNaN(time)) return;
// 获取当前页的区间ID
const pageRegionId = `page-${this.currentPageIndex - 1}`;
const region = this.audioRegions[pageRegionId];
if (!region) return;
if (type === 'start') {
// 确保开始时间不大于结束时间
if (time < region.end) {
region.update({
start: time
});
this.currentPage.start = time;
} else {
this.$message.warning('开始时间不能大于结束时间');
// 重置输入值
this.currentPage.start = region.start;
}
} else if (type === 'end') {
// 确保结束时间不小于开始时间
if (time > region.start) {
region.update({
end: time
});
this.currentPage.end = time;
} else {
this.$message.warning('结束时间不能小于开始时间');
// 重置输入值
this.currentPage.end = region.end;
}
}
},
// 处理时间调整
handleTimeChange(type, value) {
if (!this.currentGroup || !this.wavesurfer || this.isPageLocked) return;
try {
// 确保时间值有效
const newTime = Number(value.toFixed(3));
const duration = this.wavesurfer.getDuration();
if (newTime < 0 || newTime > duration) {
this.$message.warning('时间值超出范围');
return;
}
// 更新时间值
if (type === 'start') {
if (newTime >= this.currentGroup.end) {
this.$message.warning('开始时间不能大于或等于结束时间');
this.currentGroup.start = Number((this.currentGroup.end - 0.1).toFixed(3));
return;
}
this.currentGroup.start = newTime;
} else {
if (newTime <= this.currentGroup.start) {
this.$message.warning('结束时间不能小于或等于开始时间');
this.currentGroup.end = Number((this.currentGroup.start + 0.1).toFixed(3));
return;
}
this.currentGroup.end = newTime;
}
// 更新音频区域
if (this.selectedGroup !== null) {
const regionId = `${this.currentPageIndex - 1}-${this.selectedGroup}`;
const region = this.audioRegions[regionId];
if (region) {
region.update({
start: this.currentGroup.start,
end: this.currentGroup.end
});
}
}
// 如果正在播放该区间,重新开始播放
if (this.currentPlayingRegion === `${this.currentPageIndex - 1}-${this.selectedGroup}`) {
this.startRegionPlayback(this.currentGroup.start, this.currentGroup.end, this.currentPlayingRegion);
}
} catch (err) {
console.error('Error handling time change:', err);
this.$message.error('时间调整失败');
}
},
}, },
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