Commit f02a3818 authored by liujiangnan's avatar liujiangnan

feat: 完成预览功能

parent a2155bca
...@@ -695,6 +695,11 @@ html, body { ...@@ -695,6 +695,11 @@ html, body {
opacity: 1 !important; opacity: 1 !important;
} }
.preview-mode .el-slider {
pointer-events: auto !important;
opacity: 1 !important;
}
/* 预览按钮激活状态 */ /* 预览按钮激活状态 */
.basic-controls .el-button.is-preview { .basic-controls .el-button.is-preview {
color: #f56c6c; color: #f56c6c;
......
...@@ -300,12 +300,12 @@ ...@@ -300,12 +300,12 @@
<el-button @click="handleZoomOut" :disabled="!wavesurfer || audioLoading || zoomLevel <= minZoom"> <el-button @click="handleZoomOut" :disabled="!wavesurfer || audioLoading || zoomLevel <= minZoom">
<i class="el-icon-zoom-out"></i> <i class="el-icon-zoom-out"></i>
</el-button> </el-button>
<el-button @click="togglePageLock" :disabled="!wavesurfer || audioLoading || !currentPage"> <el-button @click="togglePageLock" :disabled="!wavesurfer || audioLoading || !currentPage || isPreviewMode">
<i :class="isPageLocked ? 'el-icon-lock' : 'el-icon-unlock'"></i> <i :class="isPageLocked ? 'el-icon-lock' : 'el-icon-unlock'"></i>
</el-button> </el-button>
<el-button <el-button
@click="togglePreviewMode" @click="togglePreviewMode"
:disabled="!wavesurfer || audioLoading || isPageLocked" :disabled="!wavesurfer || audioLoading"
:type="isPreviewMode ? 'danger' : 'default'" :type="isPreviewMode ? 'danger' : 'default'"
> >
<i :class="isPreviewMode ? 'el-icon-switch-button' : 'el-icon-view'"></i> <i :class="isPreviewMode ? 'el-icon-switch-button' : 'el-icon-view'"></i>
......
...@@ -313,6 +313,14 @@ new Vue({ ...@@ -313,6 +313,14 @@ new Vue({
} }
} }
} }
// 在预览模式下,手动调整位置时也同步页面和组的选中状态
if (this.isPreviewMode) {
// 重置最后检查时间,确保定时器能立即开始新的检查
this.lastCheckedTime = 0;
this.checkAndSwitchPage(this.currentTime);
this.checkAndSelectGroup(this.currentTime);
}
}); });
// 加载音频 // 加载音频
...@@ -1839,6 +1847,7 @@ new Vue({ ...@@ -1839,6 +1847,7 @@ new Vue({
// 新增:切换预览模式 // 新增:切换预览模式
togglePreviewMode() { togglePreviewMode() {
// 如果页面处于锁定状态,提示用户先解锁
if (this.isPageLocked) { if (this.isPageLocked) {
this.$message.warning('请先解锁页面'); this.$message.warning('请先解锁页面');
return; return;
...@@ -1890,20 +1899,18 @@ new Vue({ ...@@ -1890,20 +1899,18 @@ new Vue({
// 创建新的监听定时器 // 创建新的监听定时器
this.previewTimer = setInterval(() => { this.previewTimer = setInterval(() => {
if (!this.isPlaying || !this.isPreviewMode) return; if (!this.isPreviewMode) return;
const currentTime = this.wavesurfer.getCurrentTime(); const currentTime = this.wavesurfer.getCurrentTime();
// 优化:每100ms才检查一次,避免过于频繁 // 优化:每50ms检查一次
if (currentTime - this.lastCheckedTime < 0.1) return; if (currentTime - this.lastCheckedTime < 0.05) return;
this.lastCheckedTime = currentTime; this.lastCheckedTime = currentTime;
// 检查是否需要切换页面 // 检查是否需要切换页面和选中组
this.checkAndSwitchPage(currentTime); this.checkAndSwitchPage(currentTime);
// 检查是否需要选中组
this.checkAndSelectGroup(currentTime); this.checkAndSelectGroup(currentTime);
}, 100); // 100ms检查一次 }, 50);
}, },
// 新增:停止预览监听 // 新增:停止预览监听
...@@ -1916,16 +1923,18 @@ new Vue({ ...@@ -1916,16 +1923,18 @@ new Vue({
// 新增:检查并切换页面 // 新增:检查并切换页面
checkAndSwitchPage(currentTime) { checkAndSwitchPage(currentTime) {
for (let i = 0; i < this.pages.length; i++) { if (!this.pages || !this.pages.length) return;
const page = this.pages[i];
if (page.start <= currentTime && currentTime <= page.end) { // 找到当前时间所在的页面
if (this.currentPageIndex !== i + 1) { const targetPage = this.pages.find(page =>
this.currentPageIndex = i + 1; currentTime >= page.start && currentTime <= page.end
this.currentPage = page; );
this.selectedGroup = null;
this.currentGroup = null; if (targetPage) {
} const targetIndex = this.pages.indexOf(targetPage) + 1;
break; if (targetIndex !== this.currentPageIndex) {
this.currentPageIndex = targetIndex;
this.currentPage = targetPage;
} }
} }
}, },
...@@ -1934,21 +1943,17 @@ new Vue({ ...@@ -1934,21 +1943,17 @@ new Vue({
checkAndSelectGroup(currentTime) { checkAndSelectGroup(currentTime) {
if (!this.currentPage || !this.currentPage.groups) return; if (!this.currentPage || !this.currentPage.groups) return;
let found = false; // 找到当前时间所在的组
for (let i = 0; i < this.currentPage.groups.length; i++) { const targetGroup = this.currentPage.groups.findIndex(group =>
const group = this.currentPage.groups[i]; currentTime >= group.start && currentTime <= group.end
if (group.start <= currentTime && currentTime <= group.end) { );
if (this.selectedGroup !== i) {
this.selectedGroup = i;
this.currentGroup = group;
}
found = true;
break;
}
}
// 如果不在任何组的时间范围内,取消选中 if (targetGroup !== -1) {
if (!found && this.selectedGroup !== null) { if (this.selectedGroup !== targetGroup) {
this.selectedGroup = targetGroup;
this.currentGroup = this.currentPage.groups[targetGroup];
}
} else {
this.selectedGroup = null; this.selectedGroup = null;
this.currentGroup = null; this.currentGroup = null;
} }
......
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