const alertsGenericos = { imprimirError( buefy, router, err = {}, title = '¡Hubo un error!', onConfirm = () => {} ) { if (err.message === 'Unauthorized') { buefy.dialog.alert({ ariaModal: true, hasIcon: true, onConfirm, ariaRole: 'alertdialog', confirmText: 'Entendido', icon: 'alert-octagon', iconPack: 'mdi', message: 'Tu sesión se terminó. Si deseas continuar logueate nuevamente.', title, type: 'is-danger', }) localStorage.clear() router.push('/') } else { buefy.dialog.alert({ ariaModal: true, hasIcon: true, onConfirm, ariaRole: 'alertdialog', confirmText: 'Entendido', icon: 'alert-octagon', iconPack: 'mdi', message: err.message, title, type: 'is-danger', }) } }, 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', }) }, } const getToken = { token() { const token = this.tokenStr() if (!token) return null return { headers: { Authorization: `Bearer ${token}`, }, } }, tokenDelete(data) { const token = this.tokenStr() if (!token) return null return { headers: { Authorization: `Bearer ${token}`, }, data, } }, tokenStr() { return localStorage.getItem('token') }, tokenFile() { const token = this.tokenStr() if (!token) return null return { headers: { 'Content-Type': 'multipart/form-data', Authorization: `Bearer ${token}`, }, } }, } const funcionesGlobales = { objIsEmpty(obj) { for (let key in obj) if (obj.hasOwnProperty(key)) return false return true }, activo(ruta) { 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' }, } export default ({ app }, inject) => { inject('alertsGenericos', alertsGenericos) inject('getToken', getToken) inject('funcionesGlobales', funcionesGlobales) }