Commit a2155bca authored by liujiangnan's avatar liujiangnan

feat: 预览的基本功能,但还有点问题

parent d0cb470b
...@@ -628,3 +628,85 @@ html, body { ...@@ -628,3 +628,85 @@ html, body {
height: 100% !important; height: 100% !important;
cursor: ew-resize !important; cursor: ew-resize !important;
} }
/* 预览模式样式 */
.preview-mode .text-rect {
pointer-events: none !important;
cursor: default !important;
}
.preview-mode .resize-handle {
display: none !important;
}
.preview-mode .delete-rect-btn {
display: none !important;
}
.preview-mode .add-rect-btn {
display: none !important;
}
.preview-mode .el-input,
.preview-mode .el-textarea {
pointer-events: none !important;
}
.preview-mode .el-input input,
.preview-mode .el-textarea textarea {
background-color: transparent !important;
border-color: transparent !important;
cursor: default !important;
}
.preview-mode .el-pagination {
pointer-events: none !important;
opacity: 0.6;
}
.preview-mode .el-button[disabled] {
pointer-events: none !important;
opacity: 0.6;
}
/* 预览模式下的波形图区域 */
.preview-mode .wavesurfer-region {
pointer-events: none !important;
cursor: default !important;
}
.preview-mode .wavesurfer-handle {
display: none !important;
}
/* 预览模式下允许的交互 */
.preview-mode #waveform {
cursor: pointer !important;
}
.preview-mode .el-button--default:not([disabled]),
.preview-mode .el-button--danger:not([disabled]) {
pointer-events: auto !important;
opacity: 1 !important;
}
.preview-mode .el-select:not([disabled]) {
pointer-events: auto !important;
opacity: 1 !important;
}
/* 预览按钮激活状态 */
.basic-controls .el-button.is-preview {
color: #f56c6c;
border-color: #f56c6c;
}
.basic-controls .el-button.is-preview:hover {
background-color: #fef0f0;
}
.basic-controls .el-button.is-preview.is-disabled {
color: #c0c4cc;
border-color: #ebeef5;
background-color: #fff;
}
\ No newline at end of file
...@@ -288,34 +288,46 @@ ...@@ -288,34 +288,46 @@
<div class="control-wrapper"> <div class="control-wrapper">
<div class="basic-controls"> <div class="basic-controls">
<el-button-group> <el-button-group>
<el-button size="small" @click="playAudio" :disabled="audioLoading"> <el-button @click="playAudio" :disabled="!wavesurfer || audioLoading">
<i :class="isPlaying ? 'el-icon-video-pause' : 'el-icon-video-play'"></i> <i :class="isPlaying ? 'el-icon-video-pause' : 'el-icon-video-play'"></i>
</el-button> </el-button>
<el-button size="small" @click="stopAudio" :disabled="audioLoading"> <el-button @click="stopAudio" :disabled="!wavesurfer || audioLoading">
<i class="el-icon-video-stop"></i> <i class="el-icon-video-stop"></i>
</el-button> </el-button>
</el-button-group> <el-button @click="handleZoomIn" :disabled="!wavesurfer || audioLoading || zoomLevel >= maxZoom">
<i class="el-icon-zoom-in"></i>
<span class="time-display">{{ currentTime.toFixed(2) }}s</span> </el-button>
<el-button @click="handleZoomOut" :disabled="!wavesurfer || audioLoading || zoomLevel <= minZoom">
<el-button-group style="margin-left: 10px;">
<el-button size="small" @click="handleZoomOut" :disabled="audioLoading">
<i class="el-icon-zoom-out"></i> <i class="el-icon-zoom-out"></i>
</el-button> </el-button>
<el-button size="small" @click="handleZoomIn" :disabled="audioLoading"> <el-button @click="togglePageLock" :disabled="!wavesurfer || audioLoading || !currentPage">
<i class="el-icon-zoom-in"></i> <i :class="isPageLocked ? 'el-icon-lock' : 'el-icon-unlock'"></i>
</el-button>
<el-button
@click="togglePreviewMode"
:disabled="!wavesurfer || audioLoading || isPageLocked"
:type="isPreviewMode ? 'danger' : 'default'"
>
<i :class="isPreviewMode ? 'el-icon-switch-button' : 'el-icon-view'"></i>
{{ isPreviewMode ? '退出预览' : '预览' }}
</el-button> </el-button>
</el-button-group> </el-button-group>
<el-button <!-- 播放速度选择 -->
<el-select
v-model="currentPlaybackRate"
size="small" size="small"
:type="isPageLocked ? 'danger' : 'primary'" style="width: 120px; margin-left: 10px;"
@click="togglePageLock" :disabled="!isPreviewMode"
:class="{ 'is-active': isPageLocked }" @change="changePlaybackRate"
style="margin-left: 10px;"> >
<i :class="isPageLocked ? 'el-icon-lock' : 'el-icon-unlock'"></i> <el-option
{{ isPageLocked ? '解锁页面' : '锁定页面' }} v-for="rate in playbackRates"
</el-button> :key="rate"
:label="rate + 'x'"
:value="rate"
/>
</el-select>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -55,6 +55,13 @@ new Vue({ ...@@ -55,6 +55,13 @@ new Vue({
lockedPageStart: null, lockedPageStart: null,
lockedPageEnd: null, lockedPageEnd: null,
previousZoomLevel: null, previousZoomLevel: null,
// 新增:预览模式相关
isPreviewMode: false,
playbackRates: [0.5, 1, 1.5, 2, 4, 8, 10],
currentPlaybackRate: 1,
previewTimer: null,
lastCheckedTime: 0, // 用于优化检查间隔
}, },
mounted() { mounted() {
...@@ -702,7 +709,7 @@ new Vue({ ...@@ -702,7 +709,7 @@ new Vue({
// 页面选择 // 页面选择
handlePageChange(page) { handlePageChange(page) {
if (!this.wavesurfer) return; if (!this.wavesurfer || this.isPreviewMode) return;
// 检查页面锁定状态 // 检查页面锁定状态
if (this.isPageLocked) { if (this.isPageLocked) {
...@@ -832,7 +839,7 @@ new Vue({ ...@@ -832,7 +839,7 @@ new Vue({
// 选择文本组 // 选择文本组
selectGroup(index) { selectGroup(index) {
if (!this.currentPage || !this.currentPage.groups) return; if (!this.currentPage || !this.currentPage.groups || this.isPreviewMode) return;
// 如果点击已选中的组,则取消选中 // 如果点击已选中的组,则取消选中
if (this.selectedGroup === index) { if (this.selectedGroup === index) {
...@@ -846,7 +853,7 @@ new Vue({ ...@@ -846,7 +853,7 @@ new Vue({
// 开始拖拽 // 开始拖拽
startDrag(event, groupIndex, itemIndex) { startDrag(event, groupIndex, itemIndex) {
if (event.target.classList.contains('resize-handle') || !this.imageLoaded) return; if (event.target.classList.contains('resize-handle') || !this.imageLoaded || this.isPreviewMode) return;
this.isDragging = true; this.isDragging = true;
this.dragStartX = event.clientX; this.dragStartX = event.clientX;
...@@ -862,7 +869,7 @@ new Vue({ ...@@ -862,7 +869,7 @@ new Vue({
// 开始调整大小 // 开始调整大小
startResize(event, groupIndex, itemIndex) { startResize(event, groupIndex, itemIndex) {
if (!this.imageLoaded) return; if (!this.imageLoaded || this.isPreviewMode) return;
this.isResizing = true; this.isResizing = true;
this.dragStartX = event.clientX; this.dragStartX = event.clientX;
...@@ -988,7 +995,7 @@ new Vue({ ...@@ -988,7 +995,7 @@ new Vue({
// 从组中删除矩形框 // 从组中删除矩形框
deleteRectFromGroup(groupIndex, itemIndex) { deleteRectFromGroup(groupIndex, itemIndex) {
if (!this.currentPage || !this.currentPage.groups[groupIndex]) return; if (!this.currentPage || !this.currentPage.groups[groupIndex] || this.isPreviewMode) return;
const group = this.currentPage.groups[groupIndex]; const group = this.currentPage.groups[groupIndex];
if (!group.group[itemIndex]) return; if (!group.group[itemIndex]) return;
...@@ -1034,7 +1041,7 @@ new Vue({ ...@@ -1034,7 +1041,7 @@ new Vue({
// 删除整个分组 // 删除整个分组
deleteGroup() { deleteGroup() {
if (this.selectedGroup === null || !this.currentPage) return; if (this.selectedGroup === null || !this.currentPage || this.isPreviewMode) return;
this.$confirm('确认删除该组及其所有矩形框吗?', '提示', { this.$confirm('确认删除该组及其所有矩形框吗?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
...@@ -1067,7 +1074,7 @@ new Vue({ ...@@ -1067,7 +1074,7 @@ new Vue({
// 处理矩形列表行点击 // 处理矩形列表行点击
handleRectRowClick(row, oldRow) { handleRectRowClick(row, oldRow) {
if (!row) { if (!row || this.isPreviewMode) {
this.selectedItemIndex = null; this.selectedItemIndex = null;
return; return;
} }
...@@ -1197,7 +1204,7 @@ new Vue({ ...@@ -1197,7 +1204,7 @@ new Vue({
// 拾取当前时间点 // 拾取当前时间点
pickCurrentTime(target) { pickCurrentTime(target) {
if (!this.wavesurfer) return; if (!this.wavesurfer || this.isPreviewMode) return;
const currentTime = this.wavesurfer.getCurrentTime(); const currentTime = this.wavesurfer.getCurrentTime();
const formattedTime = currentTime.toFixed(2); const formattedTime = currentTime.toFixed(2);
...@@ -1217,6 +1224,8 @@ new Vue({ ...@@ -1217,6 +1224,8 @@ new Vue({
// 处理图片区域点击 // 处理图片区域点击
handleImageClick(event) { handleImageClick(event) {
if (this.isPreviewMode) return;
// 如果点击的是矩形框或其相关元素,不处理 // 如果点击的是矩形框或其相关元素,不处理
if (event.target.closest('.text-rect') || if (event.target.closest('.text-rect') ||
event.target.closest('.resize-handle') || event.target.closest('.resize-handle') ||
...@@ -1234,6 +1243,8 @@ new Vue({ ...@@ -1234,6 +1243,8 @@ new Vue({
// 处理全屏图片区域点击 // 处理全屏图片区域点击
handleFullscreenImageClick(event) { handleFullscreenImageClick(event) {
if (this.isPreviewMode) return;
// 如果点击的是矩形框或其相关元素,不处理 // 如果点击的是矩形框或其相关元素,不处理
if (event.target.closest('.text-rect') || if (event.target.closest('.text-rect') ||
event.target.closest('.resize-handle') || event.target.closest('.resize-handle') ||
...@@ -1316,7 +1327,7 @@ new Vue({ ...@@ -1316,7 +1327,7 @@ new Vue({
// 新增:切换页面锁定状态 // 新增:切换页面锁定状态
togglePageLock() { togglePageLock() {
if (!this.currentPage) return; if (!this.currentPage || this.isPreviewMode) return;
if (!this.isPageLocked) { if (!this.isPageLocked) {
// 保存当前缩放级别 // 保存当前缩放级别
...@@ -1825,6 +1836,131 @@ new Vue({ ...@@ -1825,6 +1836,131 @@ new Vue({
return (currentRegion.start < group.end && currentRegion.end > group.start); return (currentRegion.start < group.end && currentRegion.end > group.start);
}); });
}, },
// 新增:切换预览模式
togglePreviewMode() {
if (this.isPageLocked) {
this.$message.warning('请先解锁页面');
return;
}
if (!this.isPreviewMode) {
// 进入预览模式
this.isPreviewMode = true;
document.body.classList.add('preview-mode');
// 从当前位置开始播放
this.wavesurfer.play();
this.isPlaying = true;
// 设置播放速度
this.wavesurfer.setPlaybackRate(this.currentPlaybackRate);
// 开始监听播放位置
this.startPreviewMonitoring();
} else {
// 退出预览模式
this.exitPreviewMode();
}
},
// 新增:退出预览模式
exitPreviewMode() {
this.isPreviewMode = false;
document.body.classList.remove('preview-mode');
// 停止播放
if (this.isPlaying) {
this.wavesurfer.pause();
this.isPlaying = false;
}
// 清理监听器
this.stopPreviewMonitoring();
// 重置播放速度
this.wavesurfer.setPlaybackRate(1);
this.currentPlaybackRate = 1;
},
// 新增:开始预览监听
startPreviewMonitoring() {
// 清理可能存在的旧定时器
this.stopPreviewMonitoring();
// 创建新的监听定时器
this.previewTimer = setInterval(() => {
if (!this.isPlaying || !this.isPreviewMode) return;
const currentTime = this.wavesurfer.getCurrentTime();
// 优化:每100ms才检查一次,避免过于频繁
if (currentTime - this.lastCheckedTime < 0.1) return;
this.lastCheckedTime = currentTime;
// 检查是否需要切换页面
this.checkAndSwitchPage(currentTime);
// 检查是否需要选中组
this.checkAndSelectGroup(currentTime);
}, 100); // 100ms检查一次
},
// 新增:停止预览监听
stopPreviewMonitoring() {
if (this.previewTimer) {
clearInterval(this.previewTimer);
this.previewTimer = null;
}
},
// 新增:检查并切换页面
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;
}
}
},
// 新增:检查并选中组
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;
}
}
// 如果不在任何组的时间范围内,取消选中
if (!found && this.selectedGroup !== null) {
this.selectedGroup = null;
this.currentGroup = null;
}
},
// 新增:修改播放速度
changePlaybackRate(rate) {
if (!this.isPreviewMode) return;
this.currentPlaybackRate = rate;
this.wavesurfer.setPlaybackRate(rate);
},
}, },
beforeDestroy() { beforeDestroy() {
...@@ -1836,6 +1972,9 @@ new Vue({ ...@@ -1836,6 +1972,9 @@ new Vue({
// 清理定时器 // 清理定时器
this.clearPlayTimer(); this.clearPlayTimer();
// 清理预览模式的定时器
this.stopPreviewMonitoring();
// 销毁波形图 // 销毁波形图
if (this.wavesurfer) { if (this.wavesurfer) {
try { try {
......
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