125 lines
2.8 KiB
Vue
125 lines
2.8 KiB
Vue
![]() |
<template>
|
||
|
<div
|
||
|
class="full-h is-flex is-justify-content-center is-align-items-center my-5"
|
||
|
>
|
||
|
<form class="box">
|
||
|
<div class="has-text-centered">
|
||
|
<h2 class="is-size-1">PC Puma</h2>
|
||
|
</div>
|
||
|
|
||
|
<b-field label="Usuario" :type="error">
|
||
|
<b-input v-model="usuario" @keyup.enter.native="login()" />
|
||
|
</b-field>
|
||
|
|
||
|
<b-field label="Contraseña" :type="error">
|
||
|
<b-input
|
||
|
type="password"
|
||
|
password-reveal
|
||
|
v-model="password"
|
||
|
@keyup.enter.native="login()"
|
||
|
/>
|
||
|
</b-field>
|
||
|
|
||
|
<div class="has-text-centered">
|
||
|
<b-button
|
||
|
@click="login()"
|
||
|
type="is-success"
|
||
|
:disabled="error || !usuario || !password"
|
||
|
>
|
||
|
Iniciar Sesión
|
||
|
</b-button>
|
||
|
</div>
|
||
|
</form>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
|
import axios from 'axios'
|
||
|
|
||
|
export default {
|
||
|
props: {
|
||
|
imprimirMensaje: { type: Function, required: true },
|
||
|
imprimirWarning: { type: Function, required: true },
|
||
|
imprimirError: { type: Function, required: true },
|
||
|
updateIsLoading: { type: Function, required: true },
|
||
|
},
|
||
|
data() {
|
||
|
return {
|
||
|
error: '',
|
||
|
usuario: '',
|
||
|
password: '',
|
||
|
}
|
||
|
},
|
||
|
methods: {
|
||
|
login() {
|
||
|
if (this.usuario && this.password && !this.error) {
|
||
|
const data = {
|
||
|
operador: this.usuario,
|
||
|
password: this.password,
|
||
|
}
|
||
|
this.updateIsLoading(true)
|
||
|
axios
|
||
|
.post(`${process.env.api}/auth/login-admin`, data)
|
||
|
.then((res) => {
|
||
|
const info = JSON.stringify(res.data)
|
||
|
localStorage.setItem('usuario', info)
|
||
|
this.updateIsLoading(false)
|
||
|
this.$router.push('/operador/prestamo_devolucion')
|
||
|
})
|
||
|
.catch((err) => {
|
||
|
this.error = 'is-danger'
|
||
|
this.updateIsLoading(false)
|
||
|
this.imprimirError(err.response.data)
|
||
|
})
|
||
|
}
|
||
|
},
|
||
|
obtenerCatalogoInstitucion() {
|
||
|
axios
|
||
|
.get(`${process.env.api}/institucion`)
|
||
|
.then((res) => {
|
||
|
this.instituciones = res.data
|
||
|
})
|
||
|
.catch((err) => {
|
||
|
this.imprimirError(err)
|
||
|
})
|
||
|
},
|
||
|
obtenerCatalogoModulo() {
|
||
|
axios
|
||
|
.get(
|
||
|
`${process.env.api}/modulo/modulos?id_institucion=${this.idInstitucion}`
|
||
|
)
|
||
|
.then((res) => {
|
||
|
this.modulos = res.data
|
||
|
})
|
||
|
.catch((err) => {
|
||
|
this.imprimirError(err)
|
||
|
})
|
||
|
},
|
||
|
},
|
||
|
watch: {
|
||
|
password() {
|
||
|
if (this.error) this.error = ''
|
||
|
},
|
||
|
usuario() {
|
||
|
if (this.error) this.error = ''
|
||
|
},
|
||
|
idInstitucion() {
|
||
|
this.obtenerCatalogoModulo()
|
||
|
},
|
||
|
},
|
||
|
created() {
|
||
|
this.obtenerCatalogoInstitucion()
|
||
|
},
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<style scoped>
|
||
|
.full-h {
|
||
|
height: 75vh;
|
||
|
}
|
||
|
|
||
|
form {
|
||
|
width: 30rem;
|
||
|
}
|
||
|
</style>
|