auth.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <Form
  3. v-model:is-visible="infoAuthForm"
  4. formMessage="Введите данные АСУ Проколледж"
  5. />
  6. <form
  7. class="w-full h-full flex flex-col items-center justify-between pt-8 text-white"
  8. @submit.prevent="auth"
  9. >
  10. <div class="flex flex-col justify-center items-center">
  11. <h1 class="text-4xl font-bold text-center">Войдите в аккаунт</h1>
  12. <p class="opacity-50">представьтесь пожалуйста</p>
  13. </div>
  14. <div>
  15. <ClientOnly>
  16. <lottie-player
  17. class="w-[200px] h-[200px]"
  18. autoplay
  19. loop
  20. mode="normal"
  21. src="/lottie/eyes.json"
  22. />
  23. </ClientOnly>
  24. </div>
  25. <div class="w-full flex flex-col items-center px-12">
  26. <input
  27. v-model="authData.login"
  28. :class="{
  29. 'opacity-50 cursor-not-allowed': isLoading,
  30. }"
  31. class="w-full text-xl font-light mb-3 bg-transparent border-2 border-foreground text-foreground border-opacity-50 focus:border-opacity-100 focus:invalid:border-red-500 invalid:border-red-800 outline-none px-6 py-2 rounded-lg duration-150"
  32. placeholder="Логин"
  33. type="text"
  34. autocomplete="username"
  35. :disabled="isLoading"
  36. required
  37. />
  38. <input
  39. v-model="authData.password"
  40. :class="{
  41. 'opacity-50 cursor-not-allowed': isLoading,
  42. }"
  43. class="w-full text-xl font-light mb-3 bg-transparent border-2 border-foreground text-foreground border-opacity-50 focus:border-opacity-100 focus:invalid:border-red-500 invalid:border-red-800 outline-none px-6 py-2 rounded-lg duration-150"
  44. placeholder="Пароль"
  45. type="password"
  46. autocomplete="current-password"
  47. :disabled="isLoading"
  48. required
  49. />
  50. <div class="duration-150" :class="errorMsg.show ? 'h-1' : 'h-0'" />
  51. <div
  52. :class="errorMsg.show ? 'h-fit' : 'h-0'"
  53. class="flex items-center duration-150 mb-3"
  54. >
  55. <Message
  56. class="w-full"
  57. :class="
  58. errorMsg.show
  59. ? 'opacity-100 h-fit duration-100'
  60. : 'opacity-0 h-0 duration-100'
  61. "
  62. type="danger"
  63. :text="errorMsg.msg"
  64. />
  65. </div>
  66. <div class="duration-150" :class="errorMsg.show ? 'h-1' : 'h-0'" />
  67. </div>
  68. <div>
  69. <DevOnly>
  70. <button type="button" class="relative" @click="useDebug().show">
  71. <Icon
  72. name="material-symbols:bug-report-outline-rounded"
  73. class="absolute -top-2 -left-3 h-8 w-8 opacity-40 hover:opacity-100"
  74. />
  75. </button>
  76. </DevOnly>
  77. </div>
  78. <div class="w-full">
  79. <div
  80. @click="infoAuthForm = true"
  81. class="w-full flex gap-2 justify-center items-center py-2 opacity-50 hover:opacity-100 duration-150 mb-0.5 cursor-pointer"
  82. >
  83. <img
  84. src="@/assets/icons/alert-circle 1.svg"
  85. alt="alert circle"
  86. class="h-7 w-7 text-background-100 rotate-180"
  87. />
  88. <p class="font-light text-lg">Откуда брать данные?</p>
  89. </div>
  90. <button
  91. class="w-full py-2 bg-primary flex gap-3 justify-center items-center group disabled:opacity-50 duration-150"
  92. :disabled="isLoading"
  93. type="submit"
  94. >
  95. <Icon
  96. name="svg-spinners:ring-resize"
  97. v-if="isLoading"
  98. class="w-6 h-6 text-background-100 opacity-75 group-hover:opacity-100"
  99. />
  100. <img
  101. v-else
  102. src="@/assets/icons/login 1.svg"
  103. alt="logout"
  104. class="w-6 h-6 opacity-75 group-hover:opacity-100"
  105. />
  106. <p
  107. class="text-2xl text-background-100 font-semibold opacity-75 group-hover:opacity-100 duration-150"
  108. v-text="isLoading ? 'Загрузка...' : 'Войти в аккаунт'"
  109. />
  110. </button>
  111. </div>
  112. </form>
  113. </template>
  114. <script setup lang="ts">
  115. import { useUser } from "~/store/useUser";
  116. import { useDebug } from "~/store/useDebug";
  117. definePageMeta({
  118. layout: "none",
  119. });
  120. const emit = defineEmits(["isClosed"]);
  121. const router = useRouter();
  122. const user = useUser();
  123. const api = useApi();
  124. const infoAuthForm = ref(false);
  125. const isLoading = ref(false);
  126. const errorMsg = reactive({
  127. show: false,
  128. msg: "",
  129. });
  130. const authData = reactive({
  131. login: "",
  132. password: "",
  133. });
  134. async function auth() {
  135. isLoading.value = true;
  136. errorMsg.show = false;
  137. await api
  138. .post("/user/login", authData)
  139. .then((res) => {
  140. user.setUserData(res);
  141. router.push("/profile");
  142. emit("isClosed");
  143. })
  144. .catch((err) => {
  145. const res = err.response;
  146. errorMsg.show = true;
  147. if (res) errorMsg.msg = res._data.error;
  148. else errorMsg.msg = "Проблемы с подключением к серверу. Попробуйте позже";
  149. });
  150. isLoading.value = false;
  151. }
  152. </script>