pcpuma_unam_operador/plugins/inject.js

123 lines
2.4 KiB
JavaScript
Raw Permalink Normal View History

2022-07-11 01:06:30 +00:00
const alertsGenericos = {
imprimirError(
buefy,
2022-08-05 23:41:37 +00:00
router,
2022-07-11 01:06:30 +00:00
err = {},
title = '¡Hubo un error!',
onConfirm = () => {}
) {
2022-08-08 02:08:22 +00:00
let mensaje = ''
if (err.message === 'Unauthorized')
mensaje = 'Tu sesión se terminó. Si deseas continuar logueate nuevamente.'
else mensaje = err.message
buefy.dialog.alert({
ariaModal: true,
hasIcon: true,
onConfirm,
ariaRole: 'alertdialog',
confirmText: 'Entendido',
icon: 'alert-octagon',
iconPack: 'mdi',
message: mensaje,
title,
type: 'is-danger',
})
2022-08-05 23:41:37 +00:00
if (err.message === 'Unauthorized') {
localStorage.clear()
router.push('/')
}
2022-07-11 01:06:30 +00:00
},
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,
2023-05-30 21:58:01 +00:00
canCancel: ["button"],
2022-07-11 01:06:30 +00:00
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}`,
},
}
},
2022-07-22 03:17:53 +00:00
tokenDelete(data) {
const token = this.tokenStr()
if (!token) return null
return {
headers: {
Authorization: `Bearer ${token}`,
},
data,
}
},
2022-07-19 16:41:33 +00:00
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
},
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
}