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>
|
<template>
|
||||||
<!-- Карусель: Компонент для отображения изображений и видео с сервера в виде карусели -->
|
<!-- Карусель -->
|
||||||
<v-carousel
|
<div
|
||||||
v-model="currentslide"
|
class="news-carousel"
|
||||||
:interval="interval"
|
role="region"
|
||||||
cover
|
aria-label="Карусель новостей"
|
||||||
cycle
|
@mouseenter="paused = true"
|
||||||
height="450"
|
@mouseleave="paused = false"
|
||||||
hide-delimiters
|
|
||||||
hide-delimiter-background
|
|
||||||
:show-arrows="carous.length < 2 ? false : 'hover'"
|
|
||||||
color="teal-darken-4"
|
|
||||||
@update:modelValue="slidechanged"
|
|
||||||
>
|
>
|
||||||
<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-skeleton-loader
|
||||||
<v-container fill-height fluid pa-0 ma-0 pb-3 class="flex-column h-100 d-flex">
|
v-if="loading"
|
||||||
<v-card
|
type="image"
|
||||||
v-if="x.text !== '' || x.title != null"
|
height="450"
|
||||||
class="bgCard h-100 d-flex flex-column"
|
class="rounded-lg"
|
||||||
style="background: rgba(255, 255, 255, 0.3) !important; background-color: rgba(255, 255, 255, 0.3) !important;"
|
/>
|
||||||
|
|
||||||
|
<!-- Пустое состояние -->
|
||||||
|
<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
|
<template #placeholder>
|
||||||
v-if="x.title != null"
|
<div class="d-flex align-center justify-center fill-height">
|
||||||
class="text-h3 text-uppercase titles text-text_carous ma-1 mb-0"
|
<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>
|
<div class="news-carousel__content">
|
||||||
<v-col class="align-self-center">
|
<div v-if="slide.title" class="news-carousel__header">
|
||||||
{{ x.title }}
|
<h3 class="news-carousel__title">{{ slide.title }}</h3>
|
||||||
</v-col>
|
<v-avatar
|
||||||
<v-col class="flex-grow-0">
|
v-if="slide.sender"
|
||||||
<v-img width="50" :aspect-ratio="1" :src="`${burl}${x.sender}`" cover />
|
size="48"
|
||||||
</v-col>
|
rounded="lg"
|
||||||
</v-row>
|
class="news-carousel__sender"
|
||||||
</v-card-title>
|
>
|
||||||
<v-card-text
|
<v-img :src="absUrl(slide.sender)" :aspect-ratio="1" cover />
|
||||||
v-if="x.text !== ''"
|
</v-avatar>
|
||||||
class="w-50 flex-grow-0 text-h6 bgText overflow-auto ma-1 pa-0"
|
</div>
|
||||||
>
|
|
||||||
<v-textarea
|
<p v-if="slide.text" class="news-carousel__text">
|
||||||
class="text-text_caroustext-black textareas font-weight-medium nocursor"
|
{{ slide.text }}
|
||||||
:model-value="x.text"
|
</p>
|
||||||
variant="solo"
|
</div>
|
||||||
readonly
|
</div>
|
||||||
auto-grow
|
</v-img>
|
||||||
rows="1"
|
</template>
|
||||||
hide-details
|
|
||||||
flat
|
<!-- Видео -->
|
||||||
bg-color="transparent"
|
<template v-else>
|
||||||
/>
|
<div class="news-carousel__video-wrap">
|
||||||
</v-card-text>
|
<VideoPlayer
|
||||||
</v-card>
|
v-if="i === current"
|
||||||
</v-container>
|
: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-carousel-item v-else>
|
|
||||||
<div class="d-flex justify-center">
|
<!-- Кастомные индикаторы + прогресс автопрокрутки -->
|
||||||
<video
|
<div
|
||||||
ref="videoElement"
|
v-if="slides.length > 1"
|
||||||
style="height: 450px"
|
class="news-carousel__dots"
|
||||||
controls
|
role="tablist"
|
||||||
preload="metadata"
|
>
|
||||||
@ended="ended"
|
<button
|
||||||
@loadedmetadata="interval = 10000000000"
|
v-for="(slide, i) in slides"
|
||||||
>
|
:key="i"
|
||||||
<source :src="`${burl}${x.link}`" type="video/mp4" />
|
type="button"
|
||||||
Текущий браузер не поддерживает воспроизведение этого видео.
|
role="tab"
|
||||||
</video>
|
:aria-selected="i === current"
|
||||||
</div>
|
:aria-label="`Слайд ${i + 1}`"
|
||||||
</v-carousel-item>
|
class="news-carousel__dot"
|
||||||
</template>
|
:class="{ 'news-carousel__dot--active': i === current }"
|
||||||
</v-carousel>
|
@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>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script setup>
|
||||||
import { ref } from 'vue';
|
import { ref, computed, onMounted } from 'vue';
|
||||||
import { baseURL } from '@/utils/axios-api';
|
import { baseURL, axiosApiInstance } from '@/utils/axios-api';
|
||||||
import { axiosApiInstance } from '@/utils/axios-api';
|
|
||||||
import { useAlertStore } from '@/store/UseAlertStore';
|
import { useAlertStore } from '@/store/UseAlertStore';
|
||||||
|
import VideoPlayer from './VideoPlayer.vue';
|
||||||
|
|
||||||
export default {
|
/** Интервал автопрокрутки изображений, мс. */
|
||||||
setup() {
|
const INTERVAL_MS = 8000;
|
||||||
/**
|
|
||||||
* Хранит индекс текущего слайда карусели.
|
|
||||||
*/
|
|
||||||
const currentslide = ref(0);
|
|
||||||
|
|
||||||
/**
|
/** Базовый URL без завершающего слэша. */
|
||||||
* Базовый URL для загрузки медиа.
|
const burl = baseURL.slice(0, -1);
|
||||||
*/
|
|
||||||
const burl = baseURL.slice(0, -1);
|
|
||||||
|
|
||||||
/**
|
const feedAlert = useAlertStore().alert;
|
||||||
* Ссылка на элемент видео.
|
|
||||||
*/
|
|
||||||
const videoElement = ref(null);
|
|
||||||
|
|
||||||
/**
|
/** Список слайдов. Стартовая заглушка до ответа сервера. */
|
||||||
* Хранит массив данных карусели, по умолчанию содержит одно изображение.
|
const slides = ref([]);
|
||||||
*/
|
/** Индекс текущего слайда. */
|
||||||
const carous = ref([{ link: `/media/newsimage/scales.jpg`, title: null, text: '' }]);
|
const current = ref(0);
|
||||||
|
/** Флаг загрузки данных. */
|
||||||
|
const loading = ref(true);
|
||||||
|
/** Пауза автопрокрутки (например, при наведении). */
|
||||||
|
const paused = ref(false);
|
||||||
|
|
||||||
/**
|
/** Счётчик для принудительного пересоздания video-элемента при возврате на слайд. */
|
||||||
* Получает объект alert из хранилища alert для уведомлений.
|
const videoKey = ref(0);
|
||||||
*/
|
|
||||||
const feedalert = useAlertStore().alert;
|
|
||||||
|
|
||||||
/**
|
/** Является ли слайд видео. */
|
||||||
* Интервал переключения слайдов в миллисекундах.
|
const isVideo = (slide) => slide?.link?.toLowerCase().endsWith('.mp4');
|
||||||
*/
|
|
||||||
const interval = ref(10000);
|
|
||||||
|
|
||||||
/**
|
/** Текущий слайд — видео? */
|
||||||
* @arrowFunc
|
const currentIsVideo = computed(() => isVideo(slides.value[current.value]));
|
||||||
* Обрабатывает запрос для получения данных карусели с сервера.
|
|
||||||
*/
|
|
||||||
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';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.data.result.length > 0) {
|
/** Автопрокрутка активна только для изображений и при наличии >1 слайда. */
|
||||||
carous.value = result.data.result;
|
const autoplayEnabled = computed(
|
||||||
}
|
() => slides.value.length > 1 && !currentIsVideo.value && !paused.value,
|
||||||
});
|
);
|
||||||
};
|
|
||||||
|
|
||||||
getfromserver();
|
/** Абсолютный URL для медиа. */
|
||||||
|
const absUrl = (path) => `${burl}${path}`;
|
||||||
|
|
||||||
/**
|
/** Загрузка слайдов с сервера. */
|
||||||
* @arrowFunc
|
const fetchSlides = async () => {
|
||||||
* Управляет изменением слайда и переключением интервала в зависимости от типа медиа.
|
loading.value = true;
|
||||||
*/
|
try {
|
||||||
const slidechanged = () => {
|
const { data } = await axiosApiInstance.get('api/navigation/carousels/');
|
||||||
if (carous.value[currentslide.value].link.endsWith('mp4')) {
|
|
||||||
// При переключении на видео, останавливаем все другие видео
|
|
||||||
videoElement.value.forEach((e) => {
|
|
||||||
if (e.currentSrc !== burl + carous.value[currentslide.value].link) {
|
|
||||||
e.pause();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (carous.value[currentslide.value].link.endsWith('mp4')) {
|
if (data.mess) {
|
||||||
interval.value = 10000000000;
|
feedAlert.alert = true;
|
||||||
} else {
|
feedAlert.text = data.mess;
|
||||||
interval.value = 10000;
|
feedAlert.color = 'red-darken-2';
|
||||||
}
|
feedAlert.ico = 'mdi-alert-outline';
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
if (Array.isArray(data.result) && data.result.length > 0) {
|
||||||
* @arrowFunc
|
slides.value = data.result;
|
||||||
* Обрабатывает окончание воспроизведения видео и переключает слайд.
|
}
|
||||||
* @param {Object} val Событие окончания воспроизведения видео.
|
} catch (e) {
|
||||||
*/
|
feedAlert.alert = true;
|
||||||
const ended = (val) => {
|
feedAlert.text = 'Не удалось загрузить новости';
|
||||||
val.target.currentTime = 0;
|
feedAlert.color = 'red-darken-2';
|
||||||
val.target.pause();
|
feedAlert.ico = 'mdi-alert-outline';
|
||||||
document.exitFullscreen();
|
} finally {
|
||||||
currentslide.value =
|
loading.value = false;
|
||||||
currentslide.value < carous.value.length - 1 ? currentslide.value + 1 : 0;
|
}
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
slidechanged,
|
|
||||||
videoElement,
|
|
||||||
currentslide,
|
|
||||||
getfromserver,
|
|
||||||
interval,
|
|
||||||
burl,
|
|
||||||
carous,
|
|
||||||
ended,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Смена слайда: бампаем ключ, чтобы активное видео всегда было свежим элементом. */
|
||||||
|
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>
|
</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>
|
<style scoped>
|
||||||
.bgCard {
|
.news-carousel {
|
||||||
background: rgba(255, 255, 255, 0.3) !important;
|
position: relative;
|
||||||
background-color: rgba(255, 255, 255, 0.3) !important;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.v-card.bgCard {
|
.news-carousel__media {
|
||||||
background: rgba(255, 255, 255, 0.3) !important;
|
position: relative;
|
||||||
background-color: rgba(255, 255, 255, 0.3) !important;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.titles, .text-text_carous, .text-text_caroustext-black, .v-card-title, .v-card-text, .v-textarea .v-field__input {
|
.news-carousel__overlay {
|
||||||
color: #111 !important;
|
position: absolute;
|
||||||
text-shadow: none !important;
|
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>
|
</style>
|
||||||
Reference in new issue
Block a user