group.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <div
  3. v-if="!data"
  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-8 show"
  11. >
  12. <div
  13. v-for="part in data"
  14. :key="part.title"
  15. class="flex flex-col gap-2"
  16. >
  17. <h1
  18. class="text-2xl font-semibold"
  19. v-text="part.title"
  20. />
  21. <div class="grid grid-cols-3 grid-rows-auto gap-2">
  22. <div
  23. v-for="group in part.groups"
  24. :key="group.id"
  25. class="bg-primary hover:bg-opacity-80 text-black rounded-md text-xl py-2 font-semibold duration-150 text-center"
  26. @click="setGroup(group)"
  27. v-text="group.title"
  28. />
  29. </div>
  30. </div>
  31. </div>
  32. </template>
  33. <script setup lang="ts">
  34. import { useUser } from '~/store/useUser'
  35. definePageMeta({
  36. name: 'Выберите группу',
  37. middleware: ['user-only'],
  38. })
  39. const user = useUser()
  40. const { $api } = useNuxtApp()
  41. const router = useRouter()
  42. const data = ref()
  43. interface Group {
  44. id: number
  45. title: string
  46. }
  47. if (!(Object.hasOwn(user.data, 'is_student') && Object.hasOwn(user.data, 'branch_id'))) {
  48. router.push('/setup/branch')
  49. }
  50. function setGroup(group: Group) {
  51. user.data.group_id = group.id
  52. router.push('/timetable')
  53. }
  54. onMounted(async () => {
  55. data.value = await $api.timetable.getCourses(user.data.branch_id)
  56. })
  57. </script>