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
0177e9da
Commit
0177e9da
authored
May 12, 2025
by
liujiangnan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:
parent
e9c2dd1d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
213 additions
and
27 deletions
+213
-27
index.css
form/index.css
+40
-0
index.html
form/index.html
+28
-0
index.js
form/index.js
+145
-27
No files found.
form/index.css
View file @
0177e9da
...
...
@@ -178,6 +178,25 @@ html, body {
z-index
:
4
;
}
/* 添加时间调整控件样式 */
.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
;
}
/* 分页器样式 */
.pagination-container
{
position
:
fixed
;
...
...
@@ -327,7 +346,28 @@ html, body {
cursor
:
pointer
!important
;
}
/* 区间拖拽手柄样式 */
.wavesurfer-handle
{
display
:
block
!important
;
position
:
absolute
!important
;
height
:
100%
!important
;
width
:
8px
!important
;
top
:
0
!important
;
cursor
:
ew-resize
!important
;
z-index
:
3
!important
;
background
:
transparent
!important
;
}
.wavesurfer-handle-start
{
left
:
0
!important
;
}
.wavesurfer-handle-end
{
right
:
0
!important
;
}
/* 禁用状态下的手柄样式 */
.wavesurfer-region
[
data-drag
=
"false"
]
.wavesurfer-handle
{
display
:
none
!important
;
}
...
...
form/index.html
View file @
0177e9da
...
...
@@ -307,6 +307,34 @@
<i
:class=
"isPageLocked ? 'el-icon-lock' : 'el-icon-unlock'"
></i>
{{ isPageLocked ? '解锁页面' : '锁定页面' }}
</el-button>
<!-- 添加时间调整控件 -->
<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>
</el-card>
...
...
form/index.js
View file @
0177e9da
...
...
@@ -314,7 +314,6 @@ new Vue({
if
(
page
.
groups
&&
page
.
groups
.
length
>
0
)
{
// 找出所有有效的时间点
const
validTimes
=
page
.
groups
.
reduce
((
acc
,
group
)
=>
{
// 确保时间值是有效的数字且精确到小数点后3位
if
(
typeof
group
.
start
===
'
number
'
&&
!
isNaN
(
group
.
start
))
{
acc
.
starts
.
push
(
Number
(
group
.
start
.
toFixed
(
3
)));
}
...
...
@@ -325,11 +324,9 @@ new Vue({
},
{
starts
:
[],
ends
:
[]
});
if
(
validTimes
.
starts
.
length
>
0
&&
validTimes
.
ends
.
length
>
0
)
{
// 使用精确的最小和最大值
const
start
=
Math
.
min
(...
validTimes
.
starts
);
const
end
=
Math
.
max
(...
validTimes
.
ends
);
// 确保开始时间小于结束时间
if
(
start
<
end
)
{
pageRanges
.
push
({
pageIndex
,
...
...
@@ -354,8 +351,8 @@ new Vue({
start
:
range
.
start
,
end
:
range
.
end
,
color
:
'
rgba(255, 192, 203, 0.3)
'
,
drag
:
false
,
resize
:
false
,
drag
:
!
this
.
isPageLocked
,
resize
:
!
this
.
isPageLocked
,
attributes
:
{
label
:
`Page
${
range
.
pageIndex
+
1
}
`
}
...
...
@@ -366,35 +363,25 @@ new Vue({
// 添加点击事件处理
const
handleClick
=
(
event
)
=>
{
// 阻止事件冒泡
event
.
stopPropagation
();
event
.
preventDefault
();
// 检查页面锁定状态
if
(
this
.
isPageLocked
&&
range
.
pageIndex
!==
this
.
currentPageIndex
-
1
)
{
this
.
$message
.
warning
(
'
页面已锁定,请先解锁
'
);
return
;
}
// 切换到对应的页面
this
.
currentPageIndex
=
range
.
pageIndex
+
1
;
this
.
currentPage
=
this
.
pages
[
range
.
pageIndex
];
// 取消当前选中的组
this
.
selectedGroup
=
null
;
this
.
currentGroup
=
null
;
// 将区域滚动到视图中心并播放
this
.
$nextTick
(()
=>
{
// 开始播放
this
.
startRegionPlayback
(
range
.
start
,
range
.
end
,
pageRegionId
);
// 更新所有区域的样式
this
.
updateRegionsStyle
();
});
};
// 确保事件监听器只添加一次
region
.
element
.
removeEventListener
(
'
click
'
,
handleClick
);
region
.
element
.
addEventListener
(
'
click
'
,
handleClick
);
}
...
...
@@ -407,7 +394,6 @@ new Vue({
this
.
pages
.
forEach
((
page
,
pageIndex
)
=>
{
if
(
page
.
groups
)
{
page
.
groups
.
forEach
((
group
,
groupIndex
)
=>
{
// 确保时间值是有效的数字且精确到小数点后3位
const
start
=
typeof
group
.
start
===
'
number
'
&&
!
isNaN
(
group
.
start
)
?
Number
(
group
.
start
.
toFixed
(
3
))
:
null
;
const
end
=
typeof
group
.
end
===
'
number
'
&&
!
isNaN
(
group
.
end
)
?
...
...
@@ -418,31 +404,65 @@ new Vue({
const
isCurrentPage
=
pageIndex
===
this
.
currentPageIndex
-
1
;
try
{
// 更新区间创建逻辑,添加左右边界拖拽功能
const
region
=
this
.
wavesurfer
.
addRegion
({
id
:
groupRegionId
,
start
:
start
,
end
:
end
,
color
:
isCurrentPage
?
'
rgba(64, 158, 255, 0.2)
'
:
'
rgba(144, 147, 153, 0.1)
'
,
drag
:
isCurrentPage
,
resize
:
isCurrentPage
drag
:
isCurrentPage
&&
!
this
.
isPageLocked
,
resize
:
isCurrentPage
&&
!
this
.
isPageLocked
,
dragLeft
:
isCurrentPage
&&
!
this
.
isPageLocked
,
// 允许拖动左边界
dragRight
:
isCurrentPage
&&
!
this
.
isPageLocked
,
// 允许拖动右边界
opacity
:
(
!
this
.
isPageLocked
||
isCurrentPage
)
?
1
:
0.3
,
handleStyle
:
{
left
:
{
backgroundColor
:
'
#409EFF
'
,
width
:
'
8px
'
,
height
:
'
100%
'
,
cursor
:
'
ew-resize
'
},
right
:
{
backgroundColor
:
'
#409EFF
'
,
width
:
'
8px
'
,
height
:
'
100%
'
,
cursor
:
'
ew-resize
'
}
}
});
if
(
region
)
{
this
.
audioRegions
[
groupRegionId
]
=
region
;
// 为组区间添加点击播放功能
const
handleGroupClick
=
(
event
)
=>
{
// 阻止事件冒泡
event
.
stopPropagation
();
event
.
preventDefault
();
// 开始播放
// 锁定状态下只允许播放当前页面的区间
if
(
this
.
isPageLocked
&&
!
isCurrentPage
)
{
this
.
$message
.
warning
(
'
页面已锁定,只能播放当前页面的区间
'
);
return
;
}
this
.
startRegionPlayback
(
start
,
end
,
groupRegionId
);
};
// 确保事件监听器只添加一次
region
.
element
.
removeEventListener
(
'
click
'
,
handleGroupClick
);
region
.
element
.
addEventListener
(
'
click
'
,
handleGroupClick
);
// 添加区间更新事件处理
region
.
on
(
'
update-end
'
,
()
=>
{
const
group
=
this
.
currentPage
.
groups
[
groupIndex
];
if
(
group
)
{
group
.
start
=
Number
(
region
.
start
.
toFixed
(
3
));
group
.
end
=
Number
(
region
.
end
.
toFixed
(
3
));
// 如果当前选中的就是这个组,更新编辑器中的值
if
(
this
.
selectedGroup
===
groupIndex
)
{
this
.
currentGroup
=
group
;
}
}
});
}
}
catch
(
err
)
{
console
.
error
(
`Error creating group region
${
groupRegionId
}
:`
,
err
);
...
...
@@ -1231,14 +1251,21 @@ new Vue({
// 如果正在播放,先停止
this
.
stopCurrentPlayback
();
// 获取区间的最新时间值
const
region
=
this
.
audioRegions
[
regionId
];
if
(
!
region
)
return
;
const
currentStart
=
region
.
start
;
const
currentEnd
=
region
.
end
;
// 开始新的播放
this
.
wavesurfer
.
seekTo
(
s
tart
/
this
.
wavesurfer
.
getDuration
());
this
.
wavesurfer
.
seekTo
(
currentS
tart
/
this
.
wavesurfer
.
getDuration
());
this
.
wavesurfer
.
play
();
this
.
isPlaying
=
true
;
this
.
currentPlayingRegion
=
regionId
;
// 设置新的定时器
const
playDuration
=
(
end
-
s
tart
)
*
1000
;
// 转换为毫秒
const
playDuration
=
(
currentEnd
-
currentS
tart
)
*
1000
;
// 转换为毫秒
this
.
playTimer
=
setTimeout
(()
=>
{
if
(
this
.
isPlaying
&&
this
.
currentPlayingRegion
===
regionId
)
{
this
.
wavesurfer
.
pause
();
...
...
@@ -1299,9 +1326,8 @@ new Vue({
region
.
update
({
color
:
'
rgba(255, 192, 203, 0.3)
'
,
drag
:
false
,
resize
:
false
,
// 锁定状态下,非当前页区间变暗
drag
:
!
this
.
isPageLocked
,
// 锁定状态下不可拖动
resize
:
!
this
.
isPageLocked
,
// 锁定状态下不可调整大小
opacity
:
(
!
this
.
isPageLocked
||
isCurrentPage
)
?
1
:
0.3
});
...
...
@@ -1324,6 +1350,98 @@ new Vue({
});
});
},
// 新增:更新页面时间范围
updatePageTimeRange
(
type
,
value
)
{
if
(
!
this
.
currentPage
||
this
.
isPageLocked
)
return
;
const
time
=
Number
(
value
);
if
(
isNaN
(
time
))
return
;
// 获取当前页的区间ID
const
pageRegionId
=
`page-
${
this
.
currentPageIndex
-
1
}
`
;
const
region
=
this
.
audioRegions
[
pageRegionId
];
if
(
!
region
)
return
;
if
(
type
===
'
start
'
)
{
// 确保开始时间不大于结束时间
if
(
time
<
region
.
end
)
{
region
.
update
({
start
:
time
});
this
.
currentPage
.
start
=
time
;
}
else
{
this
.
$message
.
warning
(
'
开始时间不能大于结束时间
'
);
// 重置输入值
this
.
currentPage
.
start
=
region
.
start
;
}
}
else
if
(
type
===
'
end
'
)
{
// 确保结束时间不小于开始时间
if
(
time
>
region
.
start
)
{
region
.
update
({
end
:
time
});
this
.
currentPage
.
end
=
time
;
}
else
{
this
.
$message
.
warning
(
'
结束时间不能小于开始时间
'
);
// 重置输入值
this
.
currentPage
.
end
=
region
.
end
;
}
}
},
// 处理时间调整
handleTimeChange
(
type
,
value
)
{
if
(
!
this
.
currentGroup
||
!
this
.
wavesurfer
||
this
.
isPageLocked
)
return
;
try
{
// 确保时间值有效
const
newTime
=
Number
(
value
.
toFixed
(
3
));
const
duration
=
this
.
wavesurfer
.
getDuration
();
if
(
newTime
<
0
||
newTime
>
duration
)
{
this
.
$message
.
warning
(
'
时间值超出范围
'
);
return
;
}
// 更新时间值
if
(
type
===
'
start
'
)
{
if
(
newTime
>=
this
.
currentGroup
.
end
)
{
this
.
$message
.
warning
(
'
开始时间不能大于或等于结束时间
'
);
this
.
currentGroup
.
start
=
Number
((
this
.
currentGroup
.
end
-
0.1
).
toFixed
(
3
));
return
;
}
this
.
currentGroup
.
start
=
newTime
;
}
else
{
if
(
newTime
<=
this
.
currentGroup
.
start
)
{
this
.
$message
.
warning
(
'
结束时间不能小于或等于开始时间
'
);
this
.
currentGroup
.
end
=
Number
((
this
.
currentGroup
.
start
+
0.1
).
toFixed
(
3
));
return
;
}
this
.
currentGroup
.
end
=
newTime
;
}
// 更新音频区域
if
(
this
.
selectedGroup
!==
null
)
{
const
regionId
=
`
${
this
.
currentPageIndex
-
1
}
-
${
this
.
selectedGroup
}
`
;
const
region
=
this
.
audioRegions
[
regionId
];
if
(
region
)
{
region
.
update
({
start
:
this
.
currentGroup
.
start
,
end
:
this
.
currentGroup
.
end
});
}
}
// 如果正在播放该区间,重新开始播放
if
(
this
.
currentPlayingRegion
===
`
${
this
.
currentPageIndex
-
1
}
-
${
this
.
selectedGroup
}
`
)
{
this
.
startRegionPlayback
(
this
.
currentGroup
.
start
,
this
.
currentGroup
.
end
,
this
.
currentPlayingRegion
);
}
}
catch
(
err
)
{
console
.
error
(
'
Error handling time change:
'
,
err
);
this
.
$message
.
error
(
'
时间调整失败
'
);
}
},
},
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