fix [P-224]: доработана карусель и видео
This commit is contained in:
1 parent
b221a08300
commit
7a4aa968c2
2 files changed
+859
-189
No files matched your search
@@ -0,0 +1,515 @@
|
||||
<template>
|
||||
<div
|
||||
ref="root"
|
||||
class="vp"
|
||||
:class="{ 'vp--hide-cursor': playing && !controlsVisible }"
|
||||
tabindex="0"
|
||||
@mousemove="revealControls"
|
||||
@keydown="onKeydown"
|
||||
>
|
||||
<video
|
||||
ref="video"
|
||||
class="vp__video"
|
||||
:muted="muted"
|
||||
playsinline
|
||||
preload="auto"
|
||||
@click="togglePlay"
|
||||
@dblclick="toggleFullscreen"
|
||||
@loadedmetadata="onLoadedMetadata"
|
||||
@timeupdate="onTimeUpdate"
|
||||
@progress="onProgress"
|
||||
@play="playing = true"
|
||||
@pause="playing = false"
|
||||
@volumechange="onVolumeChange"
|
||||
@ended="onEnded"
|
||||
@waiting="buffering = true"
|
||||
@playing="buffering = false"
|
||||
@canplay="onCanPlay"
|
||||
>
|
||||
<source :src="src" type="video/mp4" />
|
||||
Ваш браузер не поддерживает воспроизведение видео.
|
||||
</video>
|
||||
|
||||
<!-- Индикатор буферизации -->
|
||||
<div v-if="buffering" class="vp__spinner">
|
||||
<v-progress-circular indeterminate color="white" size="48" width="3" />
|
||||
</div>
|
||||
|
||||
<!-- Большая кнопка play по центру -->
|
||||
<transition name="vp-fade">
|
||||
<button
|
||||
v-if="!playing && !buffering"
|
||||
type="button"
|
||||
class="vp__center-btn"
|
||||
aria-label="Воспроизвести"
|
||||
@click="togglePlay"
|
||||
>
|
||||
<v-icon icon="mdi-play" size="44" />
|
||||
</button>
|
||||
</transition>
|
||||
|
||||
<!-- Кнопка «включить звук» при немом автозапуске -->
|
||||
<transition name="vp-fade">
|
||||
<button
|
||||
v-if="playing && muted"
|
||||
type="button"
|
||||
class="vp__unmute"
|
||||
@click="unmute"
|
||||
>
|
||||
<v-icon icon="mdi-volume-off" size="18" start />
|
||||
Включить звук
|
||||
</button>
|
||||
</transition>
|
||||
|
||||
<!-- Нижняя панель управления -->
|
||||
<transition name="vp-slide">
|
||||
<div v-show="controlsVisible" class="vp__controls" @click.stop>
|
||||
<!-- Прогресс-бар -->
|
||||
<div
|
||||
ref="track"
|
||||
class="vp__track"
|
||||
role="slider"
|
||||
aria-label="Перемотка"
|
||||
:aria-valuenow="Math.round(progress)"
|
||||
@pointerdown="startSeek"
|
||||
>
|
||||
<div class="vp__track-buffer" :style="{ width: buffered + '%' }" />
|
||||
<div class="vp__track-fill" :style="{ width: progress + '%' }">
|
||||
<span class="vp__track-handle" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Кнопки -->
|
||||
<div class="vp__bar">
|
||||
<button type="button" class="vp__btn" :aria-label="playing ? 'Пауза' : 'Воспроизвести'" @click="togglePlay">
|
||||
<v-icon :icon="playing ? 'mdi-pause' : 'mdi-play'" size="24" />
|
||||
</button>
|
||||
|
||||
<span class="vp__time">{{ formatTime(currentTime) }} / {{ formatTime(duration) }}</span>
|
||||
|
||||
<div class="vp__spacer" />
|
||||
|
||||
<div class="vp__volume">
|
||||
<button type="button" class="vp__btn" :aria-label="isSilent ? 'Включить звук' : 'Выключить звук'" @click="toggleMute">
|
||||
<v-icon :icon="volumeIcon" size="24" />
|
||||
</button>
|
||||
<input
|
||||
class="vp__volume-slider"
|
||||
type="range"
|
||||
min="0"
|
||||
max="1"
|
||||
step="0.05"
|
||||
:value="isSilent ? 0 : volume"
|
||||
aria-label="Громкость"
|
||||
@input="setVolume"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button type="button" class="vp__btn" :aria-label="isFullscreen ? 'Выйти из полноэкранного режима' : 'Полный экран'" @click="toggleFullscreen">
|
||||
<v-icon :icon="isFullscreen ? 'mdi-fullscreen-exit' : 'mdi-fullscreen'" size="24" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted, onBeforeUnmount } from 'vue';
|
||||
|
||||
const props = defineProps({
|
||||
src: { type: String, required: true },
|
||||
autoplay: { type: Boolean, default: true },
|
||||
});
|
||||
|
||||
const emit = defineEmits(['ended']);
|
||||
|
||||
const root = ref(null);
|
||||
const video = ref(null);
|
||||
const track = ref(null);
|
||||
|
||||
const playing = ref(false);
|
||||
const buffering = ref(false);
|
||||
const muted = ref(props.autoplay);
|
||||
const volume = ref(1);
|
||||
const currentTime = ref(0);
|
||||
const duration = ref(0);
|
||||
const buffered = ref(0);
|
||||
const isFullscreen = ref(false);
|
||||
const controlsVisible = ref(true);
|
||||
|
||||
let hideTimer = null;
|
||||
let dragging = false;
|
||||
|
||||
const progress = computed(() => (duration.value ? (currentTime.value / duration.value) * 100 : 0));
|
||||
|
||||
const isSilent = computed(() => muted.value || volume.value === 0);
|
||||
|
||||
const volumeIcon = computed(() => {
|
||||
if (isSilent.value) return 'mdi-volume-off';
|
||||
if (volume.value < 0.5) return 'mdi-volume-medium';
|
||||
return 'mdi-volume-high';
|
||||
});
|
||||
|
||||
const formatTime = (sec) => {
|
||||
if (!Number.isFinite(sec)) return '0:00';
|
||||
const m = Math.floor(sec / 60);
|
||||
const s = Math.floor(sec % 60);
|
||||
return `${m}:${s.toString().padStart(2, '0')}`;
|
||||
};
|
||||
|
||||
const togglePlay = () => {
|
||||
const el = video.value;
|
||||
if (!el) return;
|
||||
if (el.paused) el.play().catch(() => {});
|
||||
else el.pause();
|
||||
};
|
||||
|
||||
const onCanPlay = () => {
|
||||
if (props.autoplay && video.value?.paused) {
|
||||
video.value.muted = true;
|
||||
muted.value = true;
|
||||
video.value.play().catch(() => {});
|
||||
}
|
||||
};
|
||||
|
||||
const unmute = () => {
|
||||
if (!video.value) return;
|
||||
video.value.muted = false;
|
||||
muted.value = false;
|
||||
if (volume.value === 0) {
|
||||
volume.value = 1;
|
||||
video.value.volume = 1;
|
||||
}
|
||||
};
|
||||
|
||||
const toggleMute = () => {
|
||||
if (!video.value) return;
|
||||
video.value.muted = !video.value.muted;
|
||||
muted.value = video.value.muted;
|
||||
};
|
||||
|
||||
const setVolume = (e) => {
|
||||
const v = Number(e.target.value);
|
||||
volume.value = v;
|
||||
if (video.value) {
|
||||
video.value.volume = v;
|
||||
video.value.muted = v === 0;
|
||||
muted.value = v === 0;
|
||||
}
|
||||
};
|
||||
|
||||
const onVolumeChange = () => {
|
||||
if (!video.value) return;
|
||||
muted.value = video.value.muted;
|
||||
volume.value = video.value.volume;
|
||||
};
|
||||
|
||||
const onLoadedMetadata = () => {
|
||||
duration.value = video.value?.duration || 0;
|
||||
};
|
||||
|
||||
const onTimeUpdate = () => {
|
||||
if (!dragging) currentTime.value = video.value?.currentTime || 0;
|
||||
};
|
||||
|
||||
const onProgress = () => {
|
||||
const el = video.value;
|
||||
if (el && el.buffered.length && el.duration) {
|
||||
buffered.value = (el.buffered.end(el.buffered.length - 1) / el.duration) * 100;
|
||||
}
|
||||
};
|
||||
|
||||
const onEnded = () => {
|
||||
playing.value = false;
|
||||
emit('ended');
|
||||
};
|
||||
|
||||
const seekToEvent = (e) => {
|
||||
const el = track.value;
|
||||
const vid = video.value;
|
||||
if (!el || !vid || !vid.duration) return;
|
||||
const rect = el.getBoundingClientRect();
|
||||
const ratio = Math.min(Math.max((e.clientX - rect.left) / rect.width, 0), 1);
|
||||
currentTime.value = ratio * vid.duration;
|
||||
vid.currentTime = currentTime.value;
|
||||
};
|
||||
|
||||
const startSeek = (e) => {
|
||||
dragging = true;
|
||||
seekToEvent(e);
|
||||
window.addEventListener('pointermove', seekToEvent);
|
||||
window.addEventListener('pointerup', endSeek);
|
||||
};
|
||||
|
||||
const endSeek = () => {
|
||||
dragging = false;
|
||||
window.removeEventListener('pointermove', seekToEvent);
|
||||
window.removeEventListener('pointerup', endSeek);
|
||||
};
|
||||
|
||||
const revealControls = () => {
|
||||
controlsVisible.value = true;
|
||||
clearTimeout(hideTimer);
|
||||
hideTimer = setTimeout(() => {
|
||||
if (playing.value) controlsVisible.value = false;
|
||||
}, 2500);
|
||||
};
|
||||
|
||||
const toggleFullscreen = () => {
|
||||
if (!root.value) return;
|
||||
if (document.fullscreenElement) document.exitFullscreen();
|
||||
else root.value.requestFullscreen?.().catch(() => {});
|
||||
};
|
||||
|
||||
const onFullscreenChange = () => {
|
||||
isFullscreen.value = document.fullscreenElement === root.value;
|
||||
};
|
||||
|
||||
const onKeydown = (e) => {
|
||||
const vid = video.value;
|
||||
if (!vid) return;
|
||||
switch (e.key) {
|
||||
case ' ':
|
||||
case 'k':
|
||||
e.preventDefault();
|
||||
togglePlay();
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
vid.currentTime = Math.min(vid.currentTime + 5, vid.duration);
|
||||
break;
|
||||
case 'ArrowLeft':
|
||||
vid.currentTime = Math.max(vid.currentTime - 5, 0);
|
||||
break;
|
||||
case 'm':
|
||||
toggleMute();
|
||||
break;
|
||||
case 'f':
|
||||
toggleFullscreen();
|
||||
break;
|
||||
}
|
||||
revealControls();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('fullscreenchange', onFullscreenChange);
|
||||
revealControls();
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('fullscreenchange', onFullscreenChange);
|
||||
document.removeEventListener('pointermove', seekToEvent);
|
||||
document.removeEventListener('pointerup', endSeek);
|
||||
clearTimeout(hideTimer);
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.vp {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #000;
|
||||
outline: none;
|
||||
overflow: hidden;
|
||||
}
|
||||
.vp--hide-cursor {
|
||||
cursor: none;
|
||||
}
|
||||
|
||||
.vp__video {
|
||||
max-height: 100%;
|
||||
max-width: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.vp__spinner {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Центральная кнопка play */
|
||||
.vp__center-btn {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 84px;
|
||||
height: 84px;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
color: #fff;
|
||||
background: rgba(20, 20, 20, 0.55);
|
||||
backdrop-filter: blur(4px);
|
||||
cursor: pointer;
|
||||
transition: transform 0.18s ease, background 0.18s ease;
|
||||
}
|
||||
.vp__center-btn:hover {
|
||||
transform: translate(-50%, -50%) scale(1.08);
|
||||
background: rgba(20, 20, 20, 0.75);
|
||||
}
|
||||
|
||||
/* Кнопка включения звука */
|
||||
.vp__unmute {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
right: 16px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 6px 14px 6px 10px;
|
||||
border: none;
|
||||
border-radius: 999px;
|
||||
color: #fff;
|
||||
font-size: 0.85rem;
|
||||
background: rgba(20, 20, 20, 0.6);
|
||||
backdrop-filter: blur(4px);
|
||||
cursor: pointer;
|
||||
transition: background 0.18s ease;
|
||||
}
|
||||
.vp__unmute:hover {
|
||||
background: rgba(20, 20, 20, 0.85);
|
||||
}
|
||||
|
||||
/* Панель управления */
|
||||
.vp__controls {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
padding: 28px 16px 12px;
|
||||
background: linear-gradient(to top, rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0));
|
||||
}
|
||||
|
||||
.vp__track {
|
||||
position: relative;
|
||||
height: 6px;
|
||||
border-radius: 3px;
|
||||
background: rgba(255, 255, 255, 0.25);
|
||||
cursor: pointer;
|
||||
margin-bottom: 10px;
|
||||
touch-action: none;
|
||||
}
|
||||
.vp__track:hover {
|
||||
height: 8px;
|
||||
}
|
||||
.vp__track-buffer {
|
||||
position: absolute;
|
||||
inset: 0 auto 0 0;
|
||||
height: 100%;
|
||||
border-radius: 3px;
|
||||
background: rgba(255, 255, 255, 0.35);
|
||||
}
|
||||
.vp__track-fill {
|
||||
position: absolute;
|
||||
inset: 0 auto 0 0;
|
||||
height: 100%;
|
||||
border-radius: 3px;
|
||||
background: #26a69a;
|
||||
}
|
||||
.vp__track-handle {
|
||||
position: absolute;
|
||||
right: -6px;
|
||||
top: 50%;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 50%;
|
||||
background: #fff;
|
||||
transform: translateY(-50%) scale(0);
|
||||
transition: transform 0.15s ease;
|
||||
}
|
||||
.vp__track:hover .vp__track-handle {
|
||||
transform: translateY(-50%) scale(1);
|
||||
}
|
||||
|
||||
.vp__bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
color: #fff;
|
||||
}
|
||||
.vp__btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
color: #fff;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s ease;
|
||||
}
|
||||
.vp__btn:hover {
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
}
|
||||
.vp__time {
|
||||
font-size: 0.85rem;
|
||||
font-variant-numeric: tabular-nums;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.vp__spacer {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
|
||||
/* Громкость */
|
||||
.vp__volume {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.vp__volume-slider {
|
||||
width: 0;
|
||||
opacity: 0;
|
||||
margin-left: 0;
|
||||
transition: width 0.2s ease, opacity 0.2s ease, margin-left 0.2s ease;
|
||||
accent-color: #26a69a;
|
||||
cursor: pointer;
|
||||
}
|
||||
.vp__volume:hover .vp__volume-slider,
|
||||
.vp__volume-slider:focus {
|
||||
width: 80px;
|
||||
opacity: 1;
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
/* Анимации */
|
||||
.vp-fade-enter-active,
|
||||
.vp-fade-leave-active {
|
||||
transition: opacity 0.2s ease;
|
||||
}
|
||||
.vp-fade-enter-from,
|
||||
.vp-fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
.vp-slide-enter-active,
|
||||
.vp-slide-leave-active {
|
||||
transition: opacity 0.2s ease, transform 0.2s ease;
|
||||
}
|
||||
.vp-slide-enter-from,
|
||||
.vp-slide-leave-to {
|
||||
opacity: 0;
|
||||
transform: translateY(8px);
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.vp__center-btn,
|
||||
.vp__track-handle,
|
||||
.vp__volume-slider,
|
||||
.vp-fade-enter-active,
|
||||
.vp-fade-leave-active,
|
||||
.vp-slide-enter-active,
|
||||
.vp-slide-leave-active {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,219 +1,374 @@
|
||||
<template>
|
||||
<!-- Карусель: Компонент для отображения изображений и видео с сервера в виде карусели -->
|
||||
<v-carousel
|
||||
v-model="currentslide"
|
||||
:interval="interval"
|
||||
cover
|
||||
cycle
|
||||
height="450"
|
||||
hide-delimiters
|
||||
hide-delimiter-background
|
||||
:show-arrows="carous.length < 2 ? false : 'hover'"
|
||||
color="teal-darken-4"
|
||||
@update:modelValue="slidechanged"
|
||||
<!-- Карусель -->
|
||||
<div
|
||||
class="news-carousel"
|
||||
role="region"
|
||||
aria-label="Карусель новостей"
|
||||
@mouseenter="paused = true"
|
||||
@mouseleave="paused = false"
|
||||
>
|
||||
<template v-for="(x, i) in carous" :key="i">
|
||||
<v-carousel-item v-if="!x.link.endsWith('mp4')" :src="`${burl}${x.link}`" cover eager>
|
||||
<v-container fill-height fluid pa-0 ma-0 pb-3 class="flex-column h-100 d-flex">
|
||||
<v-card
|
||||
v-if="x.text !== '' || x.title != null"
|
||||
class="bgCard h-100 d-flex flex-column"
|
||||
style="background: rgba(255, 255, 255, 0.3) !important; background-color: rgba(255, 255, 255, 0.3) !important;"
|
||||
<!-- Скелетон во время загрузки -->
|
||||
<v-skeleton-loader
|
||||
v-if="loading"
|
||||
type="image"
|
||||
height="450"
|
||||
class="rounded-lg"
|
||||
/>
|
||||
|
||||
<!-- Пустое состояние -->
|
||||
<v-sheet
|
||||
v-else-if="slides.length === 0"
|
||||
height="450"
|
||||
class="rounded-lg d-flex flex-column align-center justify-center text-medium-emphasis"
|
||||
color="grey-lighten-4"
|
||||
>
|
||||
<v-icon icon="mdi-image-off-outline" size="48" class="mb-2" />
|
||||
<span>Нет материалов для показа</span>
|
||||
</v-sheet>
|
||||
|
||||
<!-- Карусель -->
|
||||
<v-carousel
|
||||
v-else
|
||||
v-model="current"
|
||||
:interval="INTERVAL_MS"
|
||||
:cycle="autoplayEnabled"
|
||||
:show-arrows="slides.length > 1 ? 'hover' : false"
|
||||
:hide-delimiters="true"
|
||||
height="450"
|
||||
hide-delimiter-background
|
||||
class="rounded-lg overflow-hidden"
|
||||
@update:model-value="onSlideChange"
|
||||
>
|
||||
<v-carousel-item
|
||||
v-for="(slide, i) in slides"
|
||||
:key="i"
|
||||
eager
|
||||
>
|
||||
<!-- Изображение -->
|
||||
<template v-if="!isVideo(slide)">
|
||||
<v-img
|
||||
:src="absUrl(slide.link)"
|
||||
:alt="slide.title || 'Слайд новости'"
|
||||
cover
|
||||
height="450"
|
||||
class="news-carousel__media"
|
||||
>
|
||||
<v-card-title
|
||||
v-if="x.title != null"
|
||||
class="text-h3 text-uppercase titles text-text_carous ma-1 mb-0"
|
||||
<template #placeholder>
|
||||
<div class="d-flex align-center justify-center fill-height">
|
||||
<v-progress-circular indeterminate color="grey-lighten-2" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Контент поверх изображения -->
|
||||
<div
|
||||
v-if="slide.title || slide.text"
|
||||
class="news-carousel__overlay"
|
||||
>
|
||||
<v-row no-gutters>
|
||||
<v-col class="align-self-center">
|
||||
{{ x.title }}
|
||||
</v-col>
|
||||
<v-col class="flex-grow-0">
|
||||
<v-img width="50" :aspect-ratio="1" :src="`${burl}${x.sender}`" cover />
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-card-title>
|
||||
<v-card-text
|
||||
v-if="x.text !== ''"
|
||||
class="w-50 flex-grow-0 text-h6 bgText overflow-auto ma-1 pa-0"
|
||||
>
|
||||
<v-textarea
|
||||
class="text-text_caroustext-black textareas font-weight-medium nocursor"
|
||||
:model-value="x.text"
|
||||
variant="solo"
|
||||
readonly
|
||||
auto-grow
|
||||
rows="1"
|
||||
hide-details
|
||||
flat
|
||||
bg-color="transparent"
|
||||
/>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</v-container>
|
||||
<div class="news-carousel__content">
|
||||
<div v-if="slide.title" class="news-carousel__header">
|
||||
<h3 class="news-carousel__title">{{ slide.title }}</h3>
|
||||
<v-avatar
|
||||
v-if="slide.sender"
|
||||
size="48"
|
||||
rounded="lg"
|
||||
class="news-carousel__sender"
|
||||
>
|
||||
<v-img :src="absUrl(slide.sender)" :aspect-ratio="1" cover />
|
||||
</v-avatar>
|
||||
</div>
|
||||
|
||||
<p v-if="slide.text" class="news-carousel__text">
|
||||
{{ slide.text }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</v-img>
|
||||
</template>
|
||||
|
||||
<!-- Видео -->
|
||||
<template v-else>
|
||||
<div class="news-carousel__video-wrap">
|
||||
<VideoPlayer
|
||||
v-if="i === current"
|
||||
:key="`video-${i}-${videoKey}`"
|
||||
:src="absUrl(slide.link)"
|
||||
autoplay
|
||||
@ended="onVideoEnded"
|
||||
/>
|
||||
<!-- Заглушка для неактивного видео-слайда -->
|
||||
<div v-else class="news-carousel__video-poster">
|
||||
<v-icon icon="mdi-play-circle-outline" size="64" color="white" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</v-carousel-item>
|
||||
<v-carousel-item v-else>
|
||||
<div class="d-flex justify-center">
|
||||
<video
|
||||
ref="videoElement"
|
||||
style="height: 450px"
|
||||
controls
|
||||
preload="metadata"
|
||||
@ended="ended"
|
||||
@loadedmetadata="interval = 10000000000"
|
||||
>
|
||||
<source :src="`${burl}${x.link}`" type="video/mp4" />
|
||||
Текущий браузер не поддерживает воспроизведение этого видео.
|
||||
</video>
|
||||
</div>
|
||||
</v-carousel-item>
|
||||
</template>
|
||||
</v-carousel>
|
||||
|
||||
<!-- Кастомные индикаторы + прогресс автопрокрутки -->
|
||||
<div
|
||||
v-if="slides.length > 1"
|
||||
class="news-carousel__dots"
|
||||
role="tablist"
|
||||
>
|
||||
<button
|
||||
v-for="(slide, i) in slides"
|
||||
:key="i"
|
||||
type="button"
|
||||
role="tab"
|
||||
:aria-selected="i === current"
|
||||
:aria-label="`Слайд ${i + 1}`"
|
||||
class="news-carousel__dot"
|
||||
:class="{ 'news-carousel__dot--active': i === current }"
|
||||
@click="goTo(i)"
|
||||
>
|
||||
<span
|
||||
v-if="i === current && autoplayEnabled"
|
||||
:key="`progress-${current}`"
|
||||
class="news-carousel__progress"
|
||||
:style="{ animationDuration: `${INTERVAL_MS}ms`, animationPlayState: paused ? 'paused' : 'running' }"
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
</v-carousel>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { ref } from 'vue';
|
||||
import { baseURL } from '@/utils/axios-api';
|
||||
import { axiosApiInstance } from '@/utils/axios-api';
|
||||
<script setup>
|
||||
import { ref, computed, onMounted } from 'vue';
|
||||
import { baseURL, axiosApiInstance } from '@/utils/axios-api';
|
||||
import { useAlertStore } from '@/store/UseAlertStore';
|
||||
import VideoPlayer from './VideoPlayer.vue';
|
||||
|
||||
export default {
|
||||
setup() {
|
||||
/**
|
||||
* Хранит индекс текущего слайда карусели.
|
||||
*/
|
||||
const currentslide = ref(0);
|
||||
/** Интервал автопрокрутки изображений, мс. */
|
||||
const INTERVAL_MS = 8000;
|
||||
|
||||
/**
|
||||
* Базовый URL для загрузки медиа.
|
||||
*/
|
||||
const burl = baseURL.slice(0, -1);
|
||||
/** Базовый URL без завершающего слэша. */
|
||||
const burl = baseURL.slice(0, -1);
|
||||
|
||||
/**
|
||||
* Ссылка на элемент видео.
|
||||
*/
|
||||
const videoElement = ref(null);
|
||||
const feedAlert = useAlertStore().alert;
|
||||
|
||||
/**
|
||||
* Хранит массив данных карусели, по умолчанию содержит одно изображение.
|
||||
*/
|
||||
const carous = ref([{ link: `/media/newsimage/scales.jpg`, title: null, text: '' }]);
|
||||
/** Список слайдов. Стартовая заглушка до ответа сервера. */
|
||||
const slides = ref([]);
|
||||
/** Индекс текущего слайда. */
|
||||
const current = ref(0);
|
||||
/** Флаг загрузки данных. */
|
||||
const loading = ref(true);
|
||||
/** Пауза автопрокрутки (например, при наведении). */
|
||||
const paused = ref(false);
|
||||
|
||||
/**
|
||||
* Получает объект alert из хранилища alert для уведомлений.
|
||||
*/
|
||||
const feedalert = useAlertStore().alert;
|
||||
/** Счётчик для принудительного пересоздания video-элемента при возврате на слайд. */
|
||||
const videoKey = ref(0);
|
||||
|
||||
/**
|
||||
* Интервал переключения слайдов в миллисекундах.
|
||||
*/
|
||||
const interval = ref(10000);
|
||||
/** Является ли слайд видео. */
|
||||
const isVideo = (slide) => slide?.link?.toLowerCase().endsWith('.mp4');
|
||||
|
||||
/**
|
||||
* @arrowFunc
|
||||
* Обрабатывает запрос для получения данных карусели с сервера.
|
||||
*/
|
||||
const getfromserver = () => {
|
||||
axiosApiInstance.get('api/navigation/carousels/').then((result) => {
|
||||
if (result.data.mess !== '') {
|
||||
feedalert.alert = true;
|
||||
feedalert.text = result.data.mess;
|
||||
feedalert.color = 'red-darken-2';
|
||||
feedalert.ico = 'mdi-alert-outline';
|
||||
}
|
||||
/** Текущий слайд — видео? */
|
||||
const currentIsVideo = computed(() => isVideo(slides.value[current.value]));
|
||||
|
||||
if (result.data.result.length > 0) {
|
||||
carous.value = result.data.result;
|
||||
}
|
||||
});
|
||||
};
|
||||
/** Автопрокрутка активна только для изображений и при наличии >1 слайда. */
|
||||
const autoplayEnabled = computed(
|
||||
() => slides.value.length > 1 && !currentIsVideo.value && !paused.value,
|
||||
);
|
||||
|
||||
getfromserver();
|
||||
/** Абсолютный URL для медиа. */
|
||||
const absUrl = (path) => `${burl}${path}`;
|
||||
|
||||
/**
|
||||
* @arrowFunc
|
||||
* Управляет изменением слайда и переключением интервала в зависимости от типа медиа.
|
||||
*/
|
||||
const slidechanged = () => {
|
||||
if (carous.value[currentslide.value].link.endsWith('mp4')) {
|
||||
// При переключении на видео, останавливаем все другие видео
|
||||
videoElement.value.forEach((e) => {
|
||||
if (e.currentSrc !== burl + carous.value[currentslide.value].link) {
|
||||
e.pause();
|
||||
}
|
||||
});
|
||||
}
|
||||
/** Загрузка слайдов с сервера. */
|
||||
const fetchSlides = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const { data } = await axiosApiInstance.get('api/navigation/carousels/');
|
||||
|
||||
if (carous.value[currentslide.value].link.endsWith('mp4')) {
|
||||
interval.value = 10000000000;
|
||||
} else {
|
||||
interval.value = 10000;
|
||||
}
|
||||
};
|
||||
if (data.mess) {
|
||||
feedAlert.alert = true;
|
||||
feedAlert.text = data.mess;
|
||||
feedAlert.color = 'red-darken-2';
|
||||
feedAlert.ico = 'mdi-alert-outline';
|
||||
}
|
||||
|
||||
/**
|
||||
* @arrowFunc
|
||||
* Обрабатывает окончание воспроизведения видео и переключает слайд.
|
||||
* @param {Object} val Событие окончания воспроизведения видео.
|
||||
*/
|
||||
const ended = (val) => {
|
||||
val.target.currentTime = 0;
|
||||
val.target.pause();
|
||||
document.exitFullscreen();
|
||||
currentslide.value =
|
||||
currentslide.value < carous.value.length - 1 ? currentslide.value + 1 : 0;
|
||||
};
|
||||
|
||||
return {
|
||||
slidechanged,
|
||||
videoElement,
|
||||
currentslide,
|
||||
getfromserver,
|
||||
interval,
|
||||
burl,
|
||||
carous,
|
||||
ended,
|
||||
};
|
||||
},
|
||||
if (Array.isArray(data.result) && data.result.length > 0) {
|
||||
slides.value = data.result;
|
||||
}
|
||||
} catch (e) {
|
||||
feedAlert.alert = true;
|
||||
feedAlert.text = 'Не удалось загрузить новости';
|
||||
feedAlert.color = 'red-darken-2';
|
||||
feedAlert.ico = 'mdi-alert-outline';
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/** Смена слайда: бампаем ключ, чтобы активное видео всегда было свежим элементом. */
|
||||
const onSlideChange = () => {
|
||||
videoKey.value += 1;
|
||||
};
|
||||
|
||||
/** Перейти к слайду по клику на индикатор. */
|
||||
const goTo = (index) => {
|
||||
current.value = index;
|
||||
};
|
||||
|
||||
/** Видео закончилось — выходим из полноэкранного режима и листаем дальше. */
|
||||
const onVideoEnded = () => {
|
||||
if (document.fullscreenElement) document.exitFullscreen();
|
||||
current.value = current.value < slides.value.length - 1 ? current.value + 1 : 0;
|
||||
};
|
||||
|
||||
onMounted(fetchSlides);
|
||||
|
||||
defineExpose({ fetchSlides });
|
||||
</script>
|
||||
<style>
|
||||
.titles {
|
||||
font-family: cursive !important;
|
||||
background: rgba(255, 255, 255, 0.7) !important;
|
||||
}
|
||||
|
||||
.bgCard {
|
||||
background: rgba(255, 255, 255, 0.5) !important;
|
||||
background-color: rgba(255, 255, 255, 0.5) !important;
|
||||
}
|
||||
|
||||
.v-card.bgCard {
|
||||
background: rgba(255, 255, 255, 0.5) !important;
|
||||
background-color: rgba(255, 255, 255, 0.5) !important;
|
||||
}
|
||||
|
||||
.textareas .v-field__input {
|
||||
font-size: 1.3em !important;
|
||||
}
|
||||
|
||||
.nocursor textarea {
|
||||
cursor: default !important;
|
||||
}
|
||||
</style>
|
||||
<style scoped>
|
||||
.bgCard {
|
||||
background: rgba(255, 255, 255, 0.3) !important;
|
||||
background-color: rgba(255, 255, 255, 0.3) !important;
|
||||
.news-carousel {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.v-card.bgCard {
|
||||
background: rgba(255, 255, 255, 0.3) !important;
|
||||
background-color: rgba(255, 255, 255, 0.3) !important;
|
||||
.news-carousel__media {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.titles, .text-text_carous, .text-text_caroustext-black, .v-card-title, .v-card-text, .v-textarea .v-field__input {
|
||||
color: #111 !important;
|
||||
text-shadow: none !important;
|
||||
.news-carousel__overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
padding: 24px;
|
||||
background: linear-gradient(
|
||||
to top,
|
||||
rgba(0, 0, 0, 0.7) 0%,
|
||||
rgba(0, 0, 0, 0.35) 35%,
|
||||
rgba(0, 0, 0, 0) 65%
|
||||
);
|
||||
}
|
||||
|
||||
.news-carousel__content {
|
||||
width: 100%;
|
||||
max-width: 720px;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.news-carousel__header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.news-carousel__title {
|
||||
flex: 1 1 auto;
|
||||
margin: 0;
|
||||
font-size: clamp(1.5rem, 3.5vw, 2.5rem);
|
||||
font-weight: 700;
|
||||
line-height: 1.15;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.news-carousel__sender {
|
||||
flex: 0 0 auto;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.news-carousel__text {
|
||||
margin: 0;
|
||||
max-height: 160px;
|
||||
overflow-y: auto;
|
||||
font-size: 1.05rem;
|
||||
line-height: 1.5;
|
||||
white-space: pre-line;
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: rgba(255, 255, 255, 0.5) transparent;
|
||||
}
|
||||
|
||||
.news-carousel__text::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.news-carousel__text::-webkit-scrollbar-thumb {
|
||||
background: rgba(255, 255, 255, 0.5);
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.news-carousel__video-wrap {
|
||||
height: 450px;
|
||||
background: #000;
|
||||
}
|
||||
|
||||
.news-carousel__video {
|
||||
max-height: 450px;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.news-carousel__video-poster {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 450px;
|
||||
}
|
||||
|
||||
.news-carousel__dots {
|
||||
position: absolute;
|
||||
bottom: 16px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 2;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
padding: 0 16px;
|
||||
}
|
||||
|
||||
.news-carousel__dot {
|
||||
position: relative;
|
||||
height: 6px;
|
||||
width: 24px;
|
||||
padding: 0;
|
||||
border: none;
|
||||
border-radius: 3px;
|
||||
background: rgba(255, 255, 255, 0.5);
|
||||
cursor: pointer;
|
||||
overflow: hidden;
|
||||
transition: width 0.3s ease, background 0.3s ease;
|
||||
}
|
||||
|
||||
.news-carousel__dot:hover {
|
||||
background: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
.news-carousel__dot--active {
|
||||
width: 44px;
|
||||
background: rgba(255, 255, 255, 0.4);
|
||||
}
|
||||
|
||||
.news-carousel__progress {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
transform-origin: left center;
|
||||
background: #fff;
|
||||
animation-name: news-carousel-fill;
|
||||
animation-timing-function: linear;
|
||||
animation-fill-mode: forwards;
|
||||
}
|
||||
|
||||
@keyframes news-carousel-fill {
|
||||
from {
|
||||
transform: scaleX(0);
|
||||
}
|
||||
to {
|
||||
transform: scaleX(1);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.news-carousel__progress {
|
||||
animation: none;
|
||||
transform: scaleX(1);
|
||||
}
|
||||
|
||||
.news-carousel__dot {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user