Commit e9c2dd1d authored by liujiangnan's avatar liujiangnan

feat: 锁定页面

parent 0d5b7a31
...@@ -272,7 +272,8 @@ ...@@ -272,7 +272,8 @@
:current-page.sync="currentPageIndex" :current-page.sync="currentPageIndex"
:page-size="1" :page-size="1"
layout="prev, pager, next" layout="prev, pager, next"
:total="pages.length"> :total="pages.length"
:disabled="isPageLocked">
</el-pagination> </el-pagination>
</div> </div>
...@@ -298,6 +299,14 @@ ...@@ -298,6 +299,14 @@
:disabled="audioLoading" :disabled="audioLoading"
style="width: 200px; margin-left: 20px;"> style="width: 200px; margin-left: 20px;">
</el-slider> </el-slider>
<el-button
size="small"
:type="isPageLocked ? 'danger' : 'primary'"
@click="togglePageLock"
style="margin-left: 20px;">
<i :class="isPageLocked ? 'el-icon-lock' : 'el-icon-unlock'"></i>
{{ isPageLocked ? '解锁页面' : '锁定页面' }}
</el-button>
</div> </div>
</div> </div>
</el-card> </el-card>
......
...@@ -45,6 +45,11 @@ new Vue({ ...@@ -45,6 +45,11 @@ new Vue({
// 新增:播放控制相关 // 新增:播放控制相关
playTimer: null, playTimer: null,
currentPlayingRegion: null, currentPlayingRegion: null,
// 新增:页面锁定相关
isPageLocked: false,
lockedPageStart: null,
lockedPageEnd: null,
}, },
mounted() { mounted() {
...@@ -228,10 +233,53 @@ new Vue({ ...@@ -228,10 +233,53 @@ new Vue({
// 添加点击波形定位事件 // 添加点击波形定位事件
this.wavesurfer.on('click', (e, progress) => { this.wavesurfer.on('click', (e, progress) => {
if (this.isPageLocked) {
const clickTime = progress * this.wavesurfer.getDuration();
if (clickTime < this.lockedPageStart || clickTime > this.lockedPageEnd) {
this.$message.warning('当前位置超出锁定页面范围');
// 将光标重置回锁定区间内
if (clickTime < this.lockedPageStart) {
this.wavesurfer.seekTo(this.lockedPageStart / this.wavesurfer.getDuration());
} else {
this.wavesurfer.seekTo(this.lockedPageEnd / this.wavesurfer.getDuration());
}
return;
}
}
// 保存当前位置作为后续缩放的锚点 // 保存当前位置作为后续缩放的锚点
this.currentProgress = progress; this.currentProgress = progress;
}); });
// 添加播放进度监听
this.wavesurfer.on('audioprocess', () => {
if (this.isPageLocked) {
const currentTime = this.wavesurfer.getCurrentTime();
if (currentTime < this.lockedPageStart) {
// 如果播放位置在锁定区间之前,跳转到区间开始
this.wavesurfer.seekTo(this.lockedPageStart / this.wavesurfer.getDuration());
} else if (currentTime > this.lockedPageEnd) {
// 如果播放位置超过区间结束,停止播放
this.wavesurfer.pause();
this.isPlaying = false;
}
}
});
// 添加定位完成事件监听
this.wavesurfer.on('seek', () => {
if (this.isPageLocked) {
const currentTime = this.wavesurfer.getCurrentTime();
if (currentTime < this.lockedPageStart || currentTime > this.lockedPageEnd) {
// 如果定位到锁定区间外,重置到区间内
if (currentTime < this.lockedPageStart) {
this.wavesurfer.seekTo(this.lockedPageStart / this.wavesurfer.getDuration());
} else {
this.wavesurfer.seekTo(this.lockedPageEnd / this.wavesurfer.getDuration());
}
}
}
});
this.wavesurfer.on('error', (err) => { this.wavesurfer.on('error', (err) => {
console.error('WaveSurfer error:', err); console.error('WaveSurfer error:', err);
this.$message.error('音频加载失败'); this.$message.error('音频加载失败');
...@@ -322,6 +370,12 @@ new Vue({ ...@@ -322,6 +370,12 @@ new Vue({
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
// 检查页面锁定状态
if (this.isPageLocked && range.pageIndex !== this.currentPageIndex - 1) {
this.$message.warning('页面已锁定,请先解锁');
return;
}
// 切换到对应的页面 // 切换到对应的页面
this.currentPageIndex = range.pageIndex + 1; this.currentPageIndex = range.pageIndex + 1;
this.currentPage = this.pages[range.pageIndex]; this.currentPage = this.pages[range.pageIndex];
...@@ -336,26 +390,7 @@ new Vue({ ...@@ -336,26 +390,7 @@ new Vue({
this.startRegionPlayback(range.start, range.end, pageRegionId); this.startRegionPlayback(range.start, range.end, pageRegionId);
// 更新所有区域的样式 // 更新所有区域的样式
Object.keys(this.audioRegions).forEach(regionId => { this.updateRegionsStyle();
const region = this.audioRegions[regionId];
if (!region) return;
if (regionId.startsWith('page-')) {
region.update({
color: 'rgba(255, 192, 203, 0.3)'
});
return;
}
const [rPageIndex, groupIndex] = regionId.split('-').map(Number);
const isCurrentPage = rPageIndex === range.pageIndex;
region.update({
color: isCurrentPage ? 'rgba(64, 158, 255, 0.2)' : 'rgba(144, 147, 153, 0.1)',
drag: isCurrentPage,
resize: isCurrentPage
});
});
}); });
}; };
...@@ -520,6 +555,14 @@ new Vue({ ...@@ -520,6 +555,14 @@ new Vue({
if (!this.wavesurfer) return; if (!this.wavesurfer) return;
try { try {
// 如果页面已锁定,限制播放范围
if (this.isPageLocked) {
const currentTime = this.wavesurfer.getCurrentTime();
if (currentTime < this.lockedPageStart || currentTime > this.lockedPageEnd) {
this.wavesurfer.seekTo(this.lockedPageStart / this.wavesurfer.getDuration());
}
}
// 如果正在区间播放,先清理 // 如果正在区间播放,先清理
if (this.currentPlayingRegion) { if (this.currentPlayingRegion) {
this.stopCurrentPlayback(); this.stopCurrentPlayback();
...@@ -528,6 +571,17 @@ new Vue({ ...@@ -528,6 +571,17 @@ new Vue({
this.wavesurfer.playPause(); this.wavesurfer.playPause();
this.isPlaying = !this.isPlaying; this.isPlaying = !this.isPlaying;
// 如果是锁定状态下的播放,需要在结束位置停止
if (this.isPageLocked && this.isPlaying) {
const remainingTime = (this.lockedPageEnd - this.wavesurfer.getCurrentTime()) * 1000;
this.playTimer = setTimeout(() => {
if (this.isPlaying) {
this.wavesurfer.pause();
this.isPlaying = false;
}
}, remainingTime);
}
// 播放时保存当前位置作为缩放锚点 // 播放时保存当前位置作为缩放锚点
if (this.isPlaying) { if (this.isPlaying) {
this.currentProgress = this.wavesurfer.getCurrentTime() / this.wavesurfer.getDuration(); this.currentProgress = this.wavesurfer.getCurrentTime() / this.wavesurfer.getDuration();
...@@ -601,6 +655,16 @@ new Vue({ ...@@ -601,6 +655,16 @@ new Vue({
handlePageChange(page) { handlePageChange(page) {
if (!this.wavesurfer) return; if (!this.wavesurfer) return;
// 检查页面锁定状态
if (this.isPageLocked) {
this.$message.warning('页面已锁定,请先解锁');
// 重置回当前页码
this.$nextTick(() => {
this.currentPageIndex = this.currentPageIndex;
});
return;
}
try { try {
const index = page - 1; const index = page - 1;
this.currentPage = this.pages[index]; this.currentPage = this.pages[index];
...@@ -608,28 +672,7 @@ new Vue({ ...@@ -608,28 +672,7 @@ new Vue({
this.currentGroup = null; this.currentGroup = null;
// 更新所有区域的样式 // 更新所有区域的样式
Object.keys(this.audioRegions).forEach(regionId => { this.updateRegionsStyle();
const region = this.audioRegions[regionId];
if (!region) return;
// 如果是页面区间,设置为默认颜色
if (regionId.startsWith('page-')) {
region.update({
color: 'rgba(255, 192, 203, 0.3)'
});
return;
}
// 处理组区间
const [pageIndex, groupIndex] = regionId.split('-').map(Number);
const isCurrentPage = pageIndex === index;
region.update({
color: isCurrentPage ? 'rgba(64, 158, 255, 0.2)' : 'rgba(144, 147, 153, 0.1)',
drag: isCurrentPage,
resize: isCurrentPage
});
});
// 定位到当前页面的时间范围(如果有) // 定位到当前页面的时间范围(如果有)
if (this.currentPage && this.currentPage.groups && this.currentPage.groups.length > 0) { if (this.currentPage && this.currentPage.groups && this.currentPage.groups.length > 0) {
...@@ -1177,6 +1220,14 @@ new Vue({ ...@@ -1177,6 +1220,14 @@ new Vue({
// 新增:开始区间播放 // 新增:开始区间播放
startRegionPlayback(start, end, regionId) { startRegionPlayback(start, end, regionId) {
// 检查是否在锁定范围内
if (this.isPageLocked) {
if (start < this.lockedPageStart || end > this.lockedPageEnd) {
this.$message.warning('当前播放范围超出锁定页面范围');
return;
}
}
// 如果正在播放,先停止 // 如果正在播放,先停止
this.stopCurrentPlayback(); this.stopCurrentPlayback();
...@@ -1196,6 +1247,83 @@ new Vue({ ...@@ -1196,6 +1247,83 @@ new Vue({
} }
}, playDuration); }, playDuration);
}, },
// 新增:切换页面锁定状态
togglePageLock() {
if (!this.currentPage) return;
if (!this.isPageLocked) {
// 获取当前页面的时间范围
const times = this.currentPage.groups.reduce((acc, group) => {
if (typeof group.start === 'number' && !isNaN(group.start)) {
acc.starts.push(group.start);
}
if (typeof group.end === 'number' && !isNaN(group.end)) {
acc.ends.push(group.end);
}
return acc;
}, { starts: [], ends: [] });
if (times.starts.length > 0 && times.ends.length > 0) {
this.lockedPageStart = Math.min(...times.starts);
this.lockedPageEnd = Math.max(...times.ends);
this.isPageLocked = true;
this.$message.success('页面已锁定');
} else {
this.$message.warning('当前页面没有有效的时间范围');
return;
}
} else {
// 解锁页面
this.isPageLocked = false;
this.lockedPageStart = null;
this.lockedPageEnd = null;
this.$message.success('页面已解锁');
}
// 更新波形图区域样式
this.updateRegionsStyle();
},
// 新增:更新区域样式的统一方法
updateRegionsStyle() {
Object.keys(this.audioRegions).forEach(regionId => {
const region = this.audioRegions[regionId];
if (!region) return;
// 如果是页面区间
if (regionId.startsWith('page-')) {
const pageIndex = parseInt(regionId.split('-')[1]);
const isCurrentPage = pageIndex === this.currentPageIndex - 1;
const isClickable = !this.isPageLocked || isCurrentPage;
region.update({
color: 'rgba(255, 192, 203, 0.3)',
drag: false,
resize: false,
// 锁定状态下,非当前页区间变暗
opacity: (!this.isPageLocked || isCurrentPage) ? 1 : 0.3
});
// 更新点击事件处理
if (region.element) {
region.element.style.pointerEvents = isClickable ? 'all' : 'none';
}
return;
}
// 处理组区间
const [pageIndex, groupIndex] = regionId.split('-').map(Number);
const isCurrentPage = pageIndex === this.currentPageIndex - 1;
region.update({
color: isCurrentPage ? 'rgba(64, 158, 255, 0.2)' : 'rgba(144, 147, 153, 0.1)',
drag: isCurrentPage,
resize: isCurrentPage,
opacity: (!this.isPageLocked || isCurrentPage) ? 1 : 0.3
});
});
},
}, },
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