Commit d3955af2 authored by liujiangnan's avatar liujiangnan

feat: 块调整还不完善,先记一版

parent 6455e64c
......@@ -519,19 +519,20 @@ html, body {
display: block !important;
position: absolute !important;
height: 100% !important;
width: 8px !important;
width: 1px !important;
top: 0 !important;
cursor: ew-resize !important;
z-index: 3 !important;
background: transparent !important;
}
.wavesurfer-handle-start {
left: 0 !important;
background-color: rgba(0, 255, 0, 0.8) !important;
}
.wavesurfer-handle-end {
right: 0 !important;
background-color: rgba(255, 0, 0, 0.8) !important;
}
/* 波形图的进度条样式 */
......@@ -563,6 +564,21 @@ html, body {
background-color: rgba(255, 165, 0, 0.4) !important;
}
.wavesurfer-region[data-id^="group-"] .wavesurfer-handle {
display: block !important;
width: 1px !important;
height: 100% !important;
cursor: ew-resize !important;
}
.wavesurfer-region[data-id^="group-"] .wavesurfer-handle-start {
background-color: rgba(0, 255, 0, 0.8) !important;
}
.wavesurfer-region[data-id^="group-"] .wavesurfer-handle-end {
background-color: rgba(255, 0, 0, 0.8) !important;
}
/* 锁定状态下的标记样式 */
.wavesurfer-region[data-id$="-start"] {
background-color: rgba(0, 255, 0, 0.8) !important;
......@@ -576,14 +592,39 @@ html, body {
z-index: 5 !important;
}
/* 锁定状态下隐藏非当前页面的区间 */
/* 锁定状态下的组区间样式 */
.page-locked .wavesurfer-region[data-id^="group-"] {
display: block !important;
background-color: rgba(255, 165, 0, 0.3) !important;
border: 1px solid rgba(255, 165, 0, 0.5) !important;
}
/* 锁定状态下禁用区间拖动 */
.page-locked .wavesurfer-region .wavesurfer-handle {
display: none !important;
/* 锁定状态下允许组区间显示手柄 */
.page-locked .wavesurfer-region[data-id^="group-"] .wavesurfer-handle {
display: block !important;
width: 1px !important;
height: 100% !important;
cursor: ew-resize !important;
}
.page-locked .wavesurfer-region[data-id^="group-"] .wavesurfer-handle-start {
background-color: rgba(0, 255, 0, 0.8) !important;
}
.page-locked .wavesurfer-region[data-id^="group-"] .wavesurfer-handle-end {
background-color: rgba(255, 0, 0, 0.8) !important;
}
#waveform ::part(region-handle-start) {
background-color: rgba(0, 255, 0, 0.8) !important;
width: 1px !important;
height: 100% !important;
cursor: ew-resize !important;
}
#waveform ::part(region-handle-end) {
background-color: rgba(255, 0, 0, 0.8) !important;
width: 1px !important;
height: 100% !important;
cursor: ew-resize !important;
}
\ No newline at end of file
......@@ -211,7 +211,24 @@ new Vue({
backend: 'MediaElement',
plugins: [
WaveSurfer.regions.create({
dragSelection: false // 禁用拖动选择,避免与我们的区域交互冲突
dragSelection: false, // 禁用拖动选择,避免与我们的区域交互冲突
slop: 5, // 调整手柄灵敏度
handleMinWidth: 1, // 最小手柄宽度
handleMaxWidth: 1, // 最大手柄宽度
handleStyle: {
left: {
backgroundColor: 'rgba(0, 255, 0, 0.8)', // 绿色开始手柄
width: '1px',
height: '100%',
cursor: 'ew-resize'
},
right: {
backgroundColor: 'rgba(255, 0, 0, 0.8)', // 红色结束手柄
width: '1px',
height: '100%',
cursor: 'ew-resize'
}
}
})
]
});
......@@ -327,6 +344,22 @@ new Vue({
color: 'rgba(255, 192, 203, 0.3)',
drag: !this.isPageLocked,
resize: !this.isPageLocked,
minLength: 0.1,
maxLength: Infinity,
handleStyle: {
left: {
backgroundColor: 'rgba(0, 255, 0, 0.8)',
width: '1px',
height: '100%',
cursor: 'ew-resize'
},
right: {
backgroundColor: 'rgba(255, 0, 0, 0.8)',
width: '1px',
height: '100%',
cursor: 'ew-resize'
}
},
attributes: {
label: `Page ${pageIndex + 1}`
}
......@@ -378,231 +411,6 @@ new Vue({
}
}
});
// 创建组区间
this.pages.forEach((page, pageIndex) => {
if (page.groups) {
page.groups.forEach((group, groupIndex) => {
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: group.start,
end: group.end,
color: isCurrentPage ? 'rgba(64, 158, 255, 0.2)' : 'rgba(144, 147, 153, 0.1)',
drag: true,
resize: true,
handleStyle: {
left: {
backgroundColor: '#409EFF',
width: '4px',
height: '100%',
cursor: 'ew-resize'
},
right: {
backgroundColor: '#409EFF',
width: '4px',
height: '100%',
cursor: 'ew-resize'
}
}
});
if (region) {
this.audioRegions[groupRegionId] = region;
// 修改点击事件处理
const handleClick = (event) => {
event.stopPropagation();
event.preventDefault();
// 定位到区间开始位置
const duration = this.wavesurfer.getDuration();
this.wavesurfer.seekTo(group.start / duration);
};
region.element.removeEventListener('click', handleClick);
region.element.addEventListener('click', handleClick);
// 添加区间更新事件处理
region.on('update-end', () => {
// 检查是否与其他区间重叠
const isOverlapping = this.checkOverlap(region, groupIndex);
if (isOverlapping) {
// 如果有重叠,恢复到原始位置
region.update({
start: group.start,
end: group.end
});
this.$message.warning('区间不能重叠');
return;
}
let newStart = Number(region.start.toFixed(3));
let newEnd = Number(region.end.toFixed(3));
const duration = newEnd - newStart; // 保存原始区间长度
let needUpdate = false;
// 检查并调整开始时间,同时保持区间长度
if (newStart < this.lockedPageStart) {
newStart = this.lockedPageStart;
newEnd = newStart + duration;
needUpdate = true;
this.$message.warning('已自动调整到页面开始时间');
}
// 检查并调整结束时间,同时保持区间长度
if (newEnd > this.lockedPageEnd) {
newEnd = this.lockedPageEnd;
newStart = newEnd - duration;
// 如果调整后的开始时间小于页面开始时间,则以页面开始时间为准
if (newStart < this.lockedPageStart) {
newStart = this.lockedPageStart;
}
needUpdate = true;
this.$message.warning('已自动调整到页面结束时间');
}
// 如果需要调整,更新区间位置
if (needUpdate) {
region.update({
start: newStart,
end: newEnd
});
}
// 更新组的时间范围
group.start = newStart;
group.end = newEnd;
// 如果当前选中的就是这个组,更新编辑器中的值
if (this.selectedGroup === groupIndex) {
this.currentGroup = group;
}
});
}
} catch (err) {
console.error(`Error creating group region ${groupRegionId}:`, err);
}
}
});
}
});
// 重新创建组区间,使用与页面区间相似的样式
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);
if (isOverlapping) {
// 如果有重叠,恢复到原始位置
region.update({
start: group.start,
end: group.end
});
this.$message.warning('区间不能重叠');
return;
}
let newStart = Number(region.start.toFixed(3));
let newEnd = Number(region.end.toFixed(3));
const duration = newEnd - newStart; // 保存原始区间长度
let needUpdate = false;
// 检查并调整开始时间,同时保持区间长度
if (newStart < this.lockedPageStart) {
newStart = this.lockedPageStart;
newEnd = newStart + duration;
needUpdate = true;
this.$message.warning('已自动调整到页面开始时间');
}
// 检查并调整结束时间,同时保持区间长度
if (newEnd > this.lockedPageEnd) {
newEnd = this.lockedPageEnd;
newStart = newEnd - duration;
// 如果调整后的开始时间小于页面开始时间,则以页面开始时间为准
if (newStart < this.lockedPageStart) {
newStart = this.lockedPageStart;
}
needUpdate = true;
this.$message.warning('已自动调整到页面结束时间');
}
// 如果需要调整,更新区间位置
if (needUpdate) {
region.update({
start: newStart,
end: newEnd
});
}
// 更新组的时间范围
group.start = newStart;
group.end = newEnd;
// 如果当前选中的就是这个组,更新编辑器中的值
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) {
console.error('Error in createAllAudioRegions:', err);
}
......@@ -1385,8 +1193,8 @@ new Vue({
// 如果点击的是矩形框或其相关元素,不处理
if (event.target.closest('.text-rect') ||
event.target.closest('.resize-handle') ||
event.target.closest('.delete-rect-btn') ||
event.target.closest('.add-rect-btn') ||
event.target.closest('.delete-rect-btn') ||
event.target.closest('.add-rect-btn') ||
event.target.closest('.fullscreen-btn')) {
return;
}
......@@ -1402,8 +1210,8 @@ new Vue({
// 如果点击的是矩形框或其相关元素,不处理
if (event.target.closest('.text-rect') ||
event.target.closest('.resize-handle') ||
event.target.closest('.delete-rect-btn') ||
event.target.closest('.add-rect-btn') ||
event.target.closest('.delete-rect-btn') ||
event.target.closest('.add-rect-btn') ||
event.target.closest('.fullscreen-btn')) {
return;
}
......@@ -1546,113 +1354,108 @@ 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}`
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,
minLength: 0.1,
maxLength: Infinity,
handleStyle: {
left: {
backgroundColor: 'rgba(0, 255, 0, 0.8)',
width: '1px',
height: '100%',
cursor: 'ew-resize'
},
right: {
backgroundColor: 'rgba(255, 0, 0, 0.8)',
width: '1px',
height: '100%',
cursor: 'ew-resize'
}
});
}
});
if (region) {
this.audioRegions[groupRegionId] = region;
if (region) {
this.audioRegions[groupRegionId] = region;
// 添加点击事件处理
const handleClick = (event) => {
event.stopPropagation();
event.preventDefault();
// 修改点击事件处理
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);
// 直接选中组,不需要取消选中功能
this.selectedGroup = groupIndex;
this.currentGroup = this.currentPage.groups[groupIndex];
};
// 添加区间更新事件处理
region.on('update-end', () => {
// 检查是否与其他区间重叠
const isOverlapping = this.checkOverlap(region, groupIndex);
if (isOverlapping) {
// 如果有重叠,恢复到原始位置
region.update({
start: group.start,
end: group.end
});
this.$message.warning('区间不能重叠');
return;
}
let newStart = Number(region.start.toFixed(3));
let newEnd = Number(region.end.toFixed(3));
const duration = newEnd - newStart; // 保存原始区间长度
let needUpdate = false;
// 检查并调整开始时间,同时保持区间长度
region.element.removeEventListener('click', handleClick);
region.element.addEventListener('click', handleClick);
// 添加区间更新事件处理
region.on('update-end', () => {
// 检查是否与其他区间重叠
const isOverlapping = this.checkOverlap(region, groupIndex);
if (isOverlapping) {
// 如果有重叠,恢复到原始位置
region.update({
start: group.start,
end: group.end
});
this.$message.warning('区间不能重叠');
return;
}
let newStart = Number(region.start.toFixed(3));
let newEnd = Number(region.end.toFixed(3));
const duration = newEnd - newStart; // 保存原始区间长度
let needUpdate = false;
// 检查并调整开始时间,同时保持区间长度
if (newStart < this.lockedPageStart) {
newStart = this.lockedPageStart;
newEnd = newStart + duration;
needUpdate = true;
this.$message.warning('已自动调整到页面开始时间');
}
// 检查并调整结束时间,同时保持区间长度
if (newEnd > this.lockedPageEnd) {
newEnd = this.lockedPageEnd;
newStart = newEnd - duration;
// 如果调整后的开始时间小于页面开始时间,则以页面开始时间为准
if (newStart < this.lockedPageStart) {
newStart = this.lockedPageStart;
newEnd = newStart + duration;
needUpdate = true;
this.$message.warning('已自动调整到页面开始时间');
}
// 检查并调整结束时间,同时保持区间长度
if (newEnd > this.lockedPageEnd) {
newEnd = this.lockedPageEnd;
newStart = newEnd - duration;
// 如果调整后的开始时间小于页面开始时间,则以页面开始时间为准
if (newStart < this.lockedPageStart) {
newStart = this.lockedPageStart;
}
needUpdate = true;
this.$message.warning('已自动调整到页面结束时间');
}
// 如果需要调整,更新区间位置
if (needUpdate) {
region.update({
start: newStart,
end: newEnd
});
}
// 更新组的时间范围
group.start = newStart;
group.end = newEnd;
// 如果当前选中的就是这个组,更新编辑器中的值
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)';
}
});
}
needUpdate = true;
this.$message.warning('已自动调整到页面结束时间');
}
// 如果需要调整,更新区间位置
if (needUpdate) {
region.update({
start: newStart,
end: newEnd
});
}
// 更新组的时间范围
group.start = newStart;
group.end = newEnd;
// 如果当前选中的就是这个组,更新编辑器中的值
if (this.selectedGroup === groupIndex) {
this.currentGroup = group;
}
});
}
});
}
......
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