Commit 3f1b1d59 authored by liujiangnan's avatar liujiangnan

feat:

parent 0177e9da
......@@ -134,40 +134,50 @@ html, body {
/* 音频控制区域 */
.audio-control {
height: 200px;
height: 185px;
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 1000;
margin: 0;
border-radius: 0;
box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}
.audio-control .el-card__body {
background: #fff;
border-top: 1px dashed #DCDFE6;
padding: 10px 20px;
}
.waveform-container {
height: 100%;
height: 90px;
display: flex;
flex-direction: column;
position: relative;
background: white;
}
/* 波形图区域样式 */
.waveform-wrapper {
position: relative;
padding: 10px 10px 0;
background: #fff;
height: 116px;
overflow: visible;
}
#waveform {
flex: 1;
min-height: 120px;
height: 116px !important;
position: relative;
background: white;
margin-bottom: 5px;
overflow: hidden;
}
#wave-timeline {
height: 30px;
margin-bottom: 5px;
position: relative;
height: 20px !important;
position: absolute;
left: 0px;
right: 0px;
bottom: 0px;
overflow: visible;
}
.audio-controls {
......@@ -178,7 +188,44 @@ html, body {
z-index: 4;
}
/* 添加时间调整控件样式 */
/* 控制按钮区域样式 */
.control-wrapper {
position: absolute;
bottom: 0;
left: 0;
right: 0;
z-index: 1000;
padding: 10px;
background: #fff;
}
.basic-controls {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
}
.basic-controls .el-button-group {
margin-right: 20px;
display: inline-flex;
}
.basic-controls .el-button-group .el-button {
margin: 0;
}
.basic-controls .el-slider {
margin: 0 20px;
width: 200px;
flex-shrink: 0;
}
.basic-controls .el-button:not(.el-button-group .el-button) {
margin-left: 10px;
}
/* 时间调整控件样式 */
.time-adjust-controls {
display: flex;
align-items: center;
......@@ -197,6 +244,158 @@ html, body {
margin: 0 5px;
}
/* 确保滑块和按钮在最上层 */
.el-slider {
position: relative;
z-index: 1000;
}
.el-slider__runway {
z-index: 1000;
}
.el-slider__bar {
z-index: 1000;
}
.el-slider__button-wrapper {
z-index: 1000;
}
.el-button-group {
position: relative;
z-index: 1000;
}
.el-button {
position: relative;
z-index: 1000;
}
/* 锁定按钮特殊样式 */
.el-button--danger.is-active,
.el-button--danger:active {
background: #f56c6c;
border-color: #f56c6c;
color: #fff;
}
/* 其他样式 */
.app{
position: relative;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
}
/* 新建矩形框按钮 */
.add-rect-btn {
position: absolute;
right: 15px;
bottom: 15px;
z-index: 100;
opacity: 0.8;
transition: opacity 0.3s;
box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
}
.add-rect-btn:hover {
opacity: 1;
}
.group-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 10px;
margin: 16px 0;
border-bottom: 1px solid #DCDFE6;
}
.group-title {
font-size: 14px;
font-weight: 500;
color: #303133;
padding: 0 8px 8px;
position: relative;
}
.group-title::after {
content: '';
position: absolute;
bottom: -1px;
left: 0;
right: 0;
height: 2px;
background-color: #409EFF;
}
/* 全屏按钮 */
.fullscreen-btn {
position: absolute;
right: 15px;
top: 15px;
z-index: 100;
opacity: 0.8;
transition: opacity 0.3s;
box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
}
.fullscreen-btn:hover {
opacity: 1;
}
/* 全屏编辑器 */
.fullscreen-editor {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.7);
z-index: 2000;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.fullscreen-content {
background-color: #fff;
border-radius: 4px;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
overflow: hidden;
}
.fullscreen-content .image-container {
flex: 1;
margin: 0;
border: none;
border-radius: 0;
display: flex;
justify-content: center;
align-items: center;
background-color: #f5f7fa;
}
.fullscreen-content .image-wrapper {
position: relative;
display: flex;
justify-content: center;
align-items: center;
line-height: 0;
}
.fullscreen-content img {
display: block;
max-width: 100%;
max-height: 100%;
}
/* 分页器样式 */
.pagination-container {
position: fixed;
......@@ -325,28 +524,16 @@ html, body {
line-height: 40px;
}
/* 区域样式 */
.wavesurfer-region {
z-index: 2 !important;
border: 1px solid rgba(0, 0, 0, 0.1);
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
transition: background-color 0.2s ease;
pointer-events: all !important;
cursor: pointer !important;
}
/* 页面区间样式 */
.wavesurfer-region[data-id^="page-"] {
z-index: 3 !important;
background: rgba(255, 192, 203, 0.3) !important;
border: 2px solid rgba(255, 192, 203, 0.8) !important;
pointer-events: all !important;
cursor: pointer !important;
}
/* 组区间样式 */
.wavesurfer-region:not([data-id^="page-"]) {
z-index: 1 !important;
cursor: pointer !important;
}
/* 区间拖拽手柄样式 */
/* 波形图的拖动手柄样式 */
.wavesurfer-handle {
display: block !important;
position: absolute !important;
......@@ -366,122 +553,54 @@ html, body {
right: 0 !important;
}
/* 禁用状态下的手柄样式 */
.wavesurfer-region[data-drag="false"] .wavesurfer-handle {
display: none !important;
}
.app{
position: relative;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
/* 波形图的进度条样式 */
.wavesurfer-cursor {
z-index: 4 !important;
}
/* 新建矩形框按钮 */
.add-rect-btn {
position: absolute;
right: 15px;
bottom: 15px;
z-index: 100;
opacity: 0.8;
transition: opacity 0.3s;
box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
}
.add-rect-btn:hover {
opacity: 1;
}
.group-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 10px;
margin: 16px 0;
border-bottom: 1px solid #DCDFE6;
}
.group-title {
font-size: 14px;
font-weight: 500;
color: #303133;
padding: 0 8px 8px;
position: relative;
/* 页面区间样式 */
.wavesurfer-region[data-id^="page-"] {
z-index: 3 !important;
background-color: rgba(255, 0, 0, 0.2) !important;
pointer-events: all !important;
cursor: pointer !important;
}
.group-title::after {
content: '';
position: absolute;
bottom: -1px;
left: 0;
right: 0;
height: 2px;
background-color: #409EFF;
.wavesurfer-region[data-id^="page-"]:hover {
background-color: rgba(255, 0, 0, 0.3) !important;
}
/* 全屏按钮 */
.fullscreen-btn {
position: absolute;
right: 15px;
top: 15px;
z-index: 100;
opacity: 0.8;
transition: opacity 0.3s;
box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
}
.fullscreen-btn:hover {
opacity: 1;
/* 组区间样式 */
.wavesurfer-region:not([data-id^="page-"]) {
background-color: rgba(64, 158, 255, 0.2);
border: 2px solid rgba(64, 158, 255, 0.5);
z-index: 2 !important;
cursor: pointer !important;
}
/* 全屏编辑器 */
.fullscreen-editor {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.7);
z-index: 2000;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
.wavesurfer-region:not([data-id^="page-"]):hover {
background-color: rgba(64, 158, 255, 0.3) !important;
}
.fullscreen-content {
background-color: #fff;
border-radius: 4px;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
overflow: hidden;
/* 锁定状态下的标记样式 */
.wavesurfer-region[data-id$="-start"] {
background-color: rgba(0, 255, 0, 0.8) !important;
width: 1px !important;
z-index: 5 !important;
}
.fullscreen-content .image-container {
flex: 1;
margin: 0;
border: none;
border-radius: 0;
display: flex;
justify-content: center;
align-items: center;
background-color: #f5f7fa;
.wavesurfer-region[data-id$="-end"] {
background-color: rgba(255, 0, 0, 0.8) !important;
width: 1px !important;
z-index: 5 !important;
}
.fullscreen-content .image-wrapper {
position: relative;
display: flex;
justify-content: center;
align-items: center;
line-height: 0;
/* 锁定状态下隐藏非当前页面的区间 */
.page-locked .wavesurfer-region:not([data-id*="-start"]):not([data-id*="-end"]):not([data-id$="-${currentPageIndex-1}"]) {
display: none !important;
}
.fullscreen-content img {
display: block;
max-width: 100%;
max-height: 100%;
/* 锁定状态下禁用区间拖动 */
.page-locked .wavesurfer-region .wavesurfer-handle {
display: none !important;
}
\ No newline at end of file
......@@ -278,11 +278,16 @@
</div>
<!-- 音频控制区域 -->
<el-card class="audio-control" v-loading="audioLoading">
<div class="waveform-container">
<div class="audio-control" v-loading="audioLoading">
<!-- 波形图区域 -->
<div class="waveform-wrapper" :class="{ 'page-locked': isPageLocked }">
<div id="waveform"></div>
<div id="wave-timeline"></div>
<div class="audio-controls">
</div>
<!-- 控制按钮区域 -->
<div class="control-wrapper">
<div class="basic-controls">
<el-button-group>
<el-button size="small" @click="playAudio" :disabled="audioLoading">
<i :class="isPlaying ? 'el-icon-video-pause' : 'el-icon-video-play'"></i>
......@@ -291,54 +296,56 @@
<i class="el-icon-video-stop"></i>
</el-button>
</el-button-group>
<el-slider
v-model="zoomLevel"
:min="1"
:max="500"
@change="handleZoom"
:disabled="audioLoading"
style="width: 200px; margin-left: 20px;">
style="width: 200px;">
</el-slider>
<el-button
size="small"
:type="isPageLocked ? 'danger' : 'primary'"
@click="togglePageLock"
style="margin-left: 20px;">
:class="{ 'is-active': isPageLocked }">
<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 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>
</el-card>
</div>
</div>
</div>
</body>
<script src="./index.js"></script>
</html>
\ No newline at end of file
......@@ -50,6 +50,7 @@ new Vue({
isPageLocked: false,
lockedPageStart: null,
lockedPageEnd: null,
previousZoomLevel: null,
},
mounted() {
......@@ -209,10 +210,11 @@ new Vue({
container: '#wave-timeline',
height: 20,
notchPercentHeight: 50,
primaryFontColor: '#666',
secondaryFontColor: '#888',
primaryColor: '#666',
secondaryColor: '#888'
primaryFontColor: 'rgba(102, 102, 102, 0.7)',
secondaryFontColor: 'rgba(136, 136, 136, 0.5)',
primaryColor: 'rgba(102, 102, 102, 0.7)',
secondaryColor: 'rgba(136, 136, 136, 0.5)',
style: 'background-color: rgba(255, 255, 255, 0.1);'
})
]
});
......@@ -308,85 +310,67 @@ new Vue({
this.wavesurfer.clearRegions();
this.audioRegions = {};
// 先收集所有有效的页面时间范围
const pageRanges = [];
// 创建页面区间
this.pages.forEach((page, pageIndex) => {
// 只为有组的页面创建区间
if (page.groups && page.groups.length > 0) {
// 找出所有有效的时间点
const validTimes = page.groups.reduce((acc, group) => {
if (typeof group.start === 'number' && !isNaN(group.start)) {
acc.starts.push(Number(group.start.toFixed(3)));
}
if (typeof group.end === 'number' && !isNaN(group.end)) {
acc.ends.push(Number(group.end.toFixed(3)));
}
return acc;
}, { 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,
start,
end
});
}
}
}
});
// 按开始时间排序
pageRanges.sort((a, b) => a.start - b.start);
// 创建页面区间,确保不重叠
pageRanges.forEach((range, index) => {
const pageRegionId = `page-${range.pageIndex}`;
try {
// 创建区域
const region = this.wavesurfer.addRegion({
id: pageRegionId,
start: range.start,
end: range.end,
color: 'rgba(255, 192, 203, 0.3)',
drag: !this.isPageLocked,
resize: !this.isPageLocked,
attributes: {
label: `Page ${range.pageIndex + 1}`
}
});
if (region) {
this.audioRegions[pageRegionId] = region;
// 添加点击事件处理
const handleClick = (event) => {
event.stopPropagation();
event.preventDefault();
if (this.isPageLocked && range.pageIndex !== this.currentPageIndex - 1) {
this.$message.warning('页面已锁定,请先解锁');
return;
const pageRegionId = `page-${pageIndex}`;
try {
// 创建区域,使用页面自身的时间
const region = this.wavesurfer.addRegion({
id: pageRegionId,
start: page.start,
end: page.end,
color: 'rgba(255, 192, 203, 0.3)',
drag: !this.isPageLocked,
resize: !this.isPageLocked,
attributes: {
label: `Page ${pageIndex + 1}`
}
});
if (region) {
this.audioRegions[pageRegionId] = region;
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();
// 添加点击事件处理
const handleClick = (event) => {
event.stopPropagation();
event.preventDefault();
if (this.isPageLocked && pageIndex !== this.currentPageIndex - 1) {
this.$message.warning('页面已锁定,请先解锁');
return;
}
this.currentPageIndex = pageIndex + 1;
this.currentPage = this.pages[pageIndex];
this.selectedGroup = null;
this.currentGroup = null;
this.$nextTick(() => {
this.startRegionPlayback(page.start, page.end, pageRegionId);
this.updateRegionsStyle();
});
};
region.element.removeEventListener('click', handleClick);
region.element.addEventListener('click', handleClick);
// 添加区间更新事件处理
region.on('update-end', () => {
// 直接更新页面时间
page.start = Number(region.start.toFixed(3));
page.end = Number(region.end.toFixed(3));
// 如果是当前页面,更新视图
if (pageIndex === this.currentPageIndex - 1) {
this.updatePageTimeRange();
}
});
};
region.element.removeEventListener('click', handleClick);
region.element.addEventListener('click', handleClick);
}
} catch (err) {
console.error(`Error creating page region ${pageRegionId}:`, err);
}
} catch (err) {
console.error(`Error creating page region ${pageRegionId}:`, err);
}
});
......@@ -394,37 +378,28 @@ new Vue({
this.pages.forEach((page, pageIndex) => {
if (page.groups) {
page.groups.forEach((group, groupIndex) => {
const start = typeof group.start === 'number' && !isNaN(group.start) ?
Number(group.start.toFixed(3)) : null;
const end = typeof group.end === 'number' && !isNaN(group.end) ?
Number(group.end.toFixed(3)) : null;
if (start !== null && end !== null && start < end) {
if (typeof group.start === 'number' && typeof group.end === 'number') {
const groupRegionId = `${pageIndex}-${groupIndex}`;
const isCurrentPage = pageIndex === this.currentPageIndex - 1;
try {
// 更新区间创建逻辑,添加左右边界拖拽功能
const region = this.wavesurfer.addRegion({
id: groupRegionId,
start: start,
end: end,
start: group.start,
end: group.end,
color: isCurrentPage ? 'rgba(64, 158, 255, 0.2)' : 'rgba(144, 147, 153, 0.1)',
drag: isCurrentPage && !this.isPageLocked,
resize: isCurrentPage && !this.isPageLocked,
dragLeft: isCurrentPage && !this.isPageLocked, // 允许拖动左边界
dragRight: isCurrentPage && !this.isPageLocked, // 允许拖动右边界
opacity: (!this.isPageLocked || isCurrentPage) ? 1 : 0.3,
drag: true,
resize: true,
handleStyle: {
left: {
backgroundColor: '#409EFF',
width: '8px',
width: '4px',
height: '100%',
cursor: 'ew-resize'
},
right: {
backgroundColor: '#409EFF',
width: '8px',
width: '4px',
height: '100%',
cursor: 'ew-resize'
}
......@@ -434,33 +409,23 @@ new Vue({
if (region) {
this.audioRegions[groupRegionId] = region;
const handleGroupClick = (event) => {
// 添加点击事件
const handleClick = (event) => {
event.stopPropagation();
event.preventDefault();
// 锁定状态下只允许播放当前页面的区间
if (this.isPageLocked && !isCurrentPage) {
this.$message.warning('页面已锁定,只能播放当前页面的区间');
return;
}
this.startRegionPlayback(start, end, groupRegionId);
this.startRegionPlayback(group.start, group.end, groupRegionId);
};
region.element.removeEventListener('click', handleGroupClick);
region.element.addEventListener('click', handleGroupClick);
region.element.removeEventListener('click', handleClick);
region.element.addEventListener('click', handleClick);
// 添加区间更新事件处理
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;
}
group.start = Number(region.start.toFixed(3));
group.end = Number(region.end.toFixed(3));
// 如果当前选中的就是这个组,更新编辑器中的值
if (this.selectedGroup === groupIndex && this.currentPageIndex - 1 === pageIndex) {
this.currentGroup = group;
}
});
}
......@@ -1280,119 +1245,181 @@ new Vue({
if (!this.currentPage) return;
if (!this.isPageLocked) {
// 获取当前页面的时间范围
const times = this.currentPage.groups.reduce((acc, group) => {
if (typeof group.start === 'number' && !isNaN(group.start)) {
acc.starts.push(group.start);
}
if (typeof group.end === 'number' && !isNaN(group.end)) {
acc.ends.push(group.end);
}
return acc;
}, { starts: [], ends: [] });
// 保存当前缩放级别
this.previousZoomLevel = this.zoomLevel;
if (times.starts.length > 0 && times.ends.length > 0) {
this.lockedPageStart = Math.min(...times.starts);
this.lockedPageEnd = Math.max(...times.ends);
this.isPageLocked = true;
this.$message.success('页面已锁定');
} else {
this.$message.warning('当前页面没有有效的时间范围');
return;
}
} else {
// 解锁页面
this.isPageLocked = false;
this.lockedPageStart = null;
this.lockedPageEnd = null;
this.$message.success('页面已解锁');
}
// 使用当前页面的实际时间范围
this.lockedPageStart = this.currentPage.start;
this.lockedPageEnd = this.currentPage.end;
this.isPageLocked = true;
// 更新波形图区域样式
this.updateRegionsStyle();
},
// 添加锁定状态的类名
document.body.classList.add('page-locked');
// 新增:更新区域样式的统一方法
updateRegionsStyle() {
Object.keys(this.audioRegions).forEach(regionId => {
const region = this.audioRegions[regionId];
if (!region) return;
// 清除所有现有区间
Object.keys(this.audioRegions).forEach(regionId => {
const region = this.audioRegions[regionId];
if (region) {
region.remove();
}
});
this.audioRegions = {};
// 如果是页面区间
if (regionId.startsWith('page-')) {
const pageIndex = parseInt(regionId.split('-')[1]);
const isCurrentPage = pageIndex === this.currentPageIndex - 1;
const isClickable = !this.isPageLocked || isCurrentPage;
// 为当前页创建开始和结束标记
const pageRegionId = `page-${this.currentPageIndex - 1}`;
// 创建开始标记(绿色竖线)
const startMarker = this.wavesurfer.addRegion({
id: `${pageRegionId}-start`,
start: this.lockedPageStart,
end: this.lockedPageStart + 0.0001,
color: 'rgba(0, 255, 0, 0.8)',
drag: false,
resize: false
});
region.update({
color: 'rgba(255, 192, 203, 0.3)',
drag: !this.isPageLocked, // 锁定状态下不可拖动
resize: !this.isPageLocked, // 锁定状态下不可调整大小
opacity: (!this.isPageLocked || isCurrentPage) ? 1 : 0.3
});
// 创建结束标记(红色竖线)
const endMarker = this.wavesurfer.addRegion({
id: `${pageRegionId}-end`,
start: this.lockedPageEnd - 0.0001,
end: this.lockedPageEnd,
color: 'rgba(255, 0, 0, 0.8)',
drag: false,
resize: false
});
// 更新点击事件处理
if (region.element) {
region.element.style.pointerEvents = isClickable ? 'all' : 'none';
}
return;
if (startMarker && endMarker) {
this.audioRegions[`${pageRegionId}-start`] = startMarker;
this.audioRegions[`${pageRegionId}-end`] = endMarker;
}
// 处理组区间
const [pageIndex, groupIndex] = regionId.split('-').map(Number);
const isCurrentPage = pageIndex === this.currentPageIndex - 1;
// 重新创建组区间
if (this.currentPage.groups) {
this.currentPage.groups.forEach((group, groupIndex) => {
if (typeof group.start === 'number' && typeof group.end === 'number') {
const groupRegionId = `${this.currentPageIndex - 1}-${groupIndex}`;
const region = this.wavesurfer.addRegion({
id: groupRegionId,
start: group.start,
end: group.end,
color: 'rgba(64, 158, 255, 0.4)',
drag: false,
resize: false,
opacity: 1
});
if (region) {
this.audioRegions[groupRegionId] = region;
// 添加点击事件
const handleClick = (event) => {
event.stopPropagation();
event.preventDefault();
this.startRegionPlayback(group.start, group.end, groupRegionId);
};
region.element.removeEventListener('click', handleClick);
region.element.addEventListener('click', handleClick);
}
}
});
}
// 计算并应用缩放
const duration = this.lockedPageEnd - this.lockedPageStart;
const padding = duration * 0.1;
const displayStart = Math.max(0, this.lockedPageStart - padding);
const displayEnd = Math.min(this.wavesurfer.getDuration(), this.lockedPageEnd + padding);
const displayDuration = displayEnd - displayStart;
const totalDuration = this.wavesurfer.getDuration();
const zoomLevel = Math.min(500, Math.floor((totalDuration / displayDuration) * 1.25));
region.update({
color: isCurrentPage ? 'rgba(64, 158, 255, 0.2)' : 'rgba(144, 147, 153, 0.1)',
drag: isCurrentPage,
resize: isCurrentPage,
opacity: (!this.isPageLocked || isCurrentPage) ? 1 : 0.3
// 先设置缩放
this.zoomLevel = zoomLevel;
this.wavesurfer.zoom(zoomLevel);
// 等待缩放完成后再调整位置
this.$nextTick(() => {
// 将视图中心定位到锁定区间中心
const center = (this.lockedPageStart + this.lockedPageEnd) / 2;
this.wavesurfer.seekTo(center / totalDuration);
});
});
this.$message.success('页面已锁定');
} else {
// 解除锁定状态
this.isPageLocked = false;
// 保存当前页面的时间范围到 pages 数组
const currentPageIndex = this.currentPageIndex - 1;
if (this.pages[currentPageIndex]) {
this.pages[currentPageIndex].start = this.currentPage.start;
this.pages[currentPageIndex].end = this.currentPage.end;
}
this.lockedPageStart = null;
this.lockedPageEnd = null;
// 移除锁定状态的类名
document.body.classList.remove('page-locked');
// 重新创建所有区间
this.createAllAudioRegions();
// 恢复到之前的缩放级别
if (this.previousZoomLevel !== null) {
this.zoomLevel = this.previousZoomLevel;
this.wavesurfer.zoom(this.previousZoomLevel);
this.previousZoomLevel = null;
}
this.$message.success('页面已解锁');
}
},
// 新增:更新页面时间范围
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;
// 更新页面时间范围的方法
updatePageTimeRange() {
if (!this.currentPage) return;
if (type === 'start') {
// 确保开始时间不大于结束时间
if (time < region.end) {
region.update({
start: time
// 如果页面已锁定,更新锁定范围和标记
if (this.isPageLocked) {
this.lockedPageStart = this.currentPage.start;
this.lockedPageEnd = this.currentPage.end;
const pageIndex = this.currentPageIndex - 1;
const pageRegionId = `page-${pageIndex}`;
const startMarker = this.audioRegions[`${pageRegionId}-start`];
const endMarker = this.audioRegions[`${pageRegionId}-end`];
if (startMarker) {
startMarker.update({
start: this.currentPage.start,
end: this.currentPage.start + 0.0001
});
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
if (endMarker) {
endMarker.update({
start: this.currentPage.end - 0.0001,
end: this.currentPage.end
});
this.currentPage.end = time;
} else {
this.$message.warning('结束时间不能小于开始时间');
// 重置输入值
this.currentPage.end = region.end;
}
}
// 更新页面区间
const pageIndex = this.currentPageIndex - 1;
const pageRegionId = `page-${pageIndex}`;
const pageRegion = this.audioRegions[pageRegionId];
if (pageRegion) {
pageRegion.update({
start: this.currentPage.start,
end: this.currentPage.end
});
}
},
// 处理时间调整
handleTimeChange(type, value) {
if (!this.currentGroup || !this.wavesurfer || this.isPageLocked) return;
// 处理页面时间变化
handlePageTimeChange(type, value) {
if (!this.currentPage || !this.wavesurfer) return;
try {
// 确保时间值有效
......@@ -1406,42 +1433,47 @@ new Vue({
// 更新时间值
if (type === 'start') {
if (newTime >= this.currentGroup.end) {
if (newTime >= this.currentPage.end) {
this.$message.warning('开始时间不能大于或等于结束时间');
this.currentGroup.start = Number((this.currentGroup.end - 0.1).toFixed(3));
return;
}
this.currentGroup.start = newTime;
this.currentPage.start = newTime;
} else {
if (newTime <= this.currentGroup.start) {
if (newTime <= this.currentPage.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);
this.currentPage.end = newTime;
}
// 更新页面时间范围(这会同步更新区间和锁定标记)
this.updatePageTimeRange();
} catch (err) {
console.error('Error handling time change:', err);
console.error('Error handling page time change:', err);
this.$message.error('时间调整失败');
}
},
// 更新区域样式的方法
updateRegionsStyle() {
if (!this.wavesurfer) return;
Object.keys(this.audioRegions).forEach(regionId => {
// 跳过页面区间
if (regionId.startsWith('page-')) return;
const [pageIndex, groupIndex] = regionId.split('-').map(Number);
const region = this.audioRegions[regionId];
const isCurrentPage = pageIndex === this.currentPageIndex - 1;
if (region) {
region.update({
color: isCurrentPage ? 'rgba(64, 158, 255, 0.2)' : 'rgba(144, 147, 153, 0.1)',
opacity: (!this.isPageLocked || isCurrentPage) ? 1 : 0.3
});
}
});
},
},
beforeDestroy() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment