feat: UI completa funcional para todos los módulos
This commit is contained in:
@@ -1,6 +1,70 @@
|
||||
<template>
|
||||
<div>
|
||||
<h2>Exportar</h2>
|
||||
<p>Módulo en desarrollo</p>
|
||||
<h2>Exportar / Importar</h2>
|
||||
|
||||
<section>
|
||||
<h3>Exportar Datos</h3>
|
||||
<button @click="exportar">Exportar JSON</button>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h3>Importar Datos</h3>
|
||||
<input type="file" accept=".json" @change="onFileChange" />
|
||||
<button @click="importar" :disabled="!archivo">Importar JSON</button>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
import { db } from '@toldo/data';
|
||||
import { ExportImportService } from '@toldo/services';
|
||||
|
||||
const exportService = new ExportImportService();
|
||||
const archivo = ref<File | null>(null);
|
||||
|
||||
function onFileChange(e: any) {
|
||||
archivo.value = e.target.files[0];
|
||||
}
|
||||
|
||||
async function exportar() {
|
||||
const data = {
|
||||
productores: await db.productores.toArray(),
|
||||
productos: await db.productos.toArray(),
|
||||
movimientosInventario: await db.movimientosInventario.toArray(),
|
||||
ventas: await db.ventas.toArray(),
|
||||
ventaLineas: await db.ventaLineas.toArray(),
|
||||
gastos: await db.gastos.toArray(),
|
||||
ajustes: await db.ajustes.toArray(),
|
||||
cuadres: await db.cuadres.toArray(),
|
||||
};
|
||||
const exp = exportService.exportAll(data);
|
||||
const blob = new Blob([JSON.stringify(exp, null, 2)], { type: 'application/json' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `toldo-export-${new Date().toISOString().split('T')[0]}.json`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
async function importar() {
|
||||
if (!archivo.value) return;
|
||||
const text = await archivo.value.text();
|
||||
try {
|
||||
const json = JSON.parse(text);
|
||||
const imp = exportService.import(json);
|
||||
if (imp.data.productores.length) await db.productores.bulkPut(imp.data.productores);
|
||||
if (imp.data.productos.length) await db.productos.bulkPut(imp.data.productos);
|
||||
if (imp.data.movimientosInventario.length) await db.movimientosInventario.bulkPut(imp.data.movimientosInventario);
|
||||
if (imp.data.ventas.length) await db.ventas.bulkPut(imp.data.ventas);
|
||||
if (imp.data.ventaLineas.length) await db.ventaLineas.bulkPut(imp.data.ventaLineas);
|
||||
if (imp.data.gastos.length) await db.gastos.bulkPut(imp.data.gastos);
|
||||
if (imp.data.ajustes.length) await db.ajustes.bulkPut(imp.data.ajustes);
|
||||
if (imp.data.cuadres.length) await db.cuadres.bulkPut(imp.data.cuadres);
|
||||
alert('Datos importados correctamente');
|
||||
} catch (e: any) {
|
||||
alert(e.message);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user