Commit f02a3818 authored by liujiangnan's avatar liujiangnan

feat: 完成预览功能

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