Commit 0a1309af authored by 15011343103's avatar 15011343103

feat: 异步调用显示灯

parent 4bc039f6
......@@ -729,4 +729,198 @@ html, body {
z-index: 1;
pointer-events: none;
}
.custom-audio-marker-blue { color: #00ff00 !important; }
\ No newline at end of file
.custom-audio-marker-blue { color: #00ff00 !important; }
.upload-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #f5f7fa;
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
}
.upload-area {
width: 80%;
max-width: 800px;
background: white;
padding: 40px;
border-radius: 8px;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
.upload-section {
margin-bottom: 30px;
}
.upload-section h3 {
margin-bottom: 15px;
color: #303133;
font-size: 18px;
}
.upload-box {
border: 2px dashed #dcdfe6;
border-radius: 6px;
padding: 40px;
text-align: center;
cursor: pointer;
transition: all 0.3s;
position: relative;
}
.upload-box:hover {
border-color: #409eff;
}
.upload-box.is-dragover {
border-color: #409eff;
background-color: rgba(64, 158, 255, 0.1);
}
.upload-box i {
font-size: 48px;
color: #909399;
margin-bottom: 15px;
}
.upload-text {
color: #606266;
}
.upload-text p {
margin: 5px 0;
}
.upload-hint {
font-size: 12px;
color: #909399;
}
.file-info {
margin-top: 15px;
padding: 10px;
background-color: #f5f7fa;
border-radius: 4px;
display: flex;
justify-content: space-between;
align-items: center;
}
.file-info p {
margin: 0;
color: #606266;
}
.upload-actions {
text-align: center;
margin-top: 30px;
}
/* 时间轴样式 */
.timeline-content {
padding: 10px 0;
}
.timeline-content h4 {
margin: 0 0 10px 0;
color: #303133;
font-size: 16px;
}
.timeline-content .el-progress {
margin: 10px 0;
}
.error-message {
color: #f56c6c;
font-size: 12px;
margin: 5px 0 0 0;
}
.el-timeline-item__node {
background-color: #409eff;
}
.el-timeline-item__node--success {
background-color: #67c23a;
}
.el-timeline-item__node--warning {
background-color: #e6a23c;
}
.el-timeline-item__node--danger {
background-color: #f56c6c;
}
.el-timeline-item__node--info {
background-color: #909399;
}
.el-timeline-item__timestamp {
color: #909399;
font-size: 12px;
}
.el-timeline-item__content {
color: #303133;
}
.el-timeline-item__wrapper {
padding-left: 28px;
position: relative;
padding-bottom: 20px;
}
.el-timeline-item__tail {
position: absolute;
left: 4px;
height: 100%;
border-left: 2px solid #e4e7ed;
}
.el-timeline-item__icon {
color: #fff;
font-size: 13px;
}
.el-timeline-item__node--normal {
left: -1px;
width: 12px;
height: 12px;
border-radius: 50%;
background-color: #909399;
}
.el-timeline-item__node--large {
left: -2px;
width: 14px;
height: 14px;
border-radius: 50%;
background-color: #909399;
}
.el-timeline-item__node--primary {
background-color: #409eff;
}
.el-timeline-item__node--success {
background-color: #67c23a;
}
.el-timeline-item__node--warning {
background-color: #e6a23c;
}
.el-timeline-item__node--danger {
background-color: #f56c6c;
}
.el-timeline-item__node--info {
background-color: #909399;
}
\ No newline at end of file
......@@ -29,64 +29,112 @@
</head>
<body>
<div id="app" v-loading.fullscreen.lock="loading">
<el-container>
<!-- 主要内容区域 -->
<el-main>
<el-row>
<!-- 左侧图片编辑区域 -->
<el-col :span="12">
<div class="image-editor" v-if="currentPage">
<div class="image-container" ref="imageContainer" @click="handleImageClick">
<div class="image-wrapper">
<img :src="currentPage.image_url" ref="pageImage" @load="handleImageLoad">
<template v-for="(group, groupIndex) in currentPage.groups">
<div
v-for="(item, itemIndex) in group.group"
:key="groupIndex + '-' + itemIndex"
class="text-rect"
:class="{
'selected': selectedGroup === groupIndex,
'highlighted': selectedGroup === groupIndex && selectedItemIndex === itemIndex
}"
:style="getRectStyle(item.rect)"
@mousedown="startDrag($event, groupIndex, itemIndex)">
<div class="resize-handle" @mousedown.stop="startResize($event, groupIndex, itemIndex)"></div>
<el-button
class="delete-rect-btn"
type="danger"
size="mini"
circle
@click.stop="deleteRectFromGroup(selectedGroup, itemIndex)">
<i class="el-icon-delete"></i>
</el-button>
</div>
</template>
</div>
<el-button
class="add-rect-btn"
type="primary"
circle
size="small"
@click="addNewRect">
<i class="el-icon-plus"></i>
</el-button>
<el-button
class="fullscreen-btn"
type="primary"
circle
size="small"
@click="toggleFullscreen">
<i :class="isFullscreen ? 'el-icon-close' : 'el-icon-full-screen'"></i>
</el-button>
</div>
<!-- 文件上传界面 -->
<div class="upload-container" v-if="!hasData">
<div class="upload-area">
<div class="upload-section">
<h3>音频文件上传</h3>
<el-upload
class="upload-box"
drag
action="#"
:auto-upload="true"
:http-request="handleAudioUpload"
:show-file-list="true"
:limit="1"
:on-exceed="handleExceed"
:before-upload="beforeAudioUpload"
:on-remove="removeAudioFile"
accept=".mp3"
>
<i class="el-icon-upload"></i>
<div class="upload-text">
<p>点击或拖拽文件到此处上传</p>
<p class="upload-hint">支持 .mp3 格式</p>
</div>
</el-upload>
<el-progress
v-if="audioUploadProgress > 0 && audioUploadProgress < 100"
:percentage="audioUploadProgress"
:format="progressFormat"
></el-progress>
</div>
<div class="upload-section">
<h3>PDF文件上传</h3>
<el-upload
class="upload-box"
drag
action="#"
:auto-upload="true"
:http-request="handlePdfUpload"
:show-file-list="true"
:limit="1"
:on-exceed="handleExceed"
:before-upload="beforePdfUpload"
:on-remove="removePdfFile"
accept=".pdf"
>
<i class="el-icon-upload"></i>
<div class="upload-text">
<p>点击或拖拽文件到此处上传</p>
<p class="upload-hint">支持 .pdf 格式</p>
</div>
</el-upload>
<el-progress
v-if="pdfUploadProgress > 0 && pdfUploadProgress < 100"
:percentage="pdfUploadProgress"
:format="progressFormat"
></el-progress>
</div>
<!-- 全屏浮层 -->
<div class="fullscreen-editor" v-if="isFullscreen" @click.self="toggleFullscreen">
<div class="fullscreen-content">
<div class="image-container" ref="fullscreenContainer" @click="handleFullscreenImageClick">
<!-- 添加任务处理进度时间轴 -->
<div class="upload-section" v-if="queueTasks.length > 0">
<h3>处理进度</h3>
<el-timeline>
<el-timeline-item
v-for="(task, index) in queueTasks"
:key="index"
:type="getTimelineItemType(task.step_status)"
:color="getTimelineItemColor(task.step_status)"
:timestamp="task.create_at"
>
<div class="timeline-content">
<h4>{{ task.step_code_desc }}</h4>
<el-progress
:percentage="task.step_process"
:status="getProgressStatus(task.step_status)"
></el-progress>
<p v-if="task.err_massage" class="error-message">{{ task.err_massage }}</p>
</div>
</el-timeline-item>
</el-timeline>
</div>
<div class="upload-actions">
<el-button
type="primary"
size="large"
:disabled="!isUploadComplete"
@click="handleProcess"
>
开始处理
</el-button>
</div>
</div>
</div>
<el-container v-else>
<el-container>
<!-- 主要内容区域 -->
<el-main>
<el-row>
<!-- 左侧图片编辑区域 -->
<el-col :span="12">
<div class="image-editor" v-if="currentPage">
<div class="image-container" ref="imageContainer" @click="handleImageClick">
<div class="image-wrapper">
<img :src="currentPage.image_url" ref="fullscreenImage" @load="handleFullscreenImageLoad">
<img :src="currentPage.image_url" ref="pageImage" @load="handleImageLoad">
<template v-for="(group, groupIndex) in currentPage.groups">
<div
v-for="(item, itemIndex) in group.group"
......@@ -96,7 +144,7 @@
'selected': selectedGroup === groupIndex,
'highlighted': selectedGroup === groupIndex && selectedItemIndex === itemIndex
}"
:style="getFullscreenRectStyle(item.rect)"
:style="getRectStyle(item.rect)"
@mousedown="startDrag($event, groupIndex, itemIndex)">
<div class="resize-handle" @mousedown.stop="startResize($event, groupIndex, itemIndex)"></div>
<el-button
......@@ -124,98 +172,79 @@
circle
size="small"
@click="toggleFullscreen">
<i class="el-icon-close"></i>
<i :class="isFullscreen ? 'el-icon-close' : 'el-icon-full-screen'"></i>
</el-button>
</div>
</div>
</div>
</el-col>
<!-- 右侧文本编辑区域 -->
<el-col :span="12">
<div class="text-editor">
<!-- 页面时间范围 -->
<el-form label-width="70px" v-if="currentPage" style="padding: 10px;">
<el-form-item label="页面时间">
<el-col :span="11">
<el-input
:disabled="true"
v-model="currentPage.start"
size="small"
placeholder="开始时间"
@change="handlePageTimeChange('start', $event)">
<template slot="append">
<el-button
type="primary"
size="small"
@click="pickCurrentTime('pageStart')"
title="拾取当前时间">
<i class="el-icon-timer"></i>
</el-button>
<!-- 全屏浮层 -->
<div class="fullscreen-editor" v-if="isFullscreen" @click.self="toggleFullscreen">
<div class="fullscreen-content">
<div class="image-container" ref="fullscreenContainer" @click="handleFullscreenImageClick">
<div class="image-wrapper">
<img :src="currentPage.image_url" ref="fullscreenImage" @load="handleFullscreenImageLoad">
<template v-for="(group, groupIndex) in currentPage.groups">
<div
v-for="(item, itemIndex) in group.group"
:key="groupIndex + '-' + itemIndex"
class="text-rect"
:class="{
'selected': selectedGroup === groupIndex,
'highlighted': selectedGroup === groupIndex && selectedItemIndex === itemIndex
}"
:style="getFullscreenRectStyle(item.rect)"
@mousedown="startDrag($event, groupIndex, itemIndex)">
<div class="resize-handle" @mousedown.stop="startResize($event, groupIndex, itemIndex)"></div>
<el-button
class="delete-rect-btn"
type="danger"
size="mini"
circle
@click.stop="deleteRectFromGroup(selectedGroup, itemIndex)">
<i class="el-icon-delete"></i>
</el-button>
</div>
</template>
</el-input>
</el-col>
<el-col class="line" :span="2">-</el-col>
<el-col :span="11">
<el-input
:disabled="true"
v-model="currentPage.end"
</div>
<el-button
class="add-rect-btn"
type="primary"
circle
size="small"
placeholder="结束时间"
@change="handlePageTimeChange('end', $event)">
<template slot="append">
<el-button
type="primary"
size="small"
@click="pickCurrentTime('pageEnd')"
title="拾取当前时间">
<i class="el-icon-timer"></i>
</el-button>
</template>
</el-input>
</el-col>
</el-form-item>
</el-form>
<!-- 分隔线 -->
<div style="height: 10px; border-bottom: 1px solid #DCDFE6;"></div>
<!-- 选中组的编辑区域 -->
<template v-if="currentPage && selectedGroup !== null && currentGroup">
<div class="group-header">
<div class="group-title">组编辑 <span v-if="!isPageLocked" style="margin-left: 10px; font-size: 12px; color: #999;">(锁定后可编辑)</span> </div>
<el-button type="danger" size="small" @click="deleteGroup">删除整组</el-button>
@click="addNewRect">
<i class="el-icon-plus"></i>
</el-button>
<el-button
class="fullscreen-btn"
type="primary"
circle
size="small"
@click="toggleFullscreen">
<i class="el-icon-close"></i>
</el-button>
</div>
</div>
<el-form label-width="100px">
<el-form-item label="英文句子">
<el-input
:disabled="!isPageLocked"
type="textarea"
:rows="3"
v-model="currentGroup.sentence"
@change="handleGroupTextChange('sentence', $event)">
</el-input>
</el-form-item>
<el-form-item label="中文翻译">
<el-input
:disabled="!isPageLocked"
type="textarea"
:rows="3"
v-model="currentGroup.sentence_cn"
@change="handleGroupTextChange('sentence_cn', $event)">
</el-input>
</el-form-item>
<el-form-item label="时间范围">
</div>
</el-col>
<!-- 右侧文本编辑区域 -->
<el-col :span="12">
<div class="text-editor">
<!-- 页面时间范围 -->
<el-form label-width="70px" v-if="currentPage" style="padding: 10px;">
<el-form-item label="页面时间">
<el-col :span="11">
<el-input
:disabled="true"
v-model="currentGroup.start"
v-model="currentPage.start"
size="small"
placeholder="开始时间">
placeholder="开始时间"
@change="handlePageTimeChange('start', $event)">
<template slot="append">
<el-button
type="primary"
size="small"
@click="pickCurrentTime('groupStart')"
@click="pickCurrentTime('pageStart')"
title="拾取当前时间">
<i class="el-icon-timer"></i>
</el-button>
......@@ -226,14 +255,15 @@
<el-col :span="11">
<el-input
:disabled="true"
v-model="currentGroup.end"
v-model="currentPage.end"
size="small"
placeholder="结束时间">
placeholder="结束时间"
@change="handlePageTimeChange('end', $event)">
<template slot="append">
<el-button
type="primary"
size="small"
@click="pickCurrentTime('groupEnd')"
@click="pickCurrentTime('pageEnd')"
title="拾取当前时间">
<i class="el-icon-timer"></i>
</el-button>
......@@ -241,113 +271,180 @@
</el-input>
</el-col>
</el-form-item>
<el-form-item label="矩形列表">
<el-table
:data="currentGroup.group"
size="mini"
border
highlight-current-row
@current-change="handleRectRowClick">
<el-table-column label="文本内容">
<template slot-scope="scope">
<span>{{ scope.row.text }}</span>
</template>
</el-table-column>
<el-table-column label="操作" width="80">
<template slot-scope="scope">
<el-button
type="danger"
size="mini"
icon="el-icon-delete"
circle
@click="deleteRectFromGroup(selectedGroup, scope.$index)">
</el-button>
</template>
</el-table-column>
</el-table>
</el-form-item>
</el-form>
</template>
</div>
</el-col>
</el-row>
</el-main>
</el-container>
<!-- 分隔线 -->
<div style="height: 10px; border-bottom: 1px solid #DCDFE6;"></div>
<!-- 分页器 -->
<div class="pagination-container" v-if="currentPage">
<el-pagination
background
@current-change="handlePageChange"
:current-page.sync="currentPageIndex"
:page-size="1"
layout="prev, pager, next"
:total="pages.length"
:disabled="isPageLocked">
</el-pagination>
</div>
<!-- 选中组的编辑区域 -->
<template v-if="currentPage && selectedGroup !== null && currentGroup">
<div class="group-header">
<div class="group-title">组编辑 <span v-if="!isPageLocked" style="margin-left: 10px; font-size: 12px; color: #999;">(锁定后可编辑)</span> </div>
<el-button type="danger" size="small" @click="deleteGroup">删除整组</el-button>
</div>
<el-form label-width="100px">
<el-form-item label="英文句子">
<el-input
:disabled="!isPageLocked"
type="textarea"
:rows="3"
v-model="currentGroup.sentence"
@change="handleGroupTextChange('sentence', $event)">
</el-input>
</el-form-item>
<el-form-item label="中文翻译">
<el-input
:disabled="!isPageLocked"
type="textarea"
:rows="3"
v-model="currentGroup.sentence_cn"
@change="handleGroupTextChange('sentence_cn', $event)">
</el-input>
</el-form-item>
<el-form-item label="时间范围">
<el-col :span="11">
<el-input
:disabled="true"
v-model="currentGroup.start"
size="small"
placeholder="开始时间">
<template slot="append">
<el-button
type="primary"
size="small"
@click="pickCurrentTime('groupStart')"
title="拾取当前时间">
<i class="el-icon-timer"></i>
</el-button>
</template>
</el-input>
</el-col>
<el-col class="line" :span="2">-</el-col>
<el-col :span="11">
<el-input
:disabled="true"
v-model="currentGroup.end"
size="small"
placeholder="结束时间">
<template slot="append">
<el-button
type="primary"
size="small"
@click="pickCurrentTime('groupEnd')"
title="拾取当前时间">
<i class="el-icon-timer"></i>
</el-button>
</template>
</el-input>
</el-col>
</el-form-item>
<el-form-item label="矩形列表">
<el-table
:data="currentGroup.group"
size="mini"
border
highlight-current-row
@current-change="handleRectRowClick">
<el-table-column label="文本内容">
<template slot-scope="scope">
<span>{{ scope.row.text }}</span>
</template>
</el-table-column>
<el-table-column label="操作" width="80">
<template slot-scope="scope">
<el-button
type="danger"
size="mini"
icon="el-icon-delete"
circle
@click="deleteRectFromGroup(selectedGroup, scope.$index)">
</el-button>
</template>
</el-table-column>
</el-table>
</el-form-item>
</el-form>
</template>
</div>
</el-col>
</el-row>
</el-main>
</el-container>
<!-- 音频控制区域 -->
<div class="audio-control" v-loading="audioLoading">
<!-- 波形图区域 -->
<div class="waveform-wrapper" :class="{ 'page-locked': isPageLocked }">
<div id="waveform"></div>
<!-- 分页器 -->
<div class="pagination-container" v-if="currentPage">
<el-pagination
background
@current-change="handlePageChange"
:current-page.sync="currentPageIndex"
:page-size="1"
layout="prev, pager, next"
:total="pages.length"
:disabled="isPageLocked">
</el-pagination>
</div>
<!-- 控制按钮区域 -->
<div class="control-wrapper">
<div class="basic-controls">
<el-button-group>
<el-button @click="playAudio" :disabled="!wavesurfer || audioLoading">
<i :class="isPlaying ? 'el-icon-video-pause' : 'el-icon-video-play'"></i>
</el-button>
<el-button @click="stopAudio" :disabled="!wavesurfer || audioLoading">
<i class="el-icon-video-stop"></i>
</el-button>
<el-button @click="handleZoomIn" :disabled="!wavesurfer || audioLoading || zoomLevel >= maxZoom">
<i class="el-icon-zoom-in"></i>
</el-button>
<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 || isPreviewMode">
<i :class="isPageLocked ? 'el-icon-lock' : 'el-icon-unlock'"></i>
<span v-if="isPageLocked">解锁</span>
<span v-else>锁定页</span>
</el-button>
<el-button
@click="togglePreviewMode"
:disabled="!wavesurfer || audioLoading"
:type="isPreviewMode ? 'danger' : 'default'"
<!-- 音频控制区域 -->
<div class="audio-control" v-loading="audioLoading">
<!-- 波形图区域 -->
<div class="waveform-wrapper" :class="{ 'page-locked': isPageLocked }">
<div id="waveform"></div>
</div>
<!-- 控制按钮区域 -->
<div class="control-wrapper">
<div class="basic-controls">
<el-button-group>
<el-button @click="playAudio" :disabled="!wavesurfer || audioLoading">
<i :class="isPlaying ? 'el-icon-video-pause' : 'el-icon-video-play'"></i>
</el-button>
<el-button @click="stopAudio" :disabled="!wavesurfer || audioLoading">
<i class="el-icon-video-stop"></i>
</el-button>
<el-button @click="handleZoomIn" :disabled="!wavesurfer || audioLoading || zoomLevel >= maxZoom">
<i class="el-icon-zoom-in"></i>
</el-button>
<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 || isPreviewMode">
<i :class="isPageLocked ? 'el-icon-lock' : 'el-icon-unlock'"></i>
<span v-if="isPageLocked">解锁</span>
<span v-else>锁定页</span>
</el-button>
<el-button
@click="togglePreviewMode"
:disabled="!wavesurfer || audioLoading"
:type="isPreviewMode ? 'danger' : 'default'"
>
<i :class="isPreviewMode ? 'el-icon-switch-button' : 'el-icon-view'"></i>
{{ isPreviewMode ? '退出预览' : '预览' }}
</el-button>
</el-button-group>
<!-- 播放速度选择 -->
<el-select
v-model="currentPlaybackRate"
size="small"
style="width: 120px; margin-left: 10px;"
:disabled="!isPreviewMode"
@change="changePlaybackRate"
>
<i :class="isPreviewMode ? 'el-icon-switch-button' : 'el-icon-view'"></i>
{{ isPreviewMode ? '退出预览' : '预览' }}
</el-button>
</el-button-group>
<!-- 播放速度选择 -->
<el-select
v-model="currentPlaybackRate"
size="small"
style="width: 120px; margin-left: 10px;"
:disabled="!isPreviewMode"
@change="changePlaybackRate"
>
<el-option
v-for="rate in playbackRates"
:key="rate"
:label="rate + 'x'"
:value="rate"
/>
</el-select>
<el-option
v-for="rate in playbackRates"
:key="rate"
:label="rate + 'x'"
:value="rate"
/>
</el-select>
<div style="margin-left: 10px; display: inline-block; width: 200px;">当前时间:<div style="display: inline-block; width: 50px;">{{ formatTime(currentTime) }}</div> 秒</div>
<el-button :disabled="!isDataModified && !isPreviewMode" type="success" @click="save()">
保存修改
</el-button>
<div style="margin-left: 10px; display: inline-block; width: 200px;">当前时间:<div style="display: inline-block; width: 50px;">{{ formatTime(currentTime) }}</div> 秒</div>
<el-button :disabled="!isDataModified && !isPreviewMode" type="success" @click="save()">
保存修改
</el-button>
</div>
</div>
</div>
</div>
</el-container>
</div>
</body>
<script src="./index.js"></script>
......
......@@ -11,7 +11,7 @@ new Vue({
zoomStep: 20, // 每次放大/缩小的步长
audioRegions: {},
currentTime: 0, // 添加当前时间
// 数据相关
audioPoints: null,
pages: [],
......@@ -19,7 +19,7 @@ new Vue({
currentPageIndex: 0,
// 做一个currentPage的备份
tempPage: null,
// 编辑相关
selectedGroup: null,
currentGroup: null,
......@@ -67,8 +67,19 @@ new Vue({
lastCheckedTime: 0, // 用于优化检查间隔
isDataModified: false,
hasData: false,
audioFile: null,
pdfFile: null,
audioUploadProgress: 0,
pdfUploadProgress: 0,
audioUploadComplete: false,
pdfUploadComplete: false,
isAudioDragover: false,
isPdfDragover: false,
queueTasks: [],
},
mounted() {
this.$nextTick(() => {
// 先加载数据
......@@ -76,7 +87,7 @@ new Vue({
// 数据加载成功后初始化波形图
this.initWavesurfer();
});
// 添加全局事件监听
document.addEventListener('mousemove', this.handleMouseMove);
document.addEventListener('mouseup', this.handleMouseUp);
......@@ -84,13 +95,35 @@ new Vue({
document.addEventListener('keydown', this.handleKeydown);
});
},
methods: {
// 心跳实时查询异步处理进度及信息
async checkProcess(_data) {
let data = _data;
if (!data) {
data = await new Promise((resolve) => {
window.courseware.getData((data) => {
resolve(data);
}, t_name);
});
}
if (data && data.data_type == 'AI_QUEUE') {
// 更新队列任务列表
this.queueTasks = data.rows;
// 继续检查进度
await new Promise(resolve => setTimeout(resolve, 1000));
this.checkProcess();
} else {
this.hasData = true;
this.initPage(data);
this.$message.success('处理完成');
}
},
// 加载默认数据
async loadDefaultData() {
this.loading = true;
this.$message.info('正在加载数据...');
try {
let data = await new Promise((resolve) => {
window.courseware.getData((data) => {
......@@ -99,21 +132,17 @@ new Vue({
});
if (!data) {
this.loading = false;
// TODO 上传文件以及上传后的AI处理状态展示,直到AI处理完成才会有 data
return;
}
this.audioPoints = data.audio_points;
this.pages = data.pages;
if (data && data.data_type == 'AI_QUEUE') {
// 说明是AI处理队列,需要实时查询进度
this.loading = false;
this.checkProcess();
return;
}
this.currentPageIndex = 1;
this.currentPage = this.pages[0];
// 克隆currentPage
this.tempPage = JSON.parse(JSON.stringify(this.currentPage));
// 开始预加载图片
this.preloadImages();
this.hasData = true;
this.initPage(data);
this.loading = false;
this.$message.success('数据加载成功');
} catch (error) {
......@@ -123,7 +152,20 @@ new Vue({
throw error;
}
},
initPage(data) {
this.audioPoints = data.audio_points;
this.pages = data.pages;
this.currentPageIndex = 1;
this.currentPage = this.pages[0];
// 克隆currentPage
this.tempPage = JSON.parse(JSON.stringify(this.currentPage));
// 开始预加载图片
this.preloadImages();
},
// 预加载所有图片
preloadImages() {
if (!this.pages || this.pages.length === 0) return;
......@@ -143,43 +185,43 @@ new Vue({
if (!page.image_url) return;
const img = new Image();
img.onload = () => {
// 存储预加载的图片
this.preloadedImages[page.image_url] = img;
// 更新进度
loadedCount++;
this.preloadProgress = Math.floor((loadedCount / totalImages) * 100);
// 更新加载提示文字
loadingInstance.text = `正在预加载图片 (${this.preloadProgress}%)`;
// 所有图片加载完成
if (loadedCount === totalImages) {
loadingInstance.close();
this.$message.success('图片预加载完成');
}
};
img.onerror = () => {
console.error(`Failed to load image: ${page.image_url}`);
// 即使加载失败也计入进度
loadedCount++;
this.preloadProgress = Math.floor((loadedCount / totalImages) * 100);
loadingInstance.text = `正在预加载图片 (${this.preloadProgress}%)`;
if (loadedCount === totalImages) {
loadingInstance.close();
}
};
// 开始加载图片
img.src = page.image_url;
});
},
// 初始化波形图
initWavesurfer() {
if (!this.audioPoints || !this.audioPoints.audio_url) {
......@@ -228,12 +270,12 @@ new Vue({
})
]
});
// 监听事件
this.wavesurfer.on('ready', () => {
this.audioLoading = false;
console.log('WaveSurfer is ready'); // 添加日志
// 添加一个小延时确保 WaveSurfer 完全准备好
setTimeout(() => {
// 音频加载完成后,创建区域并显示第一页
......@@ -278,7 +320,7 @@ new Vue({
// 添加时间更新事件监听
this.wavesurfer.on('audioprocess', () => {
this.currentTime = this.wavesurfer.getCurrentTime();
if (this.isPageLocked) {
if (this.currentTime < this.lockedPageStart) {
this.wavesurfer.seekTo(this.lockedPageStart / this.wavesurfer.getDuration());
......@@ -292,7 +334,7 @@ new Vue({
// 添加 seek 事件监听,更新时间显示
this.wavesurfer.on('seek', () => {
this.currentTime = this.wavesurfer.getCurrentTime();
if (this.isPageLocked) {
if (this.currentTime < this.lockedPageStart || this.currentTime > this.lockedPageEnd) {
if (this.currentTime < this.lockedPageStart) {
......@@ -315,13 +357,13 @@ new Vue({
// 加载音频
this.audioLoading = true;
this.wavesurfer.load(this.audioPoints.audio_url);
} catch (err) {
console.error('WaveSurfer initialization error:', err);
this.$message.error('波形图初始化失败');
}
},
// 创建所有页面的音频区域
createAllAudioRegions() {
if (!this.wavesurfer || !this.wavesurfer.isReady) {
......@@ -371,17 +413,17 @@ new Vue({
if (region) {
this.audioRegions[pageRegionId] = region;
// 修改点击事件处理
const handleClick = (event) => {
event.stopPropagation();
event.preventDefault();
if (this.isPageLocked && pageIndex !== this.currentPageIndex - 1) {
this.$message.warning('页面已锁定,请先解锁');
return;
}
this.currentPageIndex = pageIndex + 1;
this.currentPage = this.pages[pageIndex];
// 克隆currentPage
......@@ -391,7 +433,7 @@ new Vue({
// 更新区域样式
this.updateRegionsStyle();
// 定位到区间开始位置
const duration = this.wavesurfer.getDuration();
this.wavesurfer.seekTo(page.start / duration);
......@@ -405,7 +447,7 @@ new Vue({
// 直接更新页面时间
page.start = Number(region.start.toFixed(3));
page.end = Number(region.end.toFixed(3));
// 如果是当前页面,更新视图
if (pageIndex === this.currentPageIndex - 1) {
this.updatePageTimeRange();
......@@ -421,7 +463,7 @@ new Vue({
console.error('Error in createAllAudioRegions:', err);
}
},
// 处理页面区间点击
handlePageRegionClick(pageIndex) {
// 如果点击的不是当前页,切换到该页
......@@ -431,11 +473,11 @@ new Vue({
this.currentPage = this.pages[pageIndex];
// 克隆currentPage
this.tempPage = JSON.parse(JSON.stringify(this.currentPage));
// 取消当前选中的组
this.selectedGroup = null;
this.currentGroup = null;
// 更新所有区域的样式
Object.keys(this.audioRegions).forEach(regionId => {
// 跳过页面区间
......@@ -444,7 +486,7 @@ new Vue({
const [rPageIndex, groupIndex] = regionId.split('-').map(Number);
const region = this.audioRegions[regionId];
const isCurrentPage = rPageIndex === pageIndex;
if (region) {
region.update({
color: isCurrentPage ? 'rgba(64, 158, 255, 0.2)' : 'rgba(144, 147, 153, 0.1)',
......@@ -474,7 +516,7 @@ new Vue({
const pageEnd = Math.max(...times.ends);
const duration = pageEnd - pageStart;
const padding = duration * 0.1; // 添加10%的padding
// 计算合适的缩放级别
const zoomLevel = this.calculateZoomLevel(pageStart - padding, pageEnd + padding);
this.zoomLevel = zoomLevel;
......@@ -484,10 +526,10 @@ new Vue({
this.$nextTick(() => {
const center = (pageStart + pageEnd) / 2;
const duration = this.wavesurfer.getDuration();
// 定位到开始位置
this.wavesurfer.seekTo(pageStart / duration);
// 确保波形图滚动到正确位置
const scrollWidth = this.wavesurfer.drawer.wrapper.scrollWidth;
const containerWidth = this.wavesurfer.drawer.wrapper.clientWidth;
......@@ -497,30 +539,30 @@ new Vue({
}
}
},
// 处理音频区域更新
handleRegionUpdated(region) {
if (!this.currentPage || !region) return;
const [pageIndex, groupIndex] = region.id.split('-').map(Number);
if (pageIndex !== this.currentPageIndex - 1) return;
const group = this.currentPage.groups[groupIndex];
if (group) {
group.start = region.start;
group.end = region.end;
// 如果当前选中的就是这个组,更新编辑器中的值
if (this.selectedGroup === groupIndex) {
this.currentGroup = group;
}
}
},
// 音频控制
playAudio() {
if (!this.wavesurfer) return;
try {
// 如果页面已锁定,限制播放范围
if (this.isPageLocked) {
......@@ -545,7 +587,7 @@ new Vue({
if (currentTime >= this.currentGroup.end) {
this.wavesurfer.seekTo(this.currentGroup.start / this.wavesurfer.getDuration());
}
// 开始播放
this.wavesurfer.play();
this.isPlaying = true;
......@@ -558,7 +600,7 @@ new Vue({
this.wavesurfer.pause();
this.isPlaying = false;
this.currentPlayingRegion = null;
// 播放结束后强制重绘
requestAnimationFrame(() => {
this.wavesurfer.drawBuffer();
......@@ -570,7 +612,7 @@ new Vue({
// 没有选中组,正常播放
this.wavesurfer.playPause();
this.isPlaying = !this.isPlaying;
// 如果是锁定状态下的播放,需要在结束位置停止
if (this.isPageLocked && this.isPlaying) {
const remainingTime = (this.lockedPageEnd - this.wavesurfer.getCurrentTime()) * 1000;
......@@ -578,7 +620,7 @@ new Vue({
if (this.isPlaying) {
this.wavesurfer.pause();
this.isPlaying = false;
// 播放结束后强制重绘
requestAnimationFrame(() => {
this.wavesurfer.drawBuffer();
......@@ -587,7 +629,7 @@ new Vue({
}, remainingTime);
}
}
// 播放时保存当前位置作为缩放锚点
if (this.isPlaying) {
this.currentProgress = this.wavesurfer.getCurrentTime() / this.wavesurfer.getDuration();
......@@ -597,10 +639,10 @@ new Vue({
this.$message.error('播放失败');
}
},
stopAudio() {
if (!this.wavesurfer) return;
try {
this.stopCurrentPlayback();
this.wavesurfer.stop();
......@@ -609,71 +651,71 @@ new Vue({
this.$message.error('停止失败');
}
},
// 缩放控制方法
handleZoomIn() {
if (!this.wavesurfer) return;
const newZoom = Math.min(this.maxZoom, this.zoomLevel + this.zoomStep);
if (newZoom !== this.zoomLevel) {
this.zoomLevel = newZoom;
this.handleZoom(this.zoomLevel);
}
},
handleZoomOut() {
if (!this.wavesurfer) return;
const newZoom = Math.max(this.minZoom, this.zoomLevel - this.zoomStep);
if (newZoom !== this.zoomLevel) {
this.zoomLevel = newZoom;
this.handleZoom(this.zoomLevel);
}
},
handleZoom(value) {
if (!this.wavesurfer) return;
try {
// 保存当前位置和状态
const currentTime = this.wavesurfer.getCurrentTime();
const duration = this.wavesurfer.getDuration();
const progress = currentTime / duration;
// 更新波形图参数
this.wavesurfer.params.fillParent = value === this.minZoom;
this.wavesurfer.params.scrollParent = value !== this.minZoom;
// 获取当前视图状态
const oldWidth = this.wavesurfer.drawer.width;
const oldScroll = this.wavesurfer.drawer.wrapper.scrollLeft;
const containerWidth = this.wavesurfer.drawer.wrapper.clientWidth;
// 应用新的缩放级别
this.wavesurfer.zoom(value);
// 使用 Promise 确保缩放操作完成
Promise.resolve().then(() => {
// 重新计算波形图
const peaks = this.wavesurfer.backend.getPeaks(this.wavesurfer.drawer.width, 0, duration);
this.wavesurfer.drawer.drawPeaks(peaks, this.wavesurfer.drawer.width, 0, duration);
// 处理滚动位置
if (value > this.minZoom) {
const targetProgress = this.currentProgress || progress;
if (this.isPageLocked) {
// 锁定状态:确保显示完整的锁定区间
const scrollWidth = this.wavesurfer.drawer.wrapper.scrollWidth;
const startPos = (this.lockedPageStart / duration) * scrollWidth;
const endPos = (this.lockedPageEnd / duration) * scrollWidth;
const regionWidth = endPos - startPos;
// 计算并应用滚动位置
requestAnimationFrame(() => {
const scrollPosition = Math.max(0, startPos - (containerWidth - regionWidth) / 2);
this.wavesurfer.drawer.wrapper.scrollLeft = scrollPosition;
// 确保重新渲染可见区域
this.wavesurfer.drawer.updateProgress(this.wavesurfer.backend.getPlayedPercents());
this.wavesurfer.fireEvent('scroll');
......@@ -684,7 +726,7 @@ new Vue({
const scrollWidth = this.wavesurfer.drawer.wrapper.scrollWidth;
const scrollPosition = Math.max(0, (targetProgress * scrollWidth) - (containerWidth / 2));
this.wavesurfer.drawer.wrapper.scrollLeft = scrollPosition;
// 确保重新渲染可见区域
this.wavesurfer.drawer.updateProgress(this.wavesurfer.backend.getPlayedPercents());
this.wavesurfer.fireEvent('scroll');
......@@ -694,7 +736,7 @@ new Vue({
// 最小缩放级别:重置所有状态
this.wavesurfer.drawer.wrapper.scrollLeft = 0;
this.currentProgress = null;
// 确保完整渲染
requestAnimationFrame(() => {
this.wavesurfer.drawer.updateProgress(this.wavesurfer.backend.getPlayedPercents());
......@@ -707,11 +749,11 @@ new Vue({
this.$message.error('缩放失败');
}
},
// 页面选择
handlePageChange(page) {
if (!this.wavesurfer || this.isPreviewMode) return;
// 检查页面锁定状态
if (this.isPageLocked) {
this.$message.warning('页面已锁定,请先解锁');
......@@ -721,7 +763,7 @@ new Vue({
});
return;
}
try {
const index = page - 1;
this.currentPage = this.pages[index];
......@@ -729,10 +771,10 @@ new Vue({
this.tempPage = JSON.parse(JSON.stringify(this.currentPage));
this.selectedGroup = null;
this.currentGroup = null;
// 更新所有区域的样式
this.updateRegionsStyle();
// 定位到当前页面的时间范围(如果有)
if (this.currentPage && this.currentPage.groups && this.currentPage.groups.length > 0) {
// 找出所有组的时间范围
......@@ -758,14 +800,14 @@ new Vue({
console.error('Error changing page:', err);
}
},
// 计算合适的缩放级别
calculateZoomLevel(start, end) {
const duration = end - start;
// 降低默认缩放倍数
return Math.min(500, Math.max(1, Math.floor(100 / duration)));
},
// 处理图片加载
handleImageLoad() {
const img = this.$refs.pageImage;
......@@ -814,7 +856,7 @@ new Vue({
this.imageRect = img.getBoundingClientRect();
this.imageLoaded = true;
},
// 获取矩形样式
getRectStyle(rect) {
if (!rect || !this.imageLoaded || !this.imageRect) return { display: 'none' };
......@@ -832,11 +874,11 @@ new Vue({
height: (height * 100) + '%'
};
},
// 选择文本组
selectGroup(index) {
if (!this.currentPage || !this.currentPage.groups || this.isPreviewMode) return;
// 如果点击已选中的组,则取消选中
if (this.selectedGroup === index) {
this.selectedGroup = null;
......@@ -846,23 +888,23 @@ new Vue({
this.currentGroup = this.currentPage.groups[index];
}
},
// 开始拖拽
startDrag(event, groupIndex, itemIndex) {
if (event.target.classList.contains('resize-handle')) return;
if (this.isPreviewMode) return;
// 获取图片容器的位置信息
const imageWrapper = this.$refs.imageContainer.querySelector('.image-wrapper');
const imageRect = imageWrapper.getBoundingClientRect();
this.isDragging = true;
this.dragStartX = event.clientX - imageRect.left;
this.dragStartY = event.clientY - imageRect.top;
this.selectedGroup = groupIndex;
this.currentGroup = this.currentPage.groups[groupIndex];
this.selectedItemIndex = itemIndex;
const rect = this.currentGroup.group[itemIndex].rect;
this.originalRect = {
x: rect ? rect.x : 0.2,
......@@ -870,7 +912,7 @@ new Vue({
width: rect ? rect.width : 0.2,
height: rect ? rect.height : 0.2
};
// 记录初始点击位置相对于矩形框的偏移
this.dragOffsetX = this.dragStartX - (this.originalRect.x * this.imageWidth);
this.dragOffsetY = this.dragStartY - (this.originalRect.y * this.imageHeight);
......@@ -878,7 +920,7 @@ new Vue({
event.preventDefault();
event.stopPropagation();
},
// 开始调整大小
startResize(event, groupIndex, itemIndex) {
if (!this.imageLoaded || this.isPreviewMode) return;
......@@ -893,16 +935,16 @@ new Vue({
event.preventDefault();
},
// 处理鼠标移动
handleMouseMove(event) {
if (!this.isDragging && !this.isResizing) return;
if (!this.currentGroup || !this.originalRect) return;
// 获取图片容器的位置信息
const imageWrapper = this.$refs.imageContainer.querySelector('.image-wrapper');
const imageRect = imageWrapper.getBoundingClientRect();
const currentRect = this.currentGroup.group[this.selectedItemIndex].rect;
if (!currentRect) return;
......@@ -913,11 +955,11 @@ new Vue({
// 计算鼠标相对于图片容器的位置
const mouseX = event.clientX - imageRect.left;
const mouseY = event.clientY - imageRect.top;
// 考虑拖拽起始点的偏移
let newX = (mouseX - this.dragOffsetX) / this.imageWidth;
let newY = (mouseY - this.dragOffsetY) / this.imageHeight;
// 限制在图片范围内
newX = Math.max(0, Math.min(1 - currentRect.width, newX));
newY = Math.max(0, Math.min(1 - currentRect.height, newY));
......@@ -928,17 +970,17 @@ new Vue({
// 计算鼠标相对于图片的位置
const mouseX = event.clientX - imageRect.left;
const mouseY = event.clientY - imageRect.top;
// 计算新的宽度和高度
const newWidth = Math.max(5, mouseX - (this.originalRect.x * this.imageWidth)) / this.imageWidth;
const newHeight = Math.max(5, mouseY - (this.originalRect.y * this.imageHeight)) / this.imageHeight;
// 限制大小
currentRect.width = Math.min(1 - currentRect.x, newWidth);
currentRect.height = Math.min(1 - currentRect.y, newHeight);
}
},
// 处理鼠标松开
handleMouseUp(event) {
if (this.isDragging || this.isResizing) {
......@@ -953,19 +995,19 @@ new Vue({
this.pages[this.currentPageIndex - 1] = this.currentPage;
}
},
// 更新音频区域
updateAudioRegion() {
if (!this.currentGroup || this.selectedGroup === null) return;
try {
// 确保时间值是数字
const start = parseFloat(this.currentGroup.start) || 0;
const end = parseFloat(this.currentGroup.end) || 0;
const regionId = `${this.currentPageIndex - 1}-${this.selectedGroup}`;
const region = this.audioRegions[regionId];
if (region) {
region.update({
start: start,
......@@ -976,11 +1018,11 @@ new Vue({
console.error('Error updating audio region:', err);
}
},
// 添加新矩形框
addNewRect() {
if (!this.currentPage || !this.imageLoaded) return;
try {
// 创建新的分组
const newGroup = {
......@@ -998,14 +1040,14 @@ new Vue({
text: ''
}]
};
// 添加到当前页面
if (!this.currentPage.groups) {
this.currentPage.groups = [];
}
const newIndex = this.currentPage.groups.length;
this.currentPage.groups.push(newGroup);
// 创建对应的音频区域
const regionId = `${this.currentPageIndex - 1}-${newIndex}`;
this.audioRegions[regionId] = this.wavesurfer.addRegion({
......@@ -1016,7 +1058,7 @@ new Vue({
drag: true,
resize: true
});
// 选中新创建的分组
this.selectGroup(newIndex);
this.isDataModified = true;
......@@ -1026,14 +1068,14 @@ new Vue({
this.$message.error('添加新矩形框失败');
}
},
// 从组中删除矩形框
deleteRectFromGroup(groupIndex, itemIndex) {
if (!this.currentPage || !this.currentPage.groups[groupIndex] || this.isPreviewMode) return;
const group = this.currentPage.groups[groupIndex];
if (!group.group[itemIndex]) return;
this.$confirm('确认删除该文本框吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
......@@ -1042,7 +1084,7 @@ new Vue({
try {
// 删除矩形框
group.group.splice(itemIndex, 1);
// 如果组内没有矩形框了,删除整个组
if (group.group.length === 0) {
// 删除音频区域
......@@ -1051,12 +1093,12 @@ new Vue({
this.audioRegions[regionId].remove();
delete this.audioRegions[regionId];
}
// 删除分组数据
this.currentPage.groups.splice(groupIndex, 1);
this.selectedGroup = null;
this.currentGroup = null;
// 重新创建所有区域以更新索引
this.createAllAudioRegions();
} else {
......@@ -1064,7 +1106,7 @@ new Vue({
const texts = group.group.map(item => item.text).filter(Boolean);
group.sentence = texts.join(' ');
}
this.pages[this.currentPageIndex - 1] = this.currentPage;
this.isDataModified = true;
this.$message.success('删除成功');
......@@ -1072,13 +1114,13 @@ new Vue({
console.error('Error deleting rectangle from group:', err);
this.$message.error('删除失败');
}
}).catch(() => {});
}).catch(() => { });
},
// 删除整个分组
deleteGroup() {
if (this.selectedGroup === null || !this.currentPage || this.isPreviewMode) return;
this.$confirm('确认删除该组及其所有矩形框吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
......@@ -1091,36 +1133,36 @@ new Vue({
this.audioRegions[regionId].remove();
delete this.audioRegions[regionId];
}
// 删除分组数据
this.currentPage.groups.splice(this.selectedGroup, 1);
this.selectedGroup = null;
this.currentGroup = null;
// 重新创建所有区域以更新索引
this.createAllAudioRegions();
// 激活保存按钮
this.isDataModified = true;
this.$message.success('删除成功');
} catch (err) {
console.error('Error deleting group:', err);
this.$message.error('删除失败');
}
}).catch(() => {});
}).catch(() => { });
},
// 处理矩形列表行点击
handleRectRowClick(row, oldRow) {
if (!row || this.isPreviewMode) {
this.selectedItemIndex = null;
return;
}
// 找到点击行对应的索引
this.selectedItemIndex = this.currentGroup.group.findIndex(item => item === row);
// 如果矩形在可视区域外,滚动到可视区域
this.$nextTick(() => {
const rect = this.currentGroup.group[this.selectedItemIndex].rect;
......@@ -1133,7 +1175,7 @@ new Vue({
}
});
},
// 切换全屏模式
toggleFullscreen() {
this.isFullscreen = !this.isFullscreen;
......@@ -1147,7 +1189,7 @@ new Vue({
});
}
},
// 处理全屏图片加载
handleFullscreenImageLoad() {
const img = this.$refs.fullscreenImage;
......@@ -1194,7 +1236,7 @@ new Vue({
this.fullscreenImageHeight = finalHeight;
this.fullscreenImageRect = img.getBoundingClientRect();
},
// 获取全屏模式下矩形框的样式
getFullscreenRectStyle(rect) {
if (!rect || !this.isFullscreen || !this.fullscreenImageRect) return { display: 'none' };
......@@ -1217,19 +1259,19 @@ new Vue({
height: actualHeight + 'px'
};
},
// 处理音频播放过程
handleAudioProcess(currentTime) {
if (!this.currentGroup && !this.currentPage) return;
// 格式化时间为两位小数
const formattedTime = currentTime.toFixed(2);
// 更新组时间
if (this.currentGroup) {
this.currentGroup.start = formattedTime;
this.currentGroup.end = formattedTime;
// 更新音频区域
this.updateAudioRegion();
}
......@@ -1240,11 +1282,11 @@ new Vue({
this.currentPage.end = formattedTime;
}
},
// 拾取当前时间点
pickCurrentTime(target) {
if (!this.wavesurfer || this.isPreviewMode) return;
// 激活保存按钮
this.isDataModified = true;
......@@ -1263,17 +1305,17 @@ new Vue({
this.updateAudioRegion();
}
},
// 处理图片区域点击
handleImageClick(event) {
if (this.isPreviewMode) return;
// 如果点击的是矩形框或其相关元素,不处理
if (event.target.closest('.text-rect') ||
event.target.closest('.resize-handle') ||
event.target.closest('.delete-rect-btn') ||
event.target.closest('.add-rect-btn') ||
event.target.closest('.fullscreen-btn')) {
if (event.target.closest('.text-rect') ||
event.target.closest('.resize-handle') ||
event.target.closest('.delete-rect-btn') ||
event.target.closest('.add-rect-btn') ||
event.target.closest('.fullscreen-btn')) {
return;
}
......@@ -1286,13 +1328,13 @@ new Vue({
// 处理全屏图片区域点击
handleFullscreenImageClick(event) {
if (this.isPreviewMode) return;
// 如果点击的是矩形框或其相关元素,不处理
if (event.target.closest('.text-rect') ||
event.target.closest('.resize-handle') ||
event.target.closest('.delete-rect-btn') ||
event.target.closest('.add-rect-btn') ||
event.target.closest('.fullscreen-btn')) {
if (event.target.closest('.text-rect') ||
event.target.closest('.resize-handle') ||
event.target.closest('.delete-rect-btn') ||
event.target.closest('.add-rect-btn') ||
event.target.closest('.fullscreen-btn')) {
return;
}
......@@ -1316,10 +1358,10 @@ new Vue({
if (this.isPlaying) {
this.wavesurfer.pause();
this.isPlaying = false;
// 添加:强制重绘波形图
requestAnimationFrame(() => {
this.wavesurfer.drawBuffer();
this.wavesurfer.drawBuffer();
});
}
this.currentPlayingRegion = null;
......@@ -1337,14 +1379,14 @@ new Vue({
// 如果正在播放,先停止
this.stopCurrentPlayback();
// 获取区间的最新时间值
const region = this.audioRegions[regionId];
if (!region) return;
const currentStart = region.start;
const currentEnd = region.end;
// 开始新的播放
this.wavesurfer.seekTo(currentStart / this.wavesurfer.getDuration());
this.wavesurfer.play();
......@@ -1358,10 +1400,10 @@ new Vue({
this.wavesurfer.pause();
this.isPlaying = false;
this.currentPlayingRegion = null;
// 添加:播放结束后强制重绘
requestAnimationFrame(() => {
this.wavesurfer.drawBuffer();
this.wavesurfer.drawBuffer();
});
}
}, playDuration);
......@@ -1394,7 +1436,7 @@ new Vue({
// 为当前页创建开始和结束标记
const pageRegionId = `page-${this.currentPageIndex - 1}`;
// 创建开始标记(绿色竖线)
const startMarker = this.wavesurfer.addRegion({
id: `${pageRegionId}-start`,
......@@ -1420,16 +1462,16 @@ new Vue({
if (startMarker && endMarker) {
this.audioRegions[`${pageRegionId}-start`] = startMarker;
this.audioRegions[`${pageRegionId}-end`] = endMarker;
// 使用border-left创建细线
this.$nextTick(() => {
const startElement = startMarker.element;
const endElement = endMarker.element;
if (startElement) {
startElement.classList.add('custom-audio-marker', 'custom-audio-marker-blue');
}
if (endElement) {
endElement.classList.add('custom-audio-marker', 'custom-audio-marker-blue');
}
......@@ -1467,12 +1509,12 @@ new Vue({
if (region) {
this.audioRegions[groupRegionId] = region;
// 添加点击事件处理
const handleClick = (event) => {
event.stopPropagation();
event.preventDefault();
// 直接选中组,不需要取消选中功能
this.selectedGroup = groupIndex;
this.currentGroup = this.currentPage.groups[groupIndex];
......@@ -1486,12 +1528,12 @@ new Vue({
region.element.removeEventListener('click', handleClick);
region.element.addEventListener('click', handleClick);
// 添加区间更新事件处理
region.on('update-end', () => {
// 检查是否与其他区间重叠
const isOverlapping = this.checkOverlap(region, groupIndex);
if (isOverlapping) {
// 如果有重叠,恢复到原始位置
region.update({
......@@ -1501,7 +1543,7 @@ new Vue({
this.$message.warning('区间不能重叠');
return;
}
let newStart = Number(region.start.toFixed(3));
let newEnd = Number(region.end.toFixed(3));
const originalStart = group.start;
......@@ -1511,7 +1553,7 @@ new Vue({
// 判断是拖拽整个区间还是调整大小
const isDragging = Math.abs((newEnd - newStart) - (originalEnd - originalStart)) < 0.001;
if (isDragging) {
// 拖拽整个区间的情况
if (newStart < this.lockedPageStart) {
......@@ -1520,7 +1562,7 @@ new Vue({
needUpdate = true;
this.$message.warning('已自动调整到页面开始时间');
}
if (newEnd > this.lockedPageEnd) {
newEnd = this.lockedPageEnd;
newStart = newEnd - duration;
......@@ -1538,7 +1580,7 @@ new Vue({
needUpdate = true;
this.$message.warning('开始时间不能早于页面开始时间');
}
if (newEnd > this.lockedPageEnd) {
// 如果是调整结束时间且超出边界,恢复到原始结束时间
newEnd = originalEnd;
......@@ -1546,7 +1588,7 @@ new Vue({
this.$message.warning('结束时间不能晚于页面结束时间');
}
}
// 如果需要调整,更新区间位置
if (needUpdate) {
region.update({
......@@ -1554,11 +1596,11 @@ new Vue({
end: newEnd
});
}
// 更新组的时间范围
group.start = newStart;
group.end = newEnd;
// 如果当前选中的就是这个组,更新编辑器中的值
if (this.selectedGroup === groupIndex) {
this.currentGroup = group;
......@@ -1571,85 +1613,85 @@ new Vue({
// 设置波形图参数
this.wavesurfer.params.fillParent = false;
this.wavesurfer.params.scrollParent = true;
// 计算当前选中区间的时长和理想显示宽度
const duration = this.lockedPageEnd - this.lockedPageStart;
const containerWidth = this.wavesurfer.drawer.wrapper.clientWidth;
const totalDuration = this.wavesurfer.getDuration();
// 计算当前缩放下选中区间的实际宽度
const currentPixelsPerSecond = (containerWidth / totalDuration) * (this.zoomLevel / 50);
const currentWidth = currentPixelsPerSecond * duration;
// 目标宽度是容器的80%
const targetWidth = containerWidth * 0.8;
// 先重置缩放确保渲染正确
this.wavesurfer.zoom(1);
// 等待一帧后应用实际缩放
requestAnimationFrame(() => {
// 只有当前宽度小于目标宽度时才调整缩放
if (currentWidth < targetWidth) {
// 计算需要的缩放倍数
const ratio = targetWidth / currentWidth;
const newZoomLevel = Math.floor(this.zoomLevel * ratio);
// 限制最大缩放值
this.zoomLevel = Math.min(50, Math.max(this.minZoom, newZoomLevel));
}
// 应用缩放并强制重绘
this.wavesurfer.zoom(this.zoomLevel);
this.wavesurfer.drawBuffer();
// 确保位置正确
this.$nextTick(() => {
// 计算区间中心点
const center = (this.lockedPageStart + this.lockedPageEnd) / 2;
const centerProgress = center / totalDuration;
// 定位到中心点
this.wavesurfer.seekTo(centerProgress);
// 计算滚动位置,确保选中区间居中显示
const scrollWidth = this.wavesurfer.drawer.wrapper.scrollWidth;
const containerWidth = this.wavesurfer.drawer.wrapper.clientWidth;
const startPos = (this.lockedPageStart / totalDuration) * scrollWidth;
const endPos = (this.lockedPageEnd / totalDuration) * scrollWidth;
const regionWidth = endPos - startPos;
const scrollPosition = Math.max(0, startPos - (containerWidth - regionWidth) / 2);
this.wavesurfer.drawer.wrapper.scrollLeft = scrollPosition;
// 再次强制重绘以确保显示正确
requestAnimationFrame(() => {
this.wavesurfer.drawBuffer();
});
// 只有当前宽度小于目标宽度时才调整缩放
if (currentWidth < targetWidth) {
// 计算需要的缩放倍数
const ratio = targetWidth / currentWidth;
const newZoomLevel = Math.floor(this.zoomLevel * ratio);
// 限制最大缩放值
this.zoomLevel = Math.min(50, Math.max(this.minZoom, newZoomLevel));
}
// 应用缩放并强制重绘
this.wavesurfer.zoom(this.zoomLevel);
this.wavesurfer.drawBuffer();
// 确保位置正确
this.$nextTick(() => {
// 计算区间中心点
const center = (this.lockedPageStart + this.lockedPageEnd) / 2;
const centerProgress = center / totalDuration;
// 定位到中心点
this.wavesurfer.seekTo(centerProgress);
// 计算滚动位置,确保选中区间居中显示
const scrollWidth = this.wavesurfer.drawer.wrapper.scrollWidth;
const containerWidth = this.wavesurfer.drawer.wrapper.clientWidth;
const startPos = (this.lockedPageStart / totalDuration) * scrollWidth;
const endPos = (this.lockedPageEnd / totalDuration) * scrollWidth;
const regionWidth = endPos - startPos;
const scrollPosition = Math.max(0, startPos - (containerWidth - regionWidth) / 2);
this.wavesurfer.drawer.wrapper.scrollLeft = scrollPosition;
// 再次强制重绘以确保显示正确
requestAnimationFrame(() => {
this.wavesurfer.drawBuffer();
});
});
});
this.$message.success('页面已锁定');
} else {
// 解除锁定状态
this.isPageLocked = false;
// 保存当前页面的时间范围到 pages 数组
const currentPageIndex = this.currentPageIndex - 1;
if (this.pages[currentPageIndex]) {
this.pages[currentPageIndex].start = this.currentPage.start;
this.pages[currentPageIndex].end = this.currentPage.end;
}
this.lockedPageStart = null;
this.lockedPageEnd = null;
// 移除锁定状态的类名
document.body.classList.remove('page-locked');
// 重新创建所有区间
this.createAllAudioRegions();
// 恢复到之前的缩放级别
if (this.previousZoomLevel !== null) {
// 重置波形图参数
......@@ -1660,12 +1702,12 @@ new Vue({
this.wavesurfer.params.fillParent = false;
this.wavesurfer.params.scrollParent = true;
}
this.zoomLevel = this.previousZoomLevel;
this.wavesurfer.zoom(this.previousZoomLevel);
this.previousZoomLevel = null;
}
this.$message.success('页面已解锁');
}
},
......@@ -1689,7 +1731,7 @@ new Vue({
start: this.currentPage.start,
end: this.currentPage.start + 0.000001
});
// 重新应用样式
this.$nextTick(() => {
if (startMarker.element) {
......@@ -1704,7 +1746,7 @@ new Vue({
start: this.currentPage.end - 0.000001,
end: this.currentPage.end
});
// 重新应用样式
this.$nextTick(() => {
if (endMarker.element) {
......@@ -1741,14 +1783,14 @@ new Vue({
// 确保时间值有效
const newTime = Number(Number(value).toFixed(2));
const duration = this.wavesurfer.getDuration();
if (newTime < 0 || newTime > duration) {
this.$message.warning('时间值超出范围');
this.currentPage.start = this.tempPage.start;
this.currentPage.end = this.tempPage.end;
return;
}
// 更新时间值
if (type === 'start') {
if (newTime >= this.currentPage.end) {
......@@ -1783,15 +1825,15 @@ new Vue({
// 更新区域样式的方法
updateRegionsStyle() {
if (!this.wavesurfer) return;
Object.keys(this.audioRegions).forEach(regionId => {
// 跳过页面区间
if (regionId.startsWith('page-')) return;
const [pageIndex, groupIndex] = regionId.split('-').map(Number);
const region = this.audioRegions[regionId];
const isCurrentPage = pageIndex === this.currentPageIndex - 1;
if (region) {
region.update({
color: isCurrentPage ? 'rgba(64, 158, 255, 0.2)' : 'rgba(144, 147, 153, 0.1)',
......@@ -1807,7 +1849,7 @@ new Vue({
if (event.target.tagName === 'INPUT' || event.target.tagName === 'TEXTAREA') {
return;
}
// 处理空格键
if (event.code === 'Space') {
event.preventDefault(); // 阻止页面滚动
......@@ -1818,7 +1860,7 @@ new Vue({
clearTimeout(this.playTimer);
return;
}
// 如果页面已锁定,检查当前位置是否在锁定范围内
if (this.isPageLocked) {
const currentTime = this.wavesurfer.getCurrentTime();
......@@ -1841,8 +1883,8 @@ new Vue({
const currentTime = this.wavesurfer.getCurrentTime();
if (currentTime >= this.currentGroup.end) {
this.wavesurfer.seekTo(this.currentGroup.start / this.wavesurfer.getDuration());
}
}
// 开始播放
this.wavesurfer.play();
this.isPlaying = true;
......@@ -1855,7 +1897,7 @@ new Vue({
this.wavesurfer.pause();
this.isPlaying = false;
this.currentPlayingRegion = null;
// 播放结束后强制重绘
requestAnimationFrame(() => {
this.wavesurfer.drawBuffer();
......@@ -1867,7 +1909,7 @@ new Vue({
// 没有选中组,正常播放
this.wavesurfer.playPause();
this.isPlaying = !this.isPlaying;
// 如果是锁定状态下的播放,需要在结束位置停止
if (this.isPageLocked && this.isPlaying) {
const remainingTime = (this.lockedPageEnd - this.wavesurfer.getCurrentTime()) * 1000;
......@@ -1875,7 +1917,7 @@ new Vue({
if (this.isPlaying) {
this.wavesurfer.pause();
this.isPlaying = false;
// 播放结束后强制重绘
requestAnimationFrame(() => {
this.wavesurfer.drawBuffer();
......@@ -1884,7 +1926,7 @@ new Vue({
}, remainingTime);
}
}
// 如果开始播放,保存当前位置作为缩放锚点
if (this.isPlaying) {
this.currentProgress = this.wavesurfer.getCurrentTime() / this.wavesurfer.getDuration();
......@@ -1895,10 +1937,10 @@ new Vue({
// 添加检查区间重叠的方法
checkOverlap(currentRegion, currentIndex) {
if (!this.currentPage || !this.currentPage.groups) return false;
return this.currentPage.groups.some((group, index) => {
if (index === currentIndex) return false; // 跳过当前区间
// 检查是否有重叠
return (currentRegion.start < group.end && currentRegion.end > group.start);
});
......@@ -1916,14 +1958,14 @@ new Vue({
// 进入预览模式
this.isPreviewMode = true;
document.body.classList.add('preview-mode');
// 从当前位置开始播放
this.wavesurfer.play();
this.isPlaying = true;
// 设置播放速度
this.wavesurfer.setPlaybackRate(this.currentPlaybackRate);
// 开始监听播放位置
this.startPreviewMonitoring();
} else {
......@@ -1936,16 +1978,16 @@ new Vue({
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;
......@@ -1955,17 +1997,17 @@ new Vue({
startPreviewMonitoring() {
// 清理可能存在的旧定时器
this.stopPreviewMonitoring();
// 创建新的监听定时器
this.previewTimer = setInterval(() => {
if (!this.isPreviewMode) return;
const currentTime = this.wavesurfer.getCurrentTime();
// 优化:每50ms检查一次
if (currentTime - this.lastCheckedTime < 0.05) return;
this.lastCheckedTime = currentTime;
// 检查是否需要切换页面和选中组
this.checkAndSwitchPage(currentTime);
this.checkAndSelectGroup(currentTime);
......@@ -1983,12 +2025,12 @@ new Vue({
// 新增:检查并切换页面
checkAndSwitchPage(currentTime) {
if (!this.pages || !this.pages.length) return;
// 找到当前时间所在的页面
const targetPage = this.pages.find(page =>
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) {
......@@ -2003,12 +2045,12 @@ new Vue({
// 新增:检查并选中组
checkAndSelectGroup(currentTime) {
if (!this.currentPage || !this.currentPage.groups) return;
// 找到当前时间所在的组
const targetGroup = this.currentPage.groups.findIndex(group =>
const targetGroup = this.currentPage.groups.findIndex(group =>
currentTime >= group.start && currentTime <= group.end
);
if (targetGroup !== -1) {
if (this.selectedGroup !== targetGroup) {
this.selectedGroup = targetGroup;
......@@ -2023,7 +2065,7 @@ new Vue({
// 新增:修改播放速度
changePlaybackRate(rate) {
if (!this.isPreviewMode) return;
this.currentPlaybackRate = rate;
this.wavesurfer.setPlaybackRate(rate);
},
......@@ -2039,12 +2081,12 @@ new Vue({
window.courseware.setData(data, () => {
console.log('----save----');
this.isDataModified = false;
},t_name);
},
}, t_name);
},
// 处理秒的显示
formatTime(_seconds) {
let seconds = Math.round(_seconds*100)/100;
let seconds = Math.round(_seconds * 100) / 100;
// 小数点后保留两位,如果只有一位则补充 0
if (seconds.toString().indexOf('.') === -1) {
seconds = seconds + '.00';
......@@ -2052,21 +2094,186 @@ new Vue({
seconds = seconds + '0';
}
return seconds.toString();
}
},
progressFormat(percentage) {
return percentage === 100 ? '上传完成' : `${percentage}%`;
},
handleExceed() {
this.$message.warning('只能上传一个文件');
},
beforeAudioUpload(file) {
const isMP3 = file.type === 'audio/mp3' || file.type === 'audio/mpeg' || file.name.toLowerCase().endsWith('.mp3');
if (!isMP3) {
this.$message.error('请上传 MP3 格式的音频文件');
}
return isMP3;
},
beforePdfUpload(file) {
const isPDF = file.type === 'application/pdf' || file.name.toLowerCase().endsWith('.pdf');
if (!isPDF) {
this.$message.error('请上传 PDF 格式的文件');
}
return isPDF;
},
async handleAudioUpload(options) {
const { file } = options;
this.audioUploadProgress = 0;
this.audioUploadComplete = false;
const uploadUrl = window.courseware.uploadUrl();
const uploadData = window.courseware.uploadData();
try {
const formData = new FormData();
for (const key in uploadData) {
formData.append(key, uploadData[key]);
}
formData.append('file', file);
const result = await this.uploadFile(formData, uploadUrl, (progress) => {
this.audioUploadProgress = progress;
});
this.audioFile = result.url;
this.audioUploadComplete = true;
this.$message.success('音频文件上传成功');
} catch (error) {
console.error('Error uploading audio:', error);
this.$message.error('音频文件上传失败');
this.audioUploadProgress = 0;
this.audioUploadComplete = false;
}
},
async handlePdfUpload(options) {
const { file } = options;
this.pdfUploadProgress = 0;
this.pdfUploadComplete = false;
const uploadUrl = window.courseware.uploadUrl();
const uploadData = window.courseware.uploadData();
try {
const formData = new FormData();
for (const key in uploadData) {
formData.append(key, uploadData[key]);
}
formData.append('file', file);
const result = await this.uploadFile(formData, uploadUrl, (progress) => {
this.pdfUploadProgress = progress;
});
this.pdfFile = result.url;
this.pdfUploadComplete = true;
this.$message.success('PDF文件上传成功');
} catch (error) {
console.error('Error uploading PDF:', error);
this.$message.error('PDF文件上传失败');
this.pdfUploadProgress = 0;
this.pdfUploadComplete = false;
}
},
uploadFile(formData, url, progressCallback) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open('POST', url);
xhr.upload.onprogress = (event) => {
if (event.lengthComputable) {
const percent = Math.round((event.loaded / event.total) * 100);
progressCallback(percent);
}
};
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
resolve(JSON.parse(xhr.responseText));
} else {
reject(new Error('Upload failed'));
}
}
};
xhr.send(formData);
});
},
removeAudioFile() {
this.audioFile = null;
this.audioUploadProgress = 0;
this.audioUploadComplete = false;
},
removePdfFile() {
this.pdfFile = null;
this.pdfUploadProgress = 0;
this.pdfUploadComplete = false;
},
async handleProcess() {
if (!this.isUploadComplete) {
this.$message.warning('请等待文件上传完成');
return;
}
this.loading = true;
window.courseware.setData({ audioUrl: this.audioFile, pdfUrl: this.pdfFile }, () => {
this.loading = false;
this.checkProcess();
}, t_name);
},
getTimelineItemType(status) {
switch (status) {
case '1': return 'info'; // 未开始
case '2': return 'primary'; // 进行中
case '3': return 'success'; // 已完成
case '4': return 'danger'; // 失败
default: return 'info';
}
},
getTimelineItemColor(status) {
switch (status) {
case '1': return '#909399'; // 未开始
case '2': return '#409eff'; // 进行中
case '3': return '#67c23a'; // 已完成
case '4': return '#f56c6c'; // 失败
default: return '#909399';
}
},
getProgressStatus(status) {
switch (status) {
case '1': return ''; // 未开始
case '2': return ''; // 进行中
case '3': return 'success'; // 已完成
case '4': return 'exception'; // 失败
default: return '';
}
},
},
beforeDestroy() {
// 清理事件监听
document.removeEventListener('mousemove', this.handleMouseMove);
document.removeEventListener('mouseup', this.handleMouseUp);
document.removeEventListener('keydown', this.handleKeydown);
// 清理定时器
this.clearPlayTimer();
// 清理预览模式的定时器
this.stopPreviewMonitoring();
// 销毁波形图
if (this.wavesurfer) {
try {
......@@ -2075,5 +2282,10 @@ new Vue({
console.error('Error destroying wavesurfer:', err);
}
}
},
computed: {
isUploadComplete() {
return this.audioUploadComplete && this.pdfUploadComplete && this.audioFile && this.pdfFile;
}
}
});
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