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
9e17fad3
Commit
9e17fad3
authored
May 13, 2025
by
liujiangnan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 可以定位页内的时间段了
parent
065fc7f4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
212 additions
and
96 deletions
+212
-96
index.css
form/index.css
+18
-35
index.html
form/index.html
+2
-29
index.js
form/index.js
+192
-32
No files found.
form/index.css
View file @
9e17fad3
...
@@ -171,13 +171,13 @@ html, body {
...
@@ -171,13 +171,13 @@ html, body {
overflow
:
hidden
;
overflow
:
hidden
;
}
}
#wave-timeline
{
.time-display
{
height
:
20px
!important
;
display
:
inline-block
;
position
:
absolute
;
margin-left
:
10px
;
left
:
0
px
;
font-size
:
14
px
;
right
:
0px
;
color
:
#606266
;
bottom
:
0px
;
min-width
:
6
0px
;
overflow
:
visible
;
text-align
:
center
;
}
}
.audio-controls
{
.audio-controls
{
...
@@ -225,25 +225,6 @@ html, body {
...
@@ -225,25 +225,6 @@ html, body {
margin-left
:
10px
;
margin-left
:
10px
;
}
}
/* 时间调整控件样式 */
.time-adjust-controls
{
display
:
flex
;
align-items
:
center
;
margin-left
:
20px
;
padding-left
:
20px
;
border-left
:
1px
solid
#DCDFE6
;
}
.time-label
{
font-size
:
14px
;
color
:
#606266
;
margin-right
:
5px
;
}
.time-adjust-controls
.el-input-number
{
margin
:
0
5px
;
}
/* 确保滑块和按钮在最上层 */
/* 确保滑块和按钮在最上层 */
.el-slider
{
.el-slider
{
position
:
relative
;
position
:
relative
;
...
@@ -571,33 +552,35 @@ html, body {
...
@@ -571,33 +552,35 @@ html, body {
}
}
/* 组区间样式 */
/* 组区间样式 */
.wavesurfer-region
:not
([
data-id
^=
"page-"
])
{
.wavesurfer-region
[
data-id
^=
"group-"
]
{
background-color
:
rgba
(
64
,
158
,
255
,
0.2
)
;
background-color
:
rgba
(
255
,
165
,
0
,
0.3
)
!important
;
border
:
2px
solid
rgba
(
64
,
158
,
255
,
0.5
)
;
border
:
1px
solid
rgba
(
255
,
165
,
0
,
0.5
)
!important
;
z-index
:
2
!important
;
z-index
:
2
!important
;
cursor
:
pointer
!important
;
cursor
:
pointer
!important
;
}
}
.wavesurfer-region
:not
([
data-id
^=
"page-"
])
:hover
{
.wavesurfer-region
[
data-id
^=
"group-"
]
:hover
{
background-color
:
rgba
(
64
,
158
,
255
,
0.3
)
!important
;
background-color
:
rgba
(
255
,
165
,
0
,
0.4
)
!important
;
}
}
/* 锁定状态下的标记样式 */
/* 锁定状态下的标记样式 */
.wavesurfer-region
[
data-id
$
=
"-start"
]
{
.wavesurfer-region
[
data-id
$
=
"-start"
]
{
background-color
:
rgba
(
0
,
255
,
0
,
0.8
)
!important
;
background-color
:
rgba
(
0
,
255
,
0
,
0.8
)
!important
;
/* width: 1px !important; */
width
:
1px
!important
;
z-index
:
5
!important
;
z-index
:
5
!important
;
}
}
.wavesurfer-region
[
data-id
$
=
"-end"
]
{
.wavesurfer-region
[
data-id
$
=
"-end"
]
{
background-color
:
rgba
(
255
,
0
,
0
,
0.8
)
!important
;
background-color
:
rgba
(
255
,
0
,
0
,
0.8
)
!important
;
/* width: 1px !important; */
width
:
1px
!important
;
z-index
:
5
!important
;
z-index
:
5
!important
;
}
}
/* 锁定状态下隐藏非当前页面的区间 */
/* 锁定状态下隐藏非当前页面的区间 */
.page-locked
.wavesurfer-region
:not
([
data-id
*=
"-start"
])
:not
([
data-id
*=
"-end"
])
:not
([
data-id
$
=
"-${currentPageIndex-1}"
])
{
.page-locked
.wavesurfer-region
[
data-id
^=
"group-"
]
{
display
:
none
!important
;
display
:
block
!important
;
background-color
:
rgba
(
255
,
165
,
0
,
0.3
)
!important
;
border
:
1px
solid
rgba
(
255
,
165
,
0
,
0.5
)
!important
;
}
}
/* 锁定状态下禁用区间拖动 */
/* 锁定状态下禁用区间拖动 */
...
...
form/index.html
View file @
9e17fad3
...
@@ -282,7 +282,6 @@
...
@@ -282,7 +282,6 @@
<!-- 波形图区域 -->
<!-- 波形图区域 -->
<div
class=
"waveform-wrapper"
:class=
"{ 'page-locked': isPageLocked }"
>
<div
class=
"waveform-wrapper"
:class=
"{ 'page-locked': isPageLocked }"
>
<div
id=
"waveform"
></div>
<div
id=
"waveform"
></div>
<div
id=
"wave-timeline"
></div>
</div>
</div>
<!-- 控制按钮区域 -->
<!-- 控制按钮区域 -->
...
@@ -297,6 +296,8 @@
...
@@ -297,6 +296,8 @@
</el-button>
</el-button>
</el-button-group>
</el-button-group>
<span
class=
"time-display"
>
{{ currentTime.toFixed(2) }}s
</span>
<el-button-group
style=
"margin-left: 10px;"
>
<el-button-group
style=
"margin-left: 10px;"
>
<el-button
size=
"small"
@
click=
"handleZoomOut"
:disabled=
"audioLoading"
>
<el-button
size=
"small"
@
click=
"handleZoomOut"
:disabled=
"audioLoading"
>
<i
class=
"el-icon-zoom-out"
></i>
<i
class=
"el-icon-zoom-out"
></i>
...
@@ -316,34 +317,6 @@
...
@@ -316,34 +317,6 @@
{{ isPageLocked ? '解锁页面' : '锁定页面' }}
{{ isPageLocked ? '解锁页面' : '锁定页面' }}
</el-button>
</el-button>
</div>
</div>
<!-- 添加时间调整控件 -->
<div
class=
"time-adjust-controls"
v-if=
"currentGroup"
>
<span
class=
"time-label"
>
开始时间:
</span>
<el-input-number
v-model=
"currentGroup.start"
:min=
"0"
:max=
"currentGroup.end"
:step=
"0.1"
:precision=
"3"
size=
"small"
:disabled=
"isPageLocked"
@
change=
"handleTimeChange('start', $event)"
style=
"width: 120px"
>
</el-input-number>
<span
class=
"time-label"
style=
"margin-left: 10px"
>
结束时间:
</span>
<el-input-number
v-model=
"currentGroup.end"
:min=
"currentGroup.start"
:max=
"wavesurfer ? wavesurfer.getDuration() : 999999"
:step=
"0.1"
:precision=
"3"
size=
"small"
:disabled=
"isPageLocked"
@
change=
"handleTimeChange('end', $event)"
style=
"width: 120px"
>
</el-input-number>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
...
...
form/index.js
View file @
9e17fad3
...
@@ -9,6 +9,7 @@ new Vue({
...
@@ -9,6 +9,7 @@ new Vue({
maxZoom
:
500
,
maxZoom
:
500
,
zoomStep
:
20
,
// 每次放大/缩小的步长
zoomStep
:
20
,
// 每次放大/缩小的步长
audioRegions
:
{},
audioRegions
:
{},
currentTime
:
0
,
// 添加当前时间
// 数据相关
// 数据相关
audioPoints
:
null
,
audioPoints
:
null
,
...
@@ -211,18 +212,6 @@ new Vue({
...
@@ -211,18 +212,6 @@ new Vue({
plugins
:
[
plugins
:
[
WaveSurfer
.
regions
.
create
({
WaveSurfer
.
regions
.
create
({
dragSelection
:
false
// 禁用拖动选择,避免与我们的区域交互冲突
dragSelection
:
false
// 禁用拖动选择,避免与我们的区域交互冲突
}),
WaveSurfer
.
timeline
.
create
({
container
:
'
#wave-timeline
'
,
height
:
20
,
notchPercentHeight
:
50
,
primaryFontColor
:
'
#666
'
,
secondaryFontColor
:
'
#888
'
,
primaryColor
:
'
#666
'
,
secondaryColor
:
'
#888
'
,
timeInterval
:
0.1
,
primaryLabelInterval
:
1
,
secondaryLabelInterval
:
0.5
})
})
]
]
});
});
...
@@ -273,28 +262,27 @@ new Vue({
...
@@ -273,28 +262,27 @@ new Vue({
this
.
currentProgress
=
progress
;
this
.
currentProgress
=
progress
;
});
});
// 添加
播放进度
监听
// 添加
时间更新事件
监听
this
.
wavesurfer
.
on
(
'
audioprocess
'
,
()
=>
{
this
.
wavesurfer
.
on
(
'
audioprocess
'
,
()
=>
{
this
.
currentTime
=
this
.
wavesurfer
.
getCurrentTime
();
if
(
this
.
isPageLocked
)
{
if
(
this
.
isPageLocked
)
{
const
currentTime
=
this
.
wavesurfer
.
getCurrentTime
();
if
(
this
.
currentTime
<
this
.
lockedPageStart
)
{
if
(
currentTime
<
this
.
lockedPageStart
)
{
// 如果播放位置在锁定区间之前,跳转到区间开始
this
.
wavesurfer
.
seekTo
(
this
.
lockedPageStart
/
this
.
wavesurfer
.
getDuration
());
this
.
wavesurfer
.
seekTo
(
this
.
lockedPageStart
/
this
.
wavesurfer
.
getDuration
());
}
else
if
(
currentTime
>
this
.
lockedPageEnd
)
{
}
else
if
(
this
.
currentTime
>
this
.
lockedPageEnd
)
{
// 如果播放位置超过区间结束,停止播放
this
.
wavesurfer
.
pause
();
this
.
wavesurfer
.
pause
();
this
.
isPlaying
=
false
;
this
.
isPlaying
=
false
;
}
}
}
}
});
});
// 添加
定位完成事件监听
// 添加
seek 事件监听,更新时间显示
this
.
wavesurfer
.
on
(
'
seek
'
,
()
=>
{
this
.
wavesurfer
.
on
(
'
seek
'
,
()
=>
{
this
.
currentTime
=
this
.
wavesurfer
.
getCurrentTime
();
if
(
this
.
isPageLocked
)
{
if
(
this
.
isPageLocked
)
{
const
currentTime
=
this
.
wavesurfer
.
getCurrentTime
();
if
(
this
.
currentTime
<
this
.
lockedPageStart
||
this
.
currentTime
>
this
.
lockedPageEnd
)
{
if
(
currentTime
<
this
.
lockedPageStart
||
currentTime
>
this
.
lockedPageEnd
)
{
if
(
this
.
currentTime
<
this
.
lockedPageStart
)
{
// 如果定位到锁定区间外,重置到区间内
if
(
currentTime
<
this
.
lockedPageStart
)
{
this
.
wavesurfer
.
seekTo
(
this
.
lockedPageStart
/
this
.
wavesurfer
.
getDuration
());
this
.
wavesurfer
.
seekTo
(
this
.
lockedPageStart
/
this
.
wavesurfer
.
getDuration
());
}
else
{
}
else
{
this
.
wavesurfer
.
seekTo
(
this
.
lockedPageEnd
/
this
.
wavesurfer
.
getDuration
());
this
.
wavesurfer
.
seekTo
(
this
.
lockedPageEnd
/
this
.
wavesurfer
.
getDuration
());
...
@@ -440,11 +428,32 @@ new Vue({
...
@@ -440,11 +428,32 @@ new Vue({
// 添加区间更新事件处理
// 添加区间更新事件处理
region
.
on
(
'
update-end
'
,
()
=>
{
region
.
on
(
'
update-end
'
,
()
=>
{
// 检查是否与其他区间重叠
const
isOverlapping
=
this
.
checkOverlap
(
region
,
groupIndex
);
// 检查是否超出页面范围
const
isOutOfBounds
=
region
.
start
<
this
.
lockedPageStart
||
region
.
end
>
this
.
lockedPageEnd
;
if
(
isOverlapping
||
isOutOfBounds
)
{
// 如果有重叠或超出范围,恢复到原始位置
region
.
update
({
start
:
group
.
start
,
end
:
group
.
end
});
if
(
isOverlapping
)
{
this
.
$message
.
warning
(
'
区间不能重叠
'
);
}
else
{
this
.
$message
.
warning
(
'
不能超出页面范围
'
);
}
return
;
}
// 更新组的时间范围
group
.
start
=
Number
(
region
.
start
.
toFixed
(
3
));
group
.
start
=
Number
(
region
.
start
.
toFixed
(
3
));
group
.
end
=
Number
(
region
.
end
.
toFixed
(
3
));
group
.
end
=
Number
(
region
.
end
.
toFixed
(
3
));
// 如果当前选中的就是这个组,更新编辑器中的值
// 如果当前选中的就是这个组,更新编辑器中的值
if
(
this
.
selectedGroup
===
groupIndex
&&
this
.
currentPageIndex
-
1
===
pageIndex
)
{
if
(
this
.
selectedGroup
===
groupIndex
)
{
this
.
currentGroup
=
group
;
this
.
currentGroup
=
group
;
}
}
});
});
...
@@ -457,6 +466,91 @@ new Vue({
...
@@ -457,6 +466,91 @@ new Vue({
}
}
});
});
// 重新创建组区间,使用与页面区间相似的样式
if
(
this
.
currentPage
.
groups
)
{
this
.
currentPage
.
groups
.
forEach
((
group
,
groupIndex
)
=>
{
if
(
typeof
group
.
start
===
'
number
'
&&
typeof
group
.
end
===
'
number
'
)
{
const
groupRegionId
=
`group-
${
groupIndex
}
`
;
const
region
=
this
.
wavesurfer
.
addRegion
({
id
:
groupRegionId
,
start
:
group
.
start
,
end
:
group
.
end
,
color
:
'
rgba(255, 165, 0, 0.3)
'
,
drag
:
true
,
// 允许拖动
resize
:
true
,
// 允许调整大小
attributes
:
{
label
:
`Group
${
groupIndex
+
1
}
`
}
});
if
(
region
)
{
this
.
audioRegions
[
groupRegionId
]
=
region
;
// 修改点击事件处理
const
handleClick
=
(
event
)
=>
{
event
.
stopPropagation
();
event
.
preventDefault
();
// 定位到区间开始位置
const
duration
=
this
.
wavesurfer
.
getDuration
();
this
.
wavesurfer
.
seekTo
(
group
.
start
/
duration
);
// 选中对应的组
this
.
selectedGroup
=
groupIndex
;
this
.
currentGroup
=
group
;
// 如果有第一个矩形,选中它
if
(
group
.
group
&&
group
.
group
.
length
>
0
)
{
this
.
selectedItemIndex
=
0
;
}
};
region
.
element
.
removeEventListener
(
'
click
'
,
handleClick
);
region
.
element
.
addEventListener
(
'
click
'
,
handleClick
);
// 添加区间更新事件处理
region
.
on
(
'
update-end
'
,
()
=>
{
// 检查是否与其他区间重叠
const
isOverlapping
=
this
.
checkOverlap
(
region
,
groupIndex
);
// 检查是否超出页面范围
const
isOutOfBounds
=
region
.
start
<
this
.
lockedPageStart
||
region
.
end
>
this
.
lockedPageEnd
;
if
(
isOverlapping
||
isOutOfBounds
)
{
// 如果有重叠或超出范围,恢复到原始位置
region
.
update
({
start
:
group
.
start
,
end
:
group
.
end
});
if
(
isOverlapping
)
{
this
.
$message
.
warning
(
'
区间不能重叠
'
);
}
else
{
this
.
$message
.
warning
(
'
不能超出页面范围
'
);
}
return
;
}
// 更新组的时间范围
group
.
start
=
Number
(
region
.
start
.
toFixed
(
3
));
group
.
end
=
Number
(
region
.
end
.
toFixed
(
3
));
// 如果当前选中的就是这个组,更新编辑器中的值
if
(
this
.
selectedGroup
===
groupIndex
)
{
this
.
currentGroup
=
group
;
}
});
// 确保区间样式正确
this
.
$nextTick
(()
=>
{
if
(
region
.
element
)
{
region
.
element
.
style
.
backgroundColor
=
'
rgba(255, 165, 0, 0.3)
'
;
region
.
element
.
style
.
border
=
'
1px solid rgba(255, 165, 0, 0.5)
'
;
}
});
}
}
});
}
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
'
Error in createAllAudioRegions:
'
,
err
);
console
.
error
(
'
Error in createAllAudioRegions:
'
,
err
);
}
}
...
@@ -1400,32 +1494,86 @@ new Vue({
...
@@ -1400,32 +1494,86 @@ new Vue({
});
});
}
}
// 重新创建组区间
// 重新创建组区间
,使用与页面区间相似的样式
if
(
this
.
currentPage
.
groups
)
{
if
(
this
.
currentPage
.
groups
)
{
this
.
currentPage
.
groups
.
forEach
((
group
,
groupIndex
)
=>
{
this
.
currentPage
.
groups
.
forEach
((
group
,
groupIndex
)
=>
{
if
(
typeof
group
.
start
===
'
number
'
&&
typeof
group
.
end
===
'
number
'
)
{
if
(
typeof
group
.
start
===
'
number
'
&&
typeof
group
.
end
===
'
number
'
)
{
const
groupRegionId
=
`
${
this
.
currentPageIndex
-
1
}
-
${
groupIndex
}
`
;
const
groupRegionId
=
`
group
-
${
groupIndex
}
`
;
const
region
=
this
.
wavesurfer
.
addRegion
({
const
region
=
this
.
wavesurfer
.
addRegion
({
id
:
groupRegionId
,
id
:
groupRegionId
,
start
:
group
.
start
,
start
:
group
.
start
,
end
:
group
.
end
,
end
:
group
.
end
,
color
:
'
rgba(64, 158, 255, 0.4)
'
,
color
:
'
rgba(255, 165, 0, 0.3)
'
,
drag
:
false
,
drag
:
true
,
// 允许拖动
resize
:
false
,
resize
:
true
,
// 允许调整大小
opacity
:
1
attributes
:
{
label
:
`Group
${
groupIndex
+
1
}
`
}
});
});
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
.
startRegionPlayback
(
group
.
start
,
group
.
end
,
groupRegionId
);
// 定位到区间开始位置
const
duration
=
this
.
wavesurfer
.
getDuration
();
this
.
wavesurfer
.
seekTo
(
group
.
start
/
duration
);
// 选中对应的组
this
.
selectedGroup
=
groupIndex
;
this
.
currentGroup
=
group
;
// 如果有第一个矩形,选中它
if
(
group
.
group
&&
group
.
group
.
length
>
0
)
{
this
.
selectedItemIndex
=
0
;
}
};
};
region
.
element
.
removeEventListener
(
'
click
'
,
handleClick
);
region
.
element
.
removeEventListener
(
'
click
'
,
handleClick
);
region
.
element
.
addEventListener
(
'
click
'
,
handleClick
);
region
.
element
.
addEventListener
(
'
click
'
,
handleClick
);
// 添加区间更新事件处理
region
.
on
(
'
update-end
'
,
()
=>
{
// 检查是否与其他区间重叠
const
isOverlapping
=
this
.
checkOverlap
(
region
,
groupIndex
);
// 检查是否超出页面范围
const
isOutOfBounds
=
region
.
start
<
this
.
lockedPageStart
||
region
.
end
>
this
.
lockedPageEnd
;
if
(
isOverlapping
||
isOutOfBounds
)
{
// 如果有重叠或超出范围,恢复到原始位置
region
.
update
({
start
:
group
.
start
,
end
:
group
.
end
});
if
(
isOverlapping
)
{
this
.
$message
.
warning
(
'
区间不能重叠
'
);
}
else
{
this
.
$message
.
warning
(
'
不能超出页面范围
'
);
}
return
;
}
// 更新组的时间范围
group
.
start
=
Number
(
region
.
start
.
toFixed
(
3
));
group
.
end
=
Number
(
region
.
end
.
toFixed
(
3
));
// 如果当前选中的就是这个组,更新编辑器中的值
if
(
this
.
selectedGroup
===
groupIndex
)
{
this
.
currentGroup
=
group
;
}
});
// 确保区间样式正确
this
.
$nextTick
(()
=>
{
if
(
region
.
element
)
{
region
.
element
.
style
.
backgroundColor
=
'
rgba(255, 165, 0, 0.3)
'
;
region
.
element
.
style
.
border
=
'
1px solid rgba(255, 165, 0, 0.5)
'
;
}
});
}
}
}
}
});
});
...
@@ -1682,6 +1830,18 @@ new Vue({
...
@@ -1682,6 +1830,18 @@ new Vue({
}
}
}
}
},
},
// 添加检查区间重叠的方法
checkOverlap
(
currentRegion
,
currentIndex
)
{
if
(
!
this
.
currentPage
||
!
this
.
currentPage
.
groups
)
return
false
;
return
this
.
currentPage
.
groups
.
some
((
group
,
index
)
=>
{
if
(
index
===
currentIndex
)
return
false
;
// 跳过当前区间
// 检查是否有重叠
return
(
currentRegion
.
start
<
group
.
end
&&
currentRegion
.
end
>
group
.
start
);
});
},
},
},
beforeDestroy
()
{
beforeDestroy
()
{
...
...
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