From 61c48b04f35481bbfa5a575406e79e4cee345b01 Mon Sep 17 00:00:00 2001 From: marcorv6 Date: Mon, 9 May 2022 22:01:09 -0500 Subject: [PATCH] admin listo --- pages/Admin/index.vue | 55 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/pages/Admin/index.vue b/pages/Admin/index.vue index 911f2bc..e3177ac 100644 --- a/pages/Admin/index.vue +++ b/pages/Admin/index.vue @@ -3,7 +3,7 @@

Reportes administrador

-

Subir base de datos de los profesores:

+

Subir base de datos de los profesores:

+

Descargar base de datos invitados:

import JsonCSV from 'vue-json-csv' import axios from 'axios' -import sweetalert2 from 'sweetalert2'; +import sweetalert2 from 'sweetalert2' export default { components: { @@ -71,20 +72,54 @@ export default { confirmarEnviar() { this.$swal({ title: '¿Estás seguro de querer enviar este archivo?', - type: "question", + type: 'question', timer: 9000, showCancelButton: true, - cancelButtonColor: "#d33", - confirmButtonText: "Aceptar", - confirmButtonColor: "#1e3c70", - }).then(res => { - if(res.value){ + cancelButtonColor: '#d33', + confirmButtonText: 'Aceptar', + confirmButtonColor: '#1e3c70', + }).then((res) => { + if (res.value) { this.enviar() } }) }, - enviar(){ - console.log("Se han enviado los datos") + enviar() { + const formData = new FormData() + + this.isLoading = true + formData.append('file', this.csv) + + axios + .post(`${process.env.api}/profesor/cargarDatos`, formData) + .then((res) => { + this.isLoading = false + this.csv = {} + this.successUpload() + }).catch(err => { + this.isLoading = false + this.csv = {} + console.log(err) + this.errorMessage() + }) + }, + successUpload() { + this.$swal({ + title: 'Se ha subido el archivo con éxito.', + type: 'success', + timer: 5000, + confirmButtonText: 'Aceptar', + confirmButtonColor: '#1e3c70', + }) + }, + errorMessage(){ + this.$swal({ + title: 'Ha ocurrido un error al subir el archivo.', + type: 'error', + timer: 5000, + confirmButtonText: 'Aceptar', + confirmButtonColor: '#1e3c70', + }) }, isDataExport() { if (this.dataExport.length > 0) return true