Actualizar js/layout.js
This commit is contained in:
84
js/layout.js
84
js/layout.js
@@ -4,43 +4,61 @@
|
||||
... */
|
||||
|
||||
// ==========================================
|
||||
// RASTREADOR FANTASMA GPS (MODO DE CAMINO)
|
||||
// 🎨 INYECTOR DE LOGO CORPORATIVO Y PWA (ICONOS APP)
|
||||
// ==========================================
|
||||
setInterval(async () => {
|
||||
if (!localStorage.getItem("token") || localStorage.getItem("role") !== "operario") return;
|
||||
setTimeout(async () => {
|
||||
if (!localStorage.getItem("token")) return;
|
||||
|
||||
const TRACK_API = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
|
||||
? 'http://localhost:3000'
|
||||
: 'https://integrarepara-api.integrarepara.es';
|
||||
|
||||
try {
|
||||
const resSt = await fetch(`${TRACK_API}/statuses`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||
const dataSt = await resSt.json();
|
||||
if (!dataSt.ok) return;
|
||||
const TRACK_API = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
|
||||
? 'http://localhost:3000'
|
||||
: 'https://integrarepara-api.integrarepara.es';
|
||||
|
||||
const res = await fetch(`${TRACK_API}/config/company`, {
|
||||
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
const caminoSt = dataSt.statuses.find(s => s.name.toLowerCase().includes('camino'));
|
||||
if (!caminoSt) return;
|
||||
if (data.ok && data.config && data.config.company_logo) {
|
||||
const logoUrl = data.config.company_logo;
|
||||
|
||||
const resSvc = await fetch(`${TRACK_API}/services/active`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||
const dataSvc = await resSvc.json();
|
||||
if (!dataSvc.ok) return;
|
||||
|
||||
const enRuta = dataSvc.services.filter(s => String(s.raw_data?.status_operativo) === String(caminoSt.id));
|
||||
|
||||
if (enRuta.length > 0) {
|
||||
// Alta velocidad activada (enableHighAccuracy: false)
|
||||
navigator.geolocation.getCurrentPosition(async (pos) => {
|
||||
const lat = pos.coords.latitude;
|
||||
const lng = pos.coords.longitude;
|
||||
// 1. INYECTAR EN LA CABECERA (Reemplaza la letra naranja por el logo)
|
||||
const headerIcon = document.querySelector('header .w-10.h-10.rounded-xl, #header-container .w-10.h-10');
|
||||
if (headerIcon) {
|
||||
headerIcon.innerHTML = '';
|
||||
headerIcon.className = "w-10 h-10 flex shrink-0 items-center justify-center";
|
||||
headerIcon.style.background = "transparent";
|
||||
headerIcon.style.boxShadow = "none";
|
||||
|
||||
for (let s of enRuta) {
|
||||
await fetch(`${TRACK_API}/services/${s.id}/location`, {
|
||||
method: 'POST',
|
||||
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
||||
body: JSON.stringify({ lat, lng })
|
||||
});
|
||||
}
|
||||
}, () => {}, { enableHighAccuracy: false, timeout: 10000, maximumAge: 30000 });
|
||||
const img = document.createElement('img');
|
||||
img.src = logoUrl;
|
||||
img.className = "max-w-full max-h-full object-contain drop-shadow-sm";
|
||||
headerIcon.appendChild(img);
|
||||
}
|
||||
|
||||
// 2. INYECTAR ICONO DE APP (Favicon para PC y Android)
|
||||
let favicon = document.querySelector("link[rel~='icon']");
|
||||
if (!favicon) {
|
||||
favicon = document.createElement('link');
|
||||
favicon.rel = 'icon';
|
||||
document.head.appendChild(favicon);
|
||||
}
|
||||
favicon.href = logoUrl;
|
||||
|
||||
// 3. INYECTAR ICONO DE iPHONE (Apple Touch Icon)
|
||||
// Esto le dice a Safari qué foto usar si le dan a "Añadir a la pantalla de inicio"
|
||||
let appleIcon = document.querySelector("link[rel='apple-touch-icon']");
|
||||
if (!appleIcon) {
|
||||
appleIcon = document.createElement('link');
|
||||
appleIcon.rel = 'apple-touch-icon';
|
||||
document.head.appendChild(appleIcon);
|
||||
}
|
||||
appleIcon.href = logoUrl;
|
||||
}
|
||||
} catch (e) { }
|
||||
}, 15000); // Se ejecuta cada 15 segundos
|
||||
} catch (e) {
|
||||
console.error("No se pudo cargar la configuración visual de la empresa", e);
|
||||
}
|
||||
}, 300); // Pequeño retraso para dejar que el HTML se dibuje primero
|
||||
|
||||
// 🛑 RASTREADOR FANTASMA GPS (MODO DE CAMINO) DESACTIVADO TEMPORALMENTE 🛑
|
||||
// (Por petición del desarrollador, se ha eliminado el bloque setInterval del GPS)
|
||||
Reference in New Issue
Block a user