pcpuma_unam_operador/components/Login.vue

97 lines
2.1 KiB
Vue
Raw Normal View History

2022-05-25 03:38:17 +00:00
<template>
<div class="full-h is-flex is-justify-content-center is-align-items-center">
<form class="box">
<div class="has-text-centered">
<h2 class="is-size-1">PC Puma</h2>
</div>
<b-field label="Usuario" :type="error">
2022-05-30 23:08:35 +00:00
<b-input type="text" @keyup.enter.native="login()" v-model="usuario" />
2022-05-25 03:38:17 +00:00
</b-field>
<b-field label="Contraseña" :type="error">
<b-input
type="password"
@keyup.enter.native="login()"
2022-05-30 23:08:35 +00:00
v-model="password"
password-reveal
2022-05-25 03:38:17 +00:00
/>
</b-field>
<div class="has-text-centered">
<b-button
@click="login()"
type="is-success"
2022-05-30 23:08:35 +00:00
:disabled="error || !(usuario && password)"
2022-05-25 03:38:17 +00:00
>
Iniciar Sesión
</b-button>
</div>
</form>
</div>
</template>
<script>
import axios from 'axios'
export default {
props: {
2022-05-30 23:08:35 +00:00
imprimirMensaje: { type: Function, required: true },
imprimirWarning: { type: Function, required: true },
2022-05-25 03:38:17 +00:00
imprimirError: { type: Function, required: true },
updateIsLoading: { type: Function, required: true },
},
data() {
return {
usuario: '',
2022-05-30 23:08:35 +00:00
password: '',
error: '',
2022-05-25 03:38:17 +00:00
}
},
methods: {
login() {
2022-05-30 23:08:35 +00:00
if (this.usuario && this.password && !this.error) {
2022-05-25 03:38:17 +00:00
const data = {
2022-05-30 23:08:35 +00:00
usuario: this.usuario,
2022-05-25 03:38:17 +00:00
password: this.password,
}
this.updateIsLoading(true)
axios
2022-05-30 23:08:35 +00:00
.post(`${process.env.api}/usuario/login`, data)
2022-05-25 03:38:17 +00:00
.then((res) => {
const info = res.data
localStorage.setItem('token', info.token)
this.updateIsLoading(false)
2022-05-30 23:08:35 +00:00
this.$router.push(`/${''}`)
2022-05-25 03:38:17 +00:00
})
.catch((err) => {
this.error = 'is-danger'
this.updateIsLoading(false)
this.imprimirError(err.response.data)
})
}
},
},
watch: {
password() {
if (this.error) this.error = ''
},
usuario() {
if (this.error) this.error = ''
},
},
}
</script>
<style scoped>
.full-h {
height: 75vh;
}
form {
width: 30rem;
}
</style>