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