feat: added ts
This commit is contained in:
@@ -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,
|
||||
};
|
||||
},
|
||||
};
|
||||
60
client/src/views/TimersList/TimersList.ts
Normal file
60
client/src/views/TimersList/TimersList.ts
Normal 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,
|
||||
}
|
||||
},
|
||||
})
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user