auditories.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <div
  3. v-if="!(auditories && auditoriesFree)"
  4. class="w-full h-full flex items-center justify-center show"
  5. >
  6. <ILoader class="w-16 h-16 text-foreground" />
  7. </div>
  8. <div
  9. v-else
  10. class="flex flex-col p-4 gap-2 show"
  11. >
  12. <template v-if="busyAuditories.length > 0">
  13. <h1 class="text-2xl font-semibold">
  14. Сейчас заняты
  15. </h1>
  16. <div class="flex flex-wrap gap-2 mb-8">
  17. <span
  18. v-for="(auditory, index) in busyAuditories"
  19. :key="index"
  20. class="text-xl font-semibold rounded-md px-2 py-1 bg-primary text-background-100"
  21. @click="$router.push(`/timetable/auditory/${auditory}`)"
  22. >
  23. {{ auditory }}
  24. </span>
  25. <p>Кабинеты отстутствуют</p>
  26. </div>
  27. </template>
  28. <template v-if="auditoriesFree.length > 0">
  29. <h1 class="text-2xl font-semibold">
  30. Сейчас свободны
  31. </h1>
  32. <div class="flex flex-wrap gap-2">
  33. <span
  34. v-for="(auditory, index) in auditoriesFree"
  35. :key="index"
  36. class="text-xl font-semibold rounded-md px-2 py-1 bg-foreground text-background-100"
  37. @click="$router.push(`/timetable/auditory/${auditory}`)"
  38. >
  39. {{ auditory }}
  40. </span>
  41. </div>
  42. </template>
  43. </div>
  44. </template>
  45. <script setup lang="ts">
  46. definePageMeta({
  47. name: 'Выберите аудиторию',
  48. middleware: ['user-only'],
  49. })
  50. const api = useApi()
  51. const auditories = ref<Array<string> | null>(null)
  52. const auditoriesFree = ref<Array<string> | null>(null)
  53. const busyAuditories = computed(() => {
  54. const result: Array<string> = []
  55. // TODO: write types
  56. for (const i of auditories.value!) {
  57. if (auditoriesFree.value?.indexOf(i) === -1) {
  58. result.push(i)
  59. }
  60. }
  61. return result
  62. })
  63. onMounted(async () => {
  64. const date = new Date()
  65. const hours = date.getHours().toString().padStart(2, '0')
  66. const minutes = date.getMinutes().toString().padStart(2, '0')
  67. auditories.value = await api.get(`/timetable/classrooms/`)
  68. auditoriesFree.value = await api.get(`/timetable/classrooms/free?time=${hours}:${minutes}`)
  69. })
  70. </script>