进度条改成白色
This commit is contained in:
parent
7ed2c7490f
commit
9e4c5119d3
@ -5,38 +5,120 @@ const { breakpoint } = useBootstrapBreakpoint();
|
|||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "HeaderVideo",
|
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() {
|
data() {
|
||||||
return {
|
return {
|
||||||
// timestamp: new Date().getTime()
|
currentFrame: 0,
|
||||||
|
timer: null,
|
||||||
|
isLoading: true, // 加载状态
|
||||||
|
loadingProgress: 0, // 加载进度
|
||||||
|
preloadedImages: [] // 预加载的图片缓存
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods:{
|
methods:{
|
||||||
handleVideoEnded:function (event){
|
handleVideoEnded:function (event){
|
||||||
window.location.href = "/Homepage";
|
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() {
|
mounted() {
|
||||||
if(this.$isMobile.phone)
|
if(this.$isMobile.phone)
|
||||||
{
|
{
|
||||||
// 重置 GIF 图片的 src 以确保从第一帧开始播放
|
this.preloadAllImages();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const videos = document.querySelectorAll('.startvideo');
|
const videos = document.querySelectorAll('.startvideo');
|
||||||
// 检查是否找到了视频元素 (可选,但好习惯)
|
|
||||||
if (videos.length > 0) {
|
if (videos.length > 0) {
|
||||||
videos.forEach(video => {
|
videos.forEach(video => {
|
||||||
video.addEventListener('ended', this.handleVideoEnded);
|
video.addEventListener('ended', this.handleVideoEnded);
|
||||||
@ -46,6 +128,14 @@ export default defineComponent({
|
|||||||
console.warn("没有找到视频元素。");
|
console.warn("没有找到视频元素。");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
beforeUnmount() {
|
||||||
|
this.stop()
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
autoplay(val) {
|
||||||
|
val ? this.start() : this.stop()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@ -53,8 +143,21 @@ export default defineComponent({
|
|||||||
<template>
|
<template>
|
||||||
<div id="beginroot" class="pageroot">
|
<div id="beginroot" class="pageroot">
|
||||||
<div id="videodiv">
|
<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"
|
<video v-else-if="$isMobile.tablet" poster="/logobeginPCpld.png"
|
||||||
id="tbstart" muted autoplay controls="controls"
|
id="tbstart" muted autoplay controls="controls"
|
||||||
playsinline webkit-playsinline
|
playsinline webkit-playsinline
|
||||||
@ -85,6 +188,33 @@ export default defineComponent({
|
|||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
@import "src/publicstyle.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{
|
#beginroot{
|
||||||
height: 100%;
|
height: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user