lilnoru/optitrack-vision-vault
0
1// Sistema de almacenamiento local simplificado2class OptiStore {3 static get(key) {4 const data = localStorage.getItem(`optitrack_${key}`);5 return data ? JSON.parse(data) : null;6 }7 8 static set(key, value) {9 localStorage.setItem(`optitrack_${key}`, JSON.stringify(value));10 }11 12 static clear() {13 localStorage.clear();14 }15}16 17// Inicialización de datos de ejemplo si no existen18document.addEventListener('DOMContentLoaded', () => {19 if (!OptiStore.get('inventario')) {20 OptiStore.set('inventario', [21 { id: 1, nombre: "Lentes Ray-Ban", categoria: "Gafas de sol", stock: 15, precio: 1200 },22 { id: 2, nombre: "Lentes Transition", categoria: "Lentes oftálmicos", stock: 8, precio: 1800 },23 { id: 3, nombre: "Estuche para lentes", categoria: "Accesorios", stock: 25, precio: 150 }24 ]);25 }26 27 if (!OptiStore.get('clientes')) {28 OptiStore.set('clientes', [29 { id: 1, nombre: "Juan Pérez", telefono: "5551234567", email: "juan@example.com" },30 { id: 2, nombre: "María García", telefono: "5557654321", email: "maria@example.com" }31 ]);32 }33 34 if (!OptiStore.get('ventas')) {35 OptiStore.set('ventas', [36 { id: 1, cliente: 1, productos: [1, 3], total: 1350, fecha: "2023-05-15" },37 { id: 2, cliente: 2, productos: [2], total: 1800, fecha: "2023-05-16" }38 ]);39 }40});41 42// Funciones de utilidad43function mostrarAlerta(mensaje, tipo = 'success') {44 const alerta = document.createElement('div');45 alerta.className = `fixed top-4 right-4 px-6 py-4 rounded-lg shadow-lg text-white ${46 tipo === 'success' ? 'bg-green-500' : 'bg-red-500'47 }`;48 alerta.textContent = mensaje;49 document.body.appendChild(alerta);50 51 setTimeout(() => {52 alerta.remove();53 }, 3000);54}