auditories.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 } = useNuxtApp()
  51. const date = new Date()
  52. const hours = date.getHours().toString().padStart(2, '0')
  53. const minutes = date.getMinutes().toString().padStart(2, '0')
  54. const auditories = ref<Array<string> | null>(null)
  55. const auditoriesFree = ref<Array<string> | null>(null)
  56. const busyAuditories = computed(() => {
  57. const result: Array<string> = []
  58. // TODO: write types
  59. for (const i of auditories.value!) {
  60. if (auditoriesFree.value?.indexOf(i) === -1) {
  61. result.push(i)
  62. }
  63. }
  64. return result
  65. })
  66. onMounted(async () => {
  67. auditories.value = await $api.timetable.getClassrooms()
  68. auditoriesFree.value = await $api.timetable.getFreeClassrooms(`${hours}:${minutes}`)
  69. })
  70. </script>