153 lines
4.0 KiB
Vue
153 lines
4.0 KiB
Vue
<template>
|
|
<section
|
|
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">
|
|
<b-input
|
|
autocomplete="off"
|
|
@keyup.enter.native="login()"
|
|
v-model="usuario"
|
|
/>
|
|
</b-field>
|
|
|
|
<b-field label="Contraseña" :type="error">
|
|
<b-input
|
|
autocomplete="off"
|
|
type="password"
|
|
@keyup.enter.native="login()"
|
|
v-model="password"
|
|
password-reveal
|
|
/>
|
|
</b-field>
|
|
|
|
<SelectInstitucion
|
|
:activas="true"
|
|
:column="false"
|
|
:idInstitucionPadre="idInstitucion"
|
|
@institucion-seleccionada="updateIdInstitucion"
|
|
/>
|
|
|
|
<InputRecordar
|
|
nombreVariable="idInstitucion"
|
|
:variablePadre="idInstitucion"
|
|
/>
|
|
|
|
<SelectModulo
|
|
:activos="true"
|
|
:column="false"
|
|
:idInstitucion="idInstitucion"
|
|
:idModuloPadre="idModulo"
|
|
@modulo-seleccionado="updateIdModulo"
|
|
deshabilitarOptVacia
|
|
/>
|
|
|
|
<InputRecordar nombreVariable="idModulo" :variablePadre="idModulo" />
|
|
|
|
<div class="is-flex is-justify-content-center my-3">
|
|
<recaptcha v-show="idModulo && usuario && password" />
|
|
</div>
|
|
|
|
<BotonIniciarSesion
|
|
:login="login"
|
|
:disabled="error != '' || !usuario || !password || !idModulo"
|
|
/>
|
|
</form>
|
|
</section>
|
|
</template>
|
|
|
|
<script>
|
|
import axios from 'axios'
|
|
import BotonIniciarSesion from '@/components/botones/BotonIniciarSesion'
|
|
import InputRecordar from '@/components/inputs/InputRecordar'
|
|
import SelectInstitucion from '@/components/selects/SelectInstitucion'
|
|
import SelectModulo from '@/components/selects/SelectModulo'
|
|
|
|
export default {
|
|
components: {
|
|
BotonIniciarSesion,
|
|
InputRecordar,
|
|
SelectInstitucion,
|
|
SelectModulo,
|
|
},
|
|
props: {
|
|
updateIsLoading: { type: Function, required: true, default: () => {} },
|
|
updateIdModulo: { type: Function, required: true, default: () => {} },
|
|
updateIdInstitucion: { type: Function, required: true, default: () => {} },
|
|
idInstitucion: { type: Number, required: true, default: 0 },
|
|
idModulo: { type: Number, required: true, default: 0 },
|
|
},
|
|
data() {
|
|
return { error: '', usuario: '', password: '' }
|
|
},
|
|
methods: {
|
|
async login() {
|
|
if (this.usuario && this.password && this.idModulo && !this.error) {
|
|
const token = await this.$recaptcha.getResponse().catch((err) => {
|
|
this.$alertsGenericos.imprimirError(this.$buefy, this.$router, {
|
|
message: 'Favor de completar el recaptcha.',
|
|
})
|
|
})
|
|
|
|
if (token) {
|
|
const data = {
|
|
operador: this.usuario,
|
|
password: this.password,
|
|
id_modulo: this.idModulo,
|
|
}
|
|
|
|
this.updateIsLoading(true)
|
|
return axios
|
|
.post(`${process.env.api}/auth/login-operador`, data, {
|
|
headers: { recaptcha: token },
|
|
})
|
|
.then(async (res) => {
|
|
const token = res.data.token
|
|
|
|
localStorage.setItem('token', token)
|
|
await this.$recaptcha.reset()
|
|
this.updateIsLoading(false)
|
|
this.$router.push('/prestamo_devolucion')
|
|
})
|
|
.catch(async (err) => {
|
|
this.error = 'is-danger'
|
|
await this.$recaptcha.reset()
|
|
this.updateIsLoading(false)
|
|
this.$alertsGenericos.imprimirError(
|
|
this.$buefy,
|
|
this.$router,
|
|
err.response.data
|
|
)
|
|
})
|
|
}
|
|
}
|
|
},
|
|
},
|
|
watch: {
|
|
password() {
|
|
if (this.error) this.error = ''
|
|
},
|
|
usuario() {
|
|
if (this.error) this.error = ''
|
|
},
|
|
},
|
|
beforeDestroy() {
|
|
this.$recaptcha.destroy()
|
|
},
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
.full-h {
|
|
min-height: 90vh;
|
|
}
|
|
|
|
form {
|
|
width: 25rem;
|
|
}
|
|
</style>
|