修复布局

This commit is contained in:
CN-JS-HuiBai
2026-04-02 23:01:20 +08:00
parent 52c8466ddd
commit 47246061b2
3 changed files with 74 additions and 15 deletions

View File

@@ -31,6 +31,8 @@ document.addEventListener('DOMContentLoaded', () => {
const playbackStatus = document.getElementById('playback-status');
const playbackStatusText = document.getElementById('playback-status-text');
const playbackSpeed = document.getElementById('playback-speed');
const transcodeProgressChip = document.getElementById('transcode-progress-chip');
const playbackProgressChip = document.getElementById('playback-progress-chip');
// Download phase elements
const downloadPhase = document.getElementById('download-phase');
@@ -127,7 +129,8 @@ document.addEventListener('DOMContentLoaded', () => {
const updatePlayControls = () => {
if (controlPlayToggle) {
controlPlayToggle.textContent = videoPlayer.paused ? 'Play' : 'Pause';
controlPlayToggle.textContent = videoPlayer.paused ? '>' : '||';
controlPlayToggle.setAttribute('aria-label', videoPlayer.paused ? 'Play' : 'Pause');
}
if (playbackStatus) {
playbackStatus.classList.remove('playing', 'paused', 'seeking');
@@ -166,6 +169,19 @@ document.addEventListener('DOMContentLoaded', () => {
}
};
const updatePlaybackProgressChip = (absoluteTime = 0) => {
if (!playbackProgressChip) return;
const safeDuration = videoDuration > 0 ? videoDuration : 0;
const percent = safeDuration > 0 ? Math.min(Math.max(Math.round((absoluteTime / safeDuration) * 100), 0), 100) : 0;
playbackProgressChip.textContent = `Play ${percent}%`;
};
const updateTranscodeProgressChip = (percent = 0, label = 'Transcode') => {
if (!transcodeProgressChip) return;
const safePercent = Math.min(Math.max(Math.round(percent || 0), 0), 100);
transcodeProgressChip.textContent = `${label} ${safePercent}%`;
};
const showCustomControls = () => {
if (customControls) {
customControls.classList.remove('hidden');
@@ -238,6 +254,7 @@ document.addEventListener('DOMContentLoaded', () => {
if (seekTotalTime) seekTotalTime.textContent = formatTime(videoDuration);
showSeekBar();
updateSeekBarPosition(seekOffset + (videoPlayer.currentTime || 0));
updatePlaybackProgressChip(seekOffset + (videoPlayer.currentTime || 0));
}
if (message.type === 'progress') {
handleProgress(message.progress);
@@ -258,6 +275,7 @@ document.addEventListener('DOMContentLoaded', () => {
if (status === 'downloading') {
showDownloadPhase();
const percent = Math.min(Math.max(Math.round(progress.percent || 0), 0), 100);
updateTranscodeProgressChip(percent, 'Download');
const downloaded = formatBytes(progress.downloadedBytes || 0);
const total = formatBytes(progress.totalBytes || 0);
downloadSizeText.textContent = `${downloaded} / ${total}`;
@@ -265,6 +283,7 @@ document.addEventListener('DOMContentLoaded', () => {
downloadProgressFill.style.width = `${percent}%`;
} else if (status === 'downloaded') {
showDownloadPhase();
updateTranscodeProgressChip(100, 'Download');
const downloaded = formatBytes(progress.downloadedBytes || progress.totalBytes || 0);
const total = formatBytes(progress.totalBytes || 0);
downloadSizeText.textContent = `${downloaded} / ${total} — 下载完成`;
@@ -276,6 +295,7 @@ document.addEventListener('DOMContentLoaded', () => {
} else if (status === 'transcoding') {
showTranscodePhase();
const percent = Math.min(Math.max(Math.round(progress.percent || 0), 0), 100);
updateTranscodeProgressChip(percent, 'Transcode');
transcodeProgressText.textContent = `${percent}%`;
transcodeProgressFill.style.width = `${percent}%`;
transcodeDetailText.textContent = progress.details || 'FFmpeg 转码中...';
@@ -288,13 +308,16 @@ document.addEventListener('DOMContentLoaded', () => {
}
} else if (status === 'finished') {
showTranscodePhase();
updateTranscodeProgressChip(100, 'Transcode');
transcodeProgressText.textContent = '100%';
transcodeProgressFill.style.width = '100%';
transcodeDetailText.textContent = '转码完成';
} else if (status === 'failed') {
updateTranscodeProgressChip(progress.percent || 0, 'Failed');
transcodeDetailText.textContent = `失败: ${progress.details || '未知错误'}`;
transcodeProgressFill.style.background = 'linear-gradient(90deg, #dc2626, #b91c1c)';
} else if (status === 'cancelled') {
updateTranscodeProgressChip(0, 'Stopped');
transcodeDetailText.textContent = '已取消';
transcodeProgressFill.style.width = '0%';
}
@@ -327,6 +350,8 @@ document.addEventListener('DOMContentLoaded', () => {
if (statFps) statFps.textContent = '';
if (statBitrate) statBitrate.textContent = '';
if (statTime) statTime.textContent = '';
updateTranscodeProgressChip(0, 'Transcode');
updatePlaybackProgressChip(0);
if (stopTranscodeBtn) {
stopTranscodeBtn.classList.add('hidden');
@@ -352,6 +377,7 @@ document.addEventListener('DOMContentLoaded', () => {
seekBarProgress.style.width = `${ratio * 100}%`;
seekBarHandle.style.left = `${ratio * 100}%`;
seekCurrentTime.textContent = formatTime(absoluteTime);
updatePlaybackProgressChip(absoluteTime);
};
// Track playback position in the custom seek bar
@@ -1077,6 +1103,8 @@ document.addEventListener('DOMContentLoaded', () => {
updatePlayControls();
updateVolumeControls();
updateFullscreenControls();
updateTranscodeProgressChip(0, 'Transcode');
updatePlaybackProgressChip(0);
// Bind events
refreshBtn.addEventListener('click', () => fetchVideos(selectedBucket));