进度条改成白色

This commit is contained in:
zhcnyuyang 2025-05-22 16:46:02 +08:00
parent 7ed2c7490f
commit 9e4c5119d3

View File

@ -5,38 +5,120 @@ const { breakpoint } = useBootstrapBreakpoint();
export default defineComponent({
name: "HeaderVideo",
props: {
//
alt: { type: String, default: '' },
// / 20
fps: { type: Number, default: 20 },
// true
autoplay: { type: Boolean, default: true },
//
loop: { type: Boolean, default: false },
// 115
framesCount: { type: Number, default: 115 },
//
basePath: { type: String, default: '/openvideo/' }
},
data() {
return {
// timestamp: new Date().getTime()
currentFrame: 0,
timer: null,
isLoading: true, //
loadingProgress: 0, //
preloadedImages: [] //
}
},
methods:{
handleVideoEnded:function (event){
window.location.href = "/Homepage";
},
preloadAllImages() {
this.isLoading = true;
this.loadingProgress = 0;
let loadedCount = 0;
const totalFrames = this.frames.length;
// Promise
const preloadPromises = this.frames.map((src, index) => {
return new Promise((resolve, reject) => {
const img = new Image();
img.onload = () => {
this.preloadedImages[index] = img;
loadedCount++;
this.loadingProgress = Math.floor(loadedCount / totalFrames * 100);
resolve(img);
};
img.onerror = (e) => {
console.error(`无法加载图片: ${src}`, e);
loadedCount++;
this.loadingProgress = Math.floor(loadedCount / totalFrames * 100);
reject(e);
};
img.src = src;
});
});
//
Promise.all(preloadPromises)
.then(() => {
console.log("所有帧预加载完成");
this.isLoading = false;
this.start();
})
.catch(() => {
console.log("部分帧加载失败,但仍继续播放");
this.isLoading = false;
this.start();
});
},
start() {
if (this.timer) return;
const interval = 1000 / this.fps;
this.timer = setInterval(() => {
const next = this.currentFrame + 1;
if (next < this.frames.length) {
this.currentFrame = next;
} else {
this.stop();
setTimeout(() => {
window.location.href = "/Homepage";
}, 100);
}
}, interval);
},
stop() {
if (this.timer) {
clearInterval(this.timer)
this.timer = null
}
}
},
computed: {
frames() {
const arr = []
for (let i = 0; i <= this.framesCount; i++) {
//
const name = String(i).padStart(5, '0') + '.jpg'
arr.push(this.basePath + name)
}
return arr
}
},
mounted() {
if(this.$isMobile.phone)
{
// GIF src
const img = document.getElementById('beginwep');
if (img) {
const src = img.getAttribute('src');
img.setAttribute('src', '');
setTimeout(() => {
img.setAttribute('src', src);
}, 10);
}
setTimeout(function() {
//
window.location.href = "/Homepage";
}, 5100);
this.preloadAllImages();
}
else
{
const videos = document.querySelectorAll('.startvideo');
// ()
if (videos.length > 0) {
videos.forEach(video => {
video.addEventListener('ended', this.handleVideoEnded);
@ -46,6 +128,14 @@ export default defineComponent({
console.warn("没有找到视频元素。");
}
}
},
beforeUnmount() {
this.stop()
},
watch: {
autoplay(val) {
val ? this.start() : this.stop()
}
}
})
</script>
@ -53,8 +143,21 @@ export default defineComponent({
<template>
<div id="beginroot" class="pageroot">
<div id="videodiv">
<img v-if="$isMobile.phone"
src="/beginwepgif.gif" id="beginwep"/>
<!-- 加载进度条 -->
<div v-if="$isMobile.phone && isLoading" class="loading-container">
<div class="progress-container">
<div class="progress-bar" :style="{width: loadingProgress + '%'}"></div>
</div>
<div class="loading-text">加载中 {{ loadingProgress }}%</div>
</div>
<img
:src="frames[currentFrame]"
id="beginwep"
:alt="alt"
class="simple-frame-player"
v-if="$isMobile.phone && !isLoading"
/>
<video v-else-if="$isMobile.tablet" poster="/logobeginPCpld.png"
id="tbstart" muted autoplay controls="controls"
playsinline webkit-playsinline
@ -85,6 +188,33 @@ export default defineComponent({
<style scoped lang="scss">
@import "src/publicstyle.scss";
.loading-container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
width: 80%;
z-index: 10;
}
.progress-container {
background-color: rgba(255, 255, 255, 0.2);
height: 8px;
border-radius: 4px;
overflow: hidden;
margin-bottom: 10px;
}
.progress-bar {
height: 100%;
background-color: white;
transition: width 0.3s ease;
}
.loading-text {
color: white;
font-size: 14px;
}
#beginroot{
height: 100%;
display: flex;