Auth.vue 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <Form
  3. v-model:is-visible="infoAuthForm"
  4. formMessage="Введите данные АСУ Проколледж"
  5. />
  6. <form class="flex flex-col gap-3" @submit.prevent="auth">
  7. <h1 class="text-4xl font-light text-center mb-6">Войдите в аккаунт</h1>
  8. <input
  9. v-model="authData.login"
  10. class="bg-transparent border-[1px] border-white text-white border-opacity-50 focus:border-opacity-100 focus:invalid:border-red-500 invalid:border-red-800 text-lg outline-none p-3 rounded-md duration-150"
  11. placeholder="Логин"
  12. type="text"
  13. autocomplete="username"
  14. required
  15. />
  16. <input
  17. v-model="authData.password"
  18. class="bg-transparent border-[1px] border-white text-white border-opacity-50 focus:border-opacity-100 focus:invalid:border-red-500 invalid:border-red-800 text-lg outline-none p-3 rounded-md duration-150"
  19. placeholder="Пароль"
  20. type="password"
  21. autocomplete="current-password"
  22. required
  23. />
  24. <Message type="done" text="123" />
  25. <button
  26. class="border-[1px] font-semibold text-md border-primary hover:bg-primary hover:text-black rounded-md flex gap-3 justify-center items-center mt-6 duration-150"
  27. :class="isLoading ? 'h-10' : 'h-12'"
  28. type="submit"
  29. >
  30. <Icon name="svg-spinners:ring-resize" v-if="isLoading" class="w-6 h-6" />
  31. <p
  32. class="text-lg"
  33. v-text="isLoading ? 'Авторизация' : 'Войти в аккаунт'"
  34. />
  35. </button>
  36. <button
  37. @click="infoAuthForm = true"
  38. class="h-12 border-[1px] font-semibold text-md border-yellow-300 hover:bg-yellow-300 hover:text-black rounded-md flex gap-3 justify-center items-center duration-150"
  39. type="button"
  40. >
  41. <p class="text-lg">Откуда брать данные?</p>
  42. </button>
  43. </form>
  44. </template>
  45. <script setup lang="ts">
  46. import { $fetch } from "ofetch";
  47. import { useUser } from "~/store/useUser";
  48. const emit = defineEmits(["isClosed"]);
  49. const {
  50. public: { API_URL },
  51. } = useRuntimeConfig();
  52. const router = useRouter();
  53. const user = useUser();
  54. const infoAuthForm = ref(false);
  55. const isLoading = ref(false);
  56. const authData = reactive({
  57. login: "",
  58. password: "",
  59. });
  60. async function auth() {
  61. isLoading.value = true;
  62. await $fetch(`${API_URL}/user/login`, {
  63. method: "POST",
  64. body: authData,
  65. }).then(() => {
  66. user.setUserData(res);
  67. router.push("/profile");
  68. emit("isClosed");
  69. }).catch((err) => {
  70. const res = err.response;
  71. if (res) {
  72. console.log(res._data.error)
  73. }
  74. });
  75. isLoading.value = false
  76. }
  77. </script>
  78. <style scoped></style>