feat: create slots for button, universal funcrion

This commit is contained in:
Alex committed 2025-01-28 15:26:49 +03:00
1 parent 016e19d1bf
commit d125712ee6
4 files changed
+60 -43

No files matched your search

+1 -5
View File
@@ -41,6 +41,7 @@
</template> </template>
<script> <script>
import { declOfNum } from '@/utils/universal_functions'
import { computed, ref } from 'vue' import { computed, ref } from 'vue'
export default { export default {
@@ -66,11 +67,6 @@ export default {
const hours = computed(() => minutes.value * 60); const hours = computed(() => minutes.value * 60);
const days = computed(() => hours.value * 24); const days = computed(() => hours.value * 24);
function declOfNum(value, titles) {
const cases = [2, 0, 1, 1, 1, 2];
return titles[(value % 100 > 4 && value % 100 < 20) ? 2 : cases[(value % 10 < 5) ? value % 10 : 5]];
}
const disabledcard = ref({ const disabledcard = ref({
text: 'окончания', text: 'окончания',
disabled: false disabled: false
@@ -25,7 +25,7 @@
<div class="d-flex ga-4"> <div class="d-flex ga-4">
<div v-for="icon in icons"> <div v-for="icon in icons">
<v-icon :color="icon.color" :icon="icon.icon" size="large" /> <v-icon :color="icon.color" :icon="icon.icon" size="large" />
<span class="ml-1">{{ cardValue[icon.field] }}</span> <span class="ml-1">{{ momenter(cardValue[icon.field], icon.field) }}</span>
</div> </div>
</div> </div>
</div> </div>
@@ -44,6 +44,8 @@
</template> </template>
<script> <script>
import moment from 'moment';
import { declOfNum } from '@/utils/universal_functions'
import { ref, computed } from 'vue'; import { ref, computed } from 'vue';
export default { export default {
@@ -61,10 +63,10 @@ export default {
type: 'test', type: 'test',
description: 'Краткое описание тестирования', description: 'Краткое описание тестирования',
file: 'https://icdn.lenta.ru/images/2024/03/27/12/20240327123127525/square_1280_63e6b3d7acbfce65d885ae4cf216dfe2.jpg', file: 'https://icdn.lenta.ru/images/2024/03/27/12/20240327123127525/square_1280_63e6b3d7acbfce65d885ae4cf216dfe2.jpg',
dateend: `до ${'31.02.2025'}`, dateend: new Date(),
questionCount: 20, question_count: 20,
time: '15 минут', time: 20,
attempts_number: 1, attemps_number: 3,
}, },
{ {
id: 2, id: 2,
@@ -72,9 +74,10 @@ export default {
type: 'test', type: 'test',
description: 'Опрос среди сотрудников ЦОД МФ', description: 'Опрос среди сотрудников ЦОД МФ',
file: 'https://icdn.lenta.ru/images/2024/03/27/12/20240327123127525/square_1280_63e6b3d7acbfce65d885ae4cf216dfe2.jpg', file: 'https://icdn.lenta.ru/images/2024/03/27/12/20240327123127525/square_1280_63e6b3d7acbfce65d885ae4cf216dfe2.jpg',
dateend: `до ${'31.06.2025'}`, dateend: new Date(),
questionCount: 28, question_count: 28,
time: '15 минут', time: 15,
attemps_number: 1,
}, },
] ]
} }
@@ -82,25 +85,25 @@ export default {
setup(props) { setup(props) {
const search = ref(''); const search = ref('');
const icons = [ const icons = [
{
icon: 'mdi-calendar-clock',
field: 'dateend',
color: 'teal-darken-1',
},
{
icon: 'mdi-clipboard-list-outline',
field: 'questionCount',
color: 'teal-darken-1',
},
// иконки для использования на вкладке назначенные использовать можно эти // иконки для использования на вкладке назначенные использовать можно эти
// { // {
// icon: 'mdi-timer-outline', // icon: 'mdi-calendar-clock',
// field: 'time', // field: 'dateend',
// color: 'teal-darken-1', // 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', // icon: 'mdi-fire',
// field: 'attempts_number', // field: 'attemps_number',
// color: '#FF9800' // color: '#FF9800'
// }, // },
] ]
@@ -110,7 +113,20 @@ export default {
return props.testingCard.filter(item => item.name.toLowerCase().includes(search.value.toLowerCase())) return props.testingCard.filter(item => item.name.toLowerCase().includes(search.value.toLowerCase()))
}) })
return { icons, search, searchTest } const momenter = (val, field)=>{
if (field == 'dateend'){
return 'до ' + moment(val).format('DD.MM.YYYY, HH:mm')
}
else if (field == 'question_count') {
return val + ' вопросов'
}
else if (field == 'time') {
return val + declOfNum(val, [' минута', ' минуты', ' минут'])
}
return val
}
return { icons, search, searchTest, momenter }
} }
} }
@@ -172,3 +172,9 @@ export function useICalReader(url) {
// return { icsContent, fetchICalFile } // return { icsContent, fetchICalFile }
// } // }
// Функция склонения числительных
export function declOfNum(value, titles) {
const cases = [2, 0, 1, 1, 1, 2];
return titles[(value % 100 > 4 && value % 100 < 20) ? 2 : cases[(value % 10 < 5) ? value % 10 : 5]];
}
+15 -16
View File
@@ -11,14 +11,11 @@
<div>Сюда заврешенные!</div> <div>Сюда заврешенные!</div>
</v-tabs-window-item> </v-tabs-window-item>
<v-tabs-window-item> <v-tabs-window-item>
<CatalogTest title="Каталог"> <CatalogTest title="Каталог" :testingCard="getAllTests">
<template #buttons> <template #buttons>
<v-btn color="#00897B1F" class="mr-2 text-teal-darken-1" elevation="0"> <v-btn color="#00897B1F" class="mr-2 text-teal-darken-1" elevation="0">
Тренироваться Тренироваться
</v-btn> </v-btn>
<v-btn color="teal-darken-1" elevation="0">
Пройти
</v-btn>
</template> </template>
</CatalogTest> </CatalogTest>
</v-tabs-window-item> </v-tabs-window-item>
@@ -28,7 +25,9 @@
<script> <script>
import CatalogTest from "@/components/testing/CatalogTest.vue"; import CatalogTest from "@/components/testing/CatalogTest.vue";
import { ref } from "vue" import { axiosApiInstance } from "@/utils/axios-api";
import { ref, computed } from "vue"
export default { export default {
components: { components: {
@@ -36,25 +35,25 @@ export default {
}, },
setup() { setup() {
const activeTab = ref(0); const activeTab = ref(0);
const getAllTests = ref([])
const test = [ const getTestById = () => {
{ axiosApiInstance.get('/api/tests/testlist/').then(resp => getAllTests.value = resp.data.results)
text: 'awdawd', }
},
{
text: 'awdawd',
},
]
const tabs = ref([ getTestById()
{ value: 0, title: `Назначенные (${test.length})`, },
const tabs = computed(() => [
{ value: 0, title: `Назначенные (${getAllTests.value.length})`, },
{ value: 1, title: 'Завершенные', }, { value: 1, title: 'Завершенные', },
{ value: 2, title: 'Каталог', }, { value: 2, title: 'Каталог', },
]) ])
return { return {
activeTab, activeTab,
tabs tabs,
getAllTests
} }
} }
} }