Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x | <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="white"
@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-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">
<v-card-title
v-if="x.title != null"
class="text-h3 text-uppercase titles text-text_carous ma-1 mb-0"
>
<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>
</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>
</template>
<script>
import { ref } from 'vue';
import { baseURL } from '@/utils/axios-api';
import { axiosApiInstance } from '@/utils/axios-api';
import { useAlertStore } from '@/store/useAlertStore';
export default {
setup() {
/**
* Хранит индекс текущего слайда карусели.
*/
const currentslide = ref(0);
/**
* Базовый URL для загрузки медиа.
*/
const burl = baseURL.slice(0, -1);
/**
* Ссылка на элемент видео.
*/
const videoElement = ref(null);
/**
* Хранит массив данных карусели, по умолчанию содержит одно изображение.
*/
const carous = ref([{ link: `/media/newsimage/scales.jpg`, title: null, text: '' }]);
/**
* Получает объект alert из хранилища alert для уведомлений.
*/
const feedalert = useAlertStore().alert;
/**
* Интервал переключения слайдов в миллисекундах.
*/
const interval = ref(10000);
/**
* @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';
}
if (result.data.result.length > 0) {
carous.value = result.data.result;
}
});
};
getfromserver();
/**
* @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();
}
});
}
if (carous.value[currentslide.value].link.endsWith('mp4')) {
interval.value = 10000000000;
} else {
interval.value = 10000;
}
};
/**
* @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,
};
},
};
</script>
<style>
.titles {
font-family: cursive !important;
background: #ffffff8c;
}
.textareas .v-field__input {
font-size: 1.3em !important;
}
.nocursor textarea {
cursor: default !important;
}
</style>
|