pcpuma_unam_operador/plugins/inject.js

116 lines
2.3 KiB
JavaScript
Raw Normal View History

2022-07-11 01:06:30 +00:00
const alertsGenericos = {
imprimirError(
buefy,
err = {},
title = '¡Hubo un error!',
onConfirm = () => {}
) {
buefy.dialog.alert({
ariaModal: true,
hasIcon: true,
onConfirm,
ariaRole: 'alertdialog',
confirmText: 'Entendido',
icon: 'alert-octagon',
iconPack: 'mdi',
message: err.message,
title,
type: 'is-danger',
})
// if (err.err && err.err === 'token error') {
// localStorage.clear()
// this.$router.push('/')
// }
},
imprimirMensaje(
buefy,
message,
onConfirm = () => {},
title = '¡Felicidades!'
) {
buefy.dialog.alert({
ariaModal: true,
hasIcon: true,
onConfirm,
ariaRole: 'alertdialog',
confirmText: 'Ok',
icon: 'check-circle',
iconPack: 'mdi',
message,
title,
type: 'is-success',
})
},
imprimirWarning(
buefy,
message,
onConfirm = () => {},
title = '¡Espera un minuto!',
onCancel = () => {}
) {
buefy.dialog.alert({
ariaModal: true,
canCancel: true,
hasIcon: true,
onCancel,
onConfirm,
ariaRole: 'alertdialog',
cancelText: 'Cancelar',
confirmText: 'Confirmar',
icon: 'help-circle',
iconPack: 'mdi',
message,
title,
type: 'is-warning',
})
},
}
2022-07-19 16:41:33 +00:00
const getToken = {
token() {
const token = this.tokenStr()
if (!token) return null
return {
headers: {
Authorization: `Bearer ${token}`,
},
}
},
tokenStr() {
return localStorage.getItem('token')
},
tokenFile() {
const token = this.tokenStr()
if (!token) return null
return {
headers: {
'Content-Type': 'multipart/form-data',
Authorization: `Bearer ${token}`,
},
}
},
}
2022-07-20 05:01:20 +00:00
const funcionesGlobales = {
objIsEmpty(obj) {
for (let key in obj) if (obj.hasOwnProperty(key)) return false
return true
},
activo(ruta) {
console.log('hola')
const location = window.location.pathname
if (location[location.length - 1]) location.slice(0, -1)
return ruta === location
},
icono(ruta) {
return this.activo(ruta) ? 'square' : 'crop-square'
},
2022-07-19 16:41:33 +00:00
}
2022-07-11 01:06:30 +00:00
export default ({ app }, inject) => {
inject('alertsGenericos', alertsGenericos)
2022-07-19 16:41:33 +00:00
inject('getToken', getToken)
2022-07-20 05:01:20 +00:00
inject('funcionesGlobales', funcionesGlobales)
2022-07-11 01:06:30 +00:00
}