Commit 49492fb2 authored by liujiangnan's avatar liujiangnan

feat

parent 6488e794
......@@ -273,4 +273,79 @@ body::-webkit-scrollbar, html::-webkit-scrollbar {
.debug-info div {
margin-bottom: 5px;
font-family: monospace;
}
/* 预加载界面样式 */
.loading-screen {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
display: flex;
align-items: center;
justify-content: center;
z-index: 9999;
}
.loading-content {
text-align: center;
color: white;
max-width: 400px;
padding: 40px;
}
.loading-spinner {
width: 60px;
height: 60px;
border: 4px solid rgba(255, 255, 255, 0.3);
border-top: 4px solid white;
border-radius: 50%;
animation: spin 1s linear infinite;
margin: 0 auto 20px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.loading-text {
font-size: 24px;
font-weight: bold;
margin-bottom: 30px;
}
.loading-progress {
margin-top: 20px;
}
.progress-bar {
width: 100%;
height: 8px;
background: rgba(255, 255, 255, 0.3);
border-radius: 4px;
overflow: hidden;
margin-bottom: 10px;
}
.progress-fill {
height: 100%;
background: white;
border-radius: 4px;
transition: width 0.3s ease;
}
.progress-text {
font-size: 16px;
opacity: 0.8;
}
/* 主要内容样式 */
.main-content {
width: 100vw;
height: 100vh;
position: relative;
overflow: hidden;
}
\ No newline at end of file
......@@ -16,58 +16,75 @@
</head>
<body>
<div id="app">
<div class="page-container">
<transition :name="pageTransition">
<div class="full-image-wrapper" :key="currentPage">
<img ref="mainImg" :src="pages[currentPage].image_url" :alt="'Page ' + pages[currentPage].page" v-if="pages.length" class="full-image"/>
<template v-if="currentRects && isRectVisible">
<div v-for="(rect, idx) in currentRects" :key="idx" class="rect-layer rect-visible" :style="getRectStyle(rect)"></div>
</template>
<!-- 单词级别矩形高亮 -->
<template v-if="highlightedWordRects && isRectVisible">
<div
v-for="(wordRect, idx) in highlightedWordRects"
:key="'word-' + idx"
class="word-rect-layer"
:style="getWordRectStyle(wordRect)"
:title="wordRect.text"
></div>
</template>
<!-- 预加载界面 -->
<div class="loading-screen" v-if="isLoading">
<div class="loading-content">
<div class="loading-spinner"></div>
<div class="loading-text">正在加载资源...</div>
<div class="loading-progress">
<div class="progress-bar">
<div class="progress-fill" :style="{ width: loadingProgress + '%' }"></div>
</div>
<div class="progress-text">{{ loadedAssets }}/{{ totalAssets }} ({{ loadingProgress }}%)</div>
</div>
</transition>
</div>
<div class="subtitle-bar" v-if="currentAudioText">
<div class="subtitle-text">
<span
v-for="(word, index) in currentWords"
:key="index"
:class="{ 'highlighted-word': highlightedWordIndexes.includes(index) }"
>
{{ word.word }}
</span>
</div>
</div>
<!-- 调试面板 -->
<div class="debug-panel" v-if="isPlaying">
<div class="debug-info">
<div>时间: {{ debugInfo.currentTime.toFixed(2) }}s</div>
<div>单词数: {{ debugInfo.totalWords }}</div>
<div>高亮索引: {{ debugInfo.highlightedIndexes.join(', ') }}</div>
<div>当前单词: {{ debugInfo.currentWord }}</div>
<div>单词矩形数: {{ debugInfo.wordRectsCount }}</div>
<div>组单词数: {{ debugInfo.groupWordsCount }}</div>
<!-- 主要内容 -->
<div class="main-content" v-else>
<div class="page-container">
<transition :name="pageTransition">
<div class="full-image-wrapper" :key="currentPage">
<img ref="mainImg" :src="pages[currentPage].image_url" :alt="'Page ' + pages[currentPage].page" v-if="pages.length" class="full-image"/>
<template v-if="currentRects && isRectVisible">
<div v-for="(rect, idx) in currentRects" :key="idx" class="rect-layer rect-visible" :style="getRectStyle(rect)"></div>
</template>
<!-- 单词级别矩形高亮 -->
<template v-if="highlightedWordRects && isRectVisible">
<div
v-for="(wordRect, idx) in highlightedWordRects"
:key="'word-' + idx"
class="word-rect-layer"
:style="getWordRectStyle(wordRect)"
:title="wordRect.text"
></div>
</template>
</div>
</transition>
</div>
<div class="subtitle-bar" v-if="currentAudioText">
<div class="subtitle-text">
<span
v-for="(word, index) in currentWords"
:key="index"
:class="{ 'highlighted-word': highlightedWordIndexes.includes(index) }"
>
{{ word.word }}
</span>
</div>
</div>
<!-- 调试面板 -->
<div class="debug-panel" v-if="isPlaying">
<div class="debug-info">
<div>时间: {{ debugInfo.currentTime.toFixed(2) }}s</div>
<div>单词数: {{ debugInfo.totalWords }}</div>
<div>高亮索引: {{ debugInfo.highlightedIndexes.join(', ') }}</div>
<div>当前单词: {{ debugInfo.currentWord }}</div>
<div>单词矩形数: {{ debugInfo.wordRectsCount }}</div>
<div>组单词数: {{ debugInfo.groupWordsCount }}</div>
</div>
</div>
<div class="fixed-btn-group">
<el-button
type="primary"
:icon="isPlaying ? 'el-icon-video-pause' : 'el-icon-video-play'"
@click="togglePlay">
{{ isPlaying ? '暂停' : '播放' }}
</el-button>
<el-button icon="el-icon-arrow-left" @click="prevPage">上一页</el-button>
<el-button icon="el-icon-arrow-right" @click="nextPage">下一页</el-button>
</div>
</div>
<div class="fixed-btn-group">
<el-button
type="primary"
:icon="isPlaying ? 'el-icon-video-pause' : 'el-icon-video-play'"
@click="togglePlay">
{{ isPlaying ? '暂停' : '播放' }}
</el-button>
<el-button icon="el-icon-arrow-left" @click="prevPage">上一页</el-button>
<el-button icon="el-icon-arrow-right" @click="nextPage">下一页</el-button>
</div>
</div>
</body>
......
......@@ -44,6 +44,11 @@ function initializeApp(data) {
// 单词级别矩形高亮相关
currentGroupWords: [], // 当前活跃组的单词矩形信息
highlightedWordRects: [], // 当前高亮的单词矩形
// 预加载相关
isLoading: true,
loadingProgress: 0,
totalAssets: 0,
loadedAssets: 0,
},
computed: {
currentGroups() {
......@@ -137,6 +142,8 @@ function initializeApp(data) {
};
}
});
// 开始预加载
this.startPreloading();
},
beforeDestroy() {
if (this.audio) {
......@@ -400,25 +407,110 @@ function initializeApp(data) {
pointerEvents: 'none',
zIndex: 3
};
},
startPreloading() {
const assetsToLoad = [];
// 添加所有图片
if (Array.isArray(this.pages)) {
this.pages.forEach(page => {
if (page.image_url) {
assetsToLoad.push({
type: 'image',
url: page.image_url,
name: `Page ${page.page || 'unknown'}`
});
}
});
}
// 添加音频
if (this.audioUrl) {
assetsToLoad.push({
type: 'audio',
url: this.audioUrl,
name: 'Audio'
});
}
this.totalAssets = assetsToLoad.length;
this.loadedAssets = 0;
if (this.totalAssets === 0) {
// 没有需要预加载的资源,直接完成
this.finishPreloading();
return;
}
// 开始加载每个资源
assetsToLoad.forEach(asset => {
if (asset.type === 'image') {
this.loadImage(asset);
} else if (asset.type === 'audio') {
this.loadAudio(asset);
}
});
},
loadImage(asset) {
const img = new Image();
img.onload = () => {
this.assetLoaded(asset);
};
img.onerror = () => {
console.warn(`Failed to load image: ${asset.url}`);
this.assetLoaded(asset);
};
img.src = asset.url;
},
loadAudio(asset) {
const audio = new Audio();
audio.oncanplaythrough = () => {
this.assetLoaded(asset);
};
audio.onerror = () => {
console.warn(`Failed to load audio: ${asset.url}`);
this.assetLoaded(asset);
};
audio.src = asset.url;
},
assetLoaded(asset) {
this.loadedAssets++;
this.loadingProgress = Math.round((this.loadedAssets / this.totalAssets) * 100);
console.log(`Loaded ${asset.type}: ${asset.name} (${this.loadedAssets}/${this.totalAssets})`);
if (this.loadedAssets >= this.totalAssets) {
this.finishPreloading();
}
},
finishPreloading() {
console.log('All assets preloaded successfully!');
this.isLoading = false;
// 初始化音频播放器
this.audio = new Audio(this.audioUrl);
this.audio.addEventListener('timeupdate', this.handleTimeUpdate);
this.audio.addEventListener('ended', this.handleAudioEnded);
this.updateImageSize();
window.addEventListener('resize', this.updateImageSize);
// 监听图片加载完成,确保能拿到尺寸
this.$nextTick(() => {
const img = this.$refs.mainImg;
if (img) {
img.onload = () => {
this.updateImageSize();
};
}
});
}
}
});
// 预加载所有图片和音频
if (Array.isArray(data.pages)) {
data.pages.forEach(page => {
if (page.image_url) {
const img = new window.Image();
img.src = page.image_url;
}
});
}
if (data.audio_points && data.audio_points.audio_url) {
const audio = new window.Audio();
audio.src = data.audio_points.audio_url;
// 可选:audio.preload = 'auto';
}
// Hide loading screen
window.air.hideAirClassLoading(t_name, data);
}
\ No newline at end of file
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