Separacion del login
This commit is contained in:
parent
a6b578e17d
commit
890d6fe7e5
@ -60,6 +60,8 @@ 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 },
|
||||
},
|
||||
@ -77,32 +79,19 @@ export default {
|
||||
methods: {
|
||||
login() {
|
||||
if (this.usuario && this.password && !this.error) {
|
||||
let tipoUsuario = ''
|
||||
let data = {}
|
||||
if (this.idModulo) {
|
||||
tipoUsuario = 'login-operador'
|
||||
data = {
|
||||
operador: this.usuario,
|
||||
password: this.password,
|
||||
id_modulo: this.idModulo,
|
||||
}
|
||||
} else {
|
||||
tipoUsuario = 'login-admin'
|
||||
data = {
|
||||
operador: this.usuario,
|
||||
password: this.password,
|
||||
}
|
||||
const data = {
|
||||
operador: this.usuario,
|
||||
password: this.password,
|
||||
id_modulo: this.idModulo,
|
||||
}
|
||||
this.updateIsLoading(true)
|
||||
axios
|
||||
.post(`${process.env.api}/auth/${tipoUsuario}`, data)
|
||||
.post(`${process.env.api}/auth/login-operador`, data)
|
||||
.then((res) => {
|
||||
const info = JSON.stringify(res.data)
|
||||
localStorage.setItem('usuario', info)
|
||||
console.log(info)
|
||||
this.updateIsLoading(false)
|
||||
this.$router.push('/operador/prestamo_devolucion')
|
||||
console.log('entramos')
|
||||
})
|
||||
.catch((err) => {
|
||||
this.error = 'is-danger'
|
||||
@ -113,7 +102,7 @@ export default {
|
||||
},
|
||||
obtenerCatalogoInstitucion() {
|
||||
axios
|
||||
.get(`${process.env.api}/institucion`)
|
||||
.get(`${process.env.api}/institucion/activas`)
|
||||
.then((res) => {
|
||||
this.instituciones = res.data
|
||||
})
|
||||
|
124
components/admin/Login.vue
Normal file
124
components/admin/Login.vue
Normal file
@ -0,0 +1,124 @@
|
||||
<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>
|
104
pages/admin/index.vue
Normal file
104
pages/admin/index.vue
Normal file
@ -0,0 +1,104 @@
|
||||
<template>
|
||||
<section class="container">
|
||||
<Login
|
||||
:imprimirMensaje="imprimirMensaje"
|
||||
:imprimirWarning="imprimirWarning"
|
||||
:imprimirError="imprimirError"
|
||||
:updateIsLoading="updateIsLoading"
|
||||
/>
|
||||
|
||||
<b-loading :is-full-page="true" v-model="isLoading" :can-cancel="false" />
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Login from '@/components/admin/Login.vue'
|
||||
|
||||
export default {
|
||||
components: { Login },
|
||||
data() {
|
||||
return {
|
||||
// admin: '',
|
||||
isLoading: false,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
updateIsLoading(booleanValue) {
|
||||
this.isLoading = booleanValue
|
||||
},
|
||||
imprimirError(err = {}, title = '¡Hubo un error!', onConfirm = () => {}) {
|
||||
this.$buefy.dialog.alert({
|
||||
ariaRole: 'alertdialog',
|
||||
ariaModal: true,
|
||||
type: 'is-danger',
|
||||
title,
|
||||
message: err.message,
|
||||
confirmText: 'Entendido',
|
||||
hasIcon: true,
|
||||
iconPack: 'mdi',
|
||||
icon: 'alert-octagon',
|
||||
onConfirm: () => onConfirm(),
|
||||
})
|
||||
if (err.err && err.err === 'token error') {
|
||||
localStorage.clear()
|
||||
this.$router.push('/')
|
||||
}
|
||||
},
|
||||
imprimirMensaje(message, title = '¡Felicidades!', onConfirm = () => {}) {
|
||||
this.$buefy.dialog.alert({
|
||||
ariaRole: 'alertdialog',
|
||||
ariaModal: true,
|
||||
type: 'is-success',
|
||||
title,
|
||||
message,
|
||||
confirmText: 'Ok',
|
||||
hasIcon: true,
|
||||
iconPack: 'mdi',
|
||||
icon: 'check-circle',
|
||||
onConfirm: () => onConfirm(),
|
||||
})
|
||||
},
|
||||
imprimirWarning(
|
||||
message,
|
||||
onConfirm = () => {},
|
||||
title = '¡Espera un minuto!',
|
||||
onCancel = () => {}
|
||||
) {
|
||||
this.$buefy.dialog.alert({
|
||||
ariaRole: 'alertdialog',
|
||||
ariaModal: true,
|
||||
type: 'is-warning',
|
||||
title,
|
||||
message,
|
||||
confirmText: 'Confirmar',
|
||||
canCancel: true,
|
||||
cancelText: 'Cancelar',
|
||||
hasIcon: true,
|
||||
iconPack: 'mdi',
|
||||
icon: 'help-circle',
|
||||
onConfirm: () => onConfirm(),
|
||||
onCancel: () => onCancel(),
|
||||
})
|
||||
},
|
||||
// getLocalhostInfo() {
|
||||
// this.admin.idUsuario = Number(localStorage.getItem('idUsuario'))
|
||||
// this.admin.idTipoUsuario = Number(localStorage.getItem('idTipoUsuario'))
|
||||
// this.admin.tipoUsuario = localStorage.getItem('tipoUsuario')
|
||||
// this.admin.token = {
|
||||
// headers: {
|
||||
// token: localStorage.getItem('token'),
|
||||
// },
|
||||
// }
|
||||
// },
|
||||
},
|
||||
created() {
|
||||
// this.getLocalhostInfo()
|
||||
// if (this.admin.idTipoUsuario === 2) this.$router.push('/responsable')
|
||||
// if (this.admin.idTipoUsuario === 3) this.$router.push('/alumno')
|
||||
// if (this.admin.idTipoUsuario === 4) this.$router.push('/casoEspecial')
|
||||
},
|
||||
layout: 'login',
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
Loading…
Reference in New Issue
Block a user