feat: added ts

This commit is contained in:
Arduinum
2026-02-19 16:26:16 +03:00
committed by Arduinum628
parent ec3d712a82
commit d26310ddad
21 changed files with 135 additions and 149 deletions

View File

@@ -1,66 +0,0 @@
import { IonIcon } from '@ionic/vue';
import {
timerOutline,
chevronUp,
chevronDown,
playCircleOutline,
pencilOutline,
trashOutline
} from 'ionicons/icons';
import { ref, onMounted } from 'vue';
import { getTimers } from '../../db/crud/timerCrud';
export default {
name: 'TimersList',
components: {
IonIcon,
},
setup() {
const timers = ref([]);
const loading = ref(true);
const error = ref(null);
const expandedId = ref(null);
const loadTimers = async () => {
loading.value = true;
error.value = null;
try {
const result = await getTimers();
timers.value = result;
} catch (err) {
error.value = err.message || 'Ошибка загрузки таймеров';
} finally {
loading.value = false;
}
};
const toggleExpand = (id) => {
expandedId.value = expandedId.value === id ? null : id;
};
onMounted(() => {
loadTimers();
});
return {
// состояние
timers,
loading,
error,
expandedId,
// методы
toggleExpand,
// иконки
timerOutline,
chevronUp,
chevronDown,
playCircleOutline,
pencilOutline,
trashOutline,
};
},
};

View File

@@ -0,0 +1,60 @@
import { defineComponent, onMounted, ref } from 'vue'
import { IonIcon } from '@ionic/vue'
import {
timerOutline,
chevronUp,
chevronDown,
playCircleOutline,
pencilOutline,
trashOutline,
} from 'ionicons/icons'
import { getTimers } from '@/db/crud/timerCrud'
import type { TimersRow } from '@/types/timerType'
export default defineComponent({
name: 'TimersList',
components: { IonIcon },
setup() {
const timers = ref<TimersRow[]>([])
const loading = ref<boolean>(true)
const error = ref<string | null>(null)
const expandedId = ref<number | null>(null)
const loadTimers = async (): Promise<void> => {
loading.value = true
error.value = null
try {
const result = await getTimers()
timers.value = result
} catch (e: unknown) {
error.value = e instanceof Error ? e.message : 'Ошибка загрузки таймеров'
} finally {
loading.value = false
}
}
const toggleExpand = (id: number): void => {
expandedId.value = expandedId.value === id ? null : id
}
onMounted(loadTimers)
return {
timers,
loading,
error,
expandedId,
toggleExpand,
timerOutline,
chevronUp,
chevronDown,
playCircleOutline,
pencilOutline,
trashOutline,
}
},
})

View File

@@ -1,4 +1,4 @@
<!-- TimersList.vue -->
<template src="./TimersList.html"></template>
<script src="./TimersList.js"></script>
<style src="./TimersList.css" scoped></style>
<template src="@/views/TimersList/TimersList.html"></template>
<script lang="ts" src="@/views/TimersList/TimersList.ts"></script>
<style src="@/views/TimersList/TimersList.css" scoped></style>