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