249 lines
7.6 KiB
Vue
249 lines
7.6 KiB
Vue
<!-- Раздел с назначенным тестированием -->
|
||
<template>
|
||
<!-- <div class="my-4 text-h5 font-weight-medium">{{ title }}</div> -->
|
||
<div :class="containerClass">
|
||
<v-container :fluid="true">
|
||
<v-row>
|
||
<v-text-field
|
||
v-model="search"
|
||
append-inner-icon="mdi-magnify"
|
||
label="Найти тестирование по названию"
|
||
variant="outlined"
|
||
density="comfortable"
|
||
bg-color="grey-lighten-4"
|
||
class="search-field"
|
||
hide-details
|
||
@click:append-inner="searchTest"
|
||
clearable
|
||
/>
|
||
</v-row>
|
||
</v-container>
|
||
<!-- Карточка где буду отрисовываться тесты в цикле -->
|
||
<v-card
|
||
v-for="cardValue in searchTest"
|
||
:key="cardValue.id"
|
||
class="my-4 test-card"
|
||
elevation="2"
|
||
:class="{ 'passed-test': activeTab === 0 && cardValue.is_passed }"
|
||
>
|
||
<v-row class="pa-4">
|
||
<v-col cols="2" class="justify-center my-auto">
|
||
<v-img
|
||
:src="cardValue.file || defaultImage"
|
||
class="mx-auto rounded-lg"
|
||
max-height="120"
|
||
contain
|
||
/>
|
||
</v-col>
|
||
<v-col cols="auto" class="d-flex flex-grow-1">
|
||
<div class="d-flex flex-column justify-center flex-grow-1">
|
||
<div class="text-h6 font-weight-bold mb-2">{{ cardValue.name }}</div>
|
||
<div class="text-body-1 text-grey-darken-1 mb-4 test-description" style="max-width: 600px" v-html="formatDescription(cardValue.description)"></div>
|
||
<div class="d-flex flex-wrap gap-4">
|
||
<slot name="results"></slot>
|
||
<div v-for="icon in activeTabIcon" class="d-inline-flex align-center test-info-item">
|
||
<v-icon :color="icon.color" :icon="icon.icon" size="small" class="mr-2" />
|
||
<span class="text-body-2">{{ momenter(cardValue[icon.field], icon.field) }}</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</v-col>
|
||
<v-col cols="auto" class="align-self-center">
|
||
<template v-if="activeTab === 0 && cardValue.is_passed">
|
||
<div class="d-flex align-center status-badge success">
|
||
<v-icon color="teal-darken-1" icon="mdi-check-circle-outline" size="small" class="mr-2" />
|
||
<span class="text-teal-darken-1 text-body-2 font-weight-medium">Сдано успешно</span>
|
||
</div>
|
||
</template>
|
||
<template v-else-if="cardValue.attemps_number > 0">
|
||
<slot name="buttons" :cardValue="cardValue"></slot>
|
||
</template>
|
||
<template v-else>
|
||
<div>
|
||
<div class="d-flex status-badge error mb-2">
|
||
<v-icon color="red-darken-1" icon="mdi-alert-circle-outline" size="small" class="mr-2" />
|
||
<span class="text-red-darken-1 text-body-2 font-weight-medium">Попытки закончились</span>
|
||
</div>
|
||
<div class="text-caption text-grey-darken-1 text-center">
|
||
Для повторного прохождения<br>обратитесь к администратору
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</v-col>
|
||
</v-row>
|
||
</v-card>
|
||
<!-- Если данные отсутствуют, выводим сообщение об этом -->
|
||
<v-container
|
||
v-if="!searchTest.length"
|
||
:fluid="true"
|
||
class="empty-state"
|
||
style="min-height: 70vh;"
|
||
>
|
||
<v-row class="align-center flex-column pa-8" style="min-height: 300px;">
|
||
<v-icon icon="mdi-note-off-outline" color="grey-lighten-1" size="64" class="mb-4" />
|
||
<v-card-title class="text-h5 text-grey-darken-1 font-weight-medium text-center">
|
||
Данные не найдены
|
||
</v-card-title>
|
||
</v-row>
|
||
</v-container>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
import moment from 'moment';
|
||
import { declOfNum } from '@/utils/universal_functions';
|
||
import { baseURL } from '@/utils/axios-api';
|
||
import defaultImage from '@/assets/emblem.png';
|
||
import { ref, computed } from 'vue';
|
||
|
||
export default {
|
||
props: {
|
||
title: {
|
||
type: String,
|
||
default: 'Не забыть передать тайтл сюда!',
|
||
},
|
||
activeTab: {
|
||
type: Number,
|
||
default: 0,
|
||
},
|
||
testingCard: {
|
||
type: Array,
|
||
default: () => [],
|
||
},
|
||
class: {
|
||
type: [String, Object, Array],
|
||
default: '',
|
||
},
|
||
},
|
||
setup(props) {
|
||
const search = ref('');
|
||
|
||
// Create a computed property to handle the containerClass
|
||
const containerClass = computed(() => props.class);
|
||
|
||
const searchTest = computed(() => {
|
||
let filteredTests = props.testingCard;
|
||
// Фильтруем неактивные тесты только во вкладке "Назначенные"
|
||
if (props.activeTab === 0) {
|
||
filteredTests = props.testingCard.filter((test) => test.is_active);
|
||
}
|
||
if (!search.value) return filteredTests;
|
||
return filteredTests.filter((item) =>
|
||
item.name.toLowerCase().includes(search.value.toLowerCase()),
|
||
);
|
||
});
|
||
|
||
const activeTabIcon = computed(() => {
|
||
let icons = [
|
||
// иконки для использования в карточках
|
||
{
|
||
icon: 'mdi-calendar-clock',
|
||
field: 'dateend',
|
||
color: 'teal-darken-1',
|
||
},
|
||
{
|
||
icon: 'mdi-clipboard-list-outline',
|
||
field: 'question_count',
|
||
color: 'teal-darken-1',
|
||
},
|
||
{
|
||
icon: 'mdi-timer-outline',
|
||
field: 'time',
|
||
color: 'teal-darken-1',
|
||
},
|
||
{
|
||
icon: 'mdi-fire',
|
||
field: 'attemps_number',
|
||
color: '#FF9800',
|
||
},
|
||
];
|
||
if (props.activeTab === 0) {
|
||
return icons;
|
||
} else {
|
||
return icons.splice(1, 2);
|
||
}
|
||
});
|
||
|
||
const momenter = (val, field) => {
|
||
if (field === 'dateend') {
|
||
return 'до ' + moment(val).format('DD.MM.YYYY, HH:mm');
|
||
} else if (field === 'question_count') {
|
||
return val + declOfNum(val, [' вопрос', ' вопроса', ' вопросов']);
|
||
} else if (field === 'time') {
|
||
return val + declOfNum(val, [' минута', ' минуты', ' минут']);
|
||
} else if (field === 'attemps_number') {
|
||
return val + declOfNum(val, [' попытка', ' попытки', ' попыток']);
|
||
}
|
||
return val;
|
||
};
|
||
|
||
const formatDescription = (text) => {
|
||
if (!text) return '';
|
||
// Заменяем \r\n и \n на <br>
|
||
return text.replace(/\r?\n/g, '<br>');
|
||
};
|
||
|
||
return { search, searchTest, momenter, activeTabIcon, baseURL, formatDescription, defaultImage, containerClass };
|
||
},
|
||
};
|
||
</script>
|
||
|
||
<style scoped>
|
||
.test-card {
|
||
border: 1px solid rgba(var(--v-border-color), 0.12);
|
||
background-color: rgb(var(--v-theme-cards));
|
||
}
|
||
|
||
.passed-test {
|
||
border-left: 4px solid rgb(var(--v-theme-btn_text));
|
||
}
|
||
|
||
.search-field {
|
||
max-width: 400px;
|
||
}
|
||
|
||
.test-info-item {
|
||
padding: 4px 12px;
|
||
background: rgba(var(--v-theme-btn_text), 0.05);
|
||
border-radius: 16px;
|
||
}
|
||
|
||
.status-badge {
|
||
padding: 8px 16px;
|
||
border-radius: 20px;
|
||
}
|
||
|
||
.status-badge.success {
|
||
background: rgba(var(--v-theme-btn_text), 0.1);
|
||
color: rgb(var(--v-theme-black_and_white));
|
||
}
|
||
|
||
.status-badge.error {
|
||
background: rgba(244, 67, 54, 0.1);
|
||
}
|
||
|
||
.no-attempts-container {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
padding: 12px;
|
||
max-width: 200px;
|
||
text-align: center;
|
||
}
|
||
|
||
.empty-state {
|
||
min-height: 300px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
background: rgba(var(--v-border-color), 0.05);
|
||
border-radius: 8px;
|
||
}
|
||
|
||
.test-description {
|
||
white-space: pre-wrap;
|
||
word-wrap: break-word;
|
||
color: rgb(var(--v-theme-text_carous));
|
||
}
|
||
</style>
|