142 lines
4.4 KiB
JavaScript
142 lines
4.4 KiB
JavaScript
async function respostaServer() {
|
|
// Função para obter a URL base da API
|
|
async function getApiUrl() {
|
|
try {
|
|
const response = await fetch('../../../Sites/Site_ItGuys/php/config_url.php');
|
|
if (!response.ok) {
|
|
throw new Error('Network response was not ok');
|
|
}
|
|
const data = await response.json();
|
|
return data.apiUrl;
|
|
} catch (error) {
|
|
console.error('Error fetching API URL:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
// Função para obter o token do localStorage
|
|
function getAuthToken() {
|
|
return localStorage.getItem('x-access-token');
|
|
}
|
|
|
|
// Obtenha a URL da API e o token
|
|
const apiUrl = await getApiUrl();
|
|
const token = getAuthToken();
|
|
|
|
return { apiUrl, token }; // Retorne os valores
|
|
}
|
|
|
|
// Função para verificar o ambiente do usuário
|
|
async function verificarAmbiente() {
|
|
try {
|
|
const { apiUrl, token } = await respostaServer(); // Desestruture a resposta
|
|
|
|
const response = await fetch(`${apiUrl}/mounting`, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'x-access-token': token || '' // Use um fallback para token
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Erro na requisição: ' + response.statusText);
|
|
}
|
|
|
|
const data = await response.json();
|
|
const nameuser = data.usuario.nome || 'Visitante'; // Fallback caso o nome não esteja definido
|
|
const primeiroNomeuser = nameuser.split(' ')[0].substring(0, 10);
|
|
|
|
const main = document.getElementById("entrada_1");
|
|
const tela_laod = document.getElementById('entrada_2');
|
|
|
|
let elemento_1;
|
|
let elemento_2;
|
|
|
|
if (main.innerHTML.trim() === "") {
|
|
elemento_1 = 'Estamos carregando sua página';
|
|
} else {
|
|
elemento_1 = 'Seja bem-vindo, ' + primeiroNomeuser; // Corrigido para concatenar corretamente
|
|
}
|
|
|
|
elemento_2 = '<canvas id="animationCanvas"></canvas>';
|
|
tela_laod.innerHTML = '<div class="teste"><h1>' + elemento_1 + '</h1>' + elemento_2 + '</div>';
|
|
|
|
// Inicia a animação após configurar o canvas
|
|
iniciarAnimacao();
|
|
|
|
// Inicia a contagem para limpar a tela após 3 segundos
|
|
finalizar();
|
|
} catch (error) {
|
|
console.error('Erro ao verificar o ambiente:', error);
|
|
}
|
|
}
|
|
|
|
function finalizar() {
|
|
const tela_laod = document.getElementById('entrada_2');
|
|
setTimeout(() => {
|
|
tela_laod.innerHTML = '';
|
|
}, 3000);
|
|
}
|
|
|
|
function iniciarAnimacao() {
|
|
const canvas = document.getElementById('animationCanvas');
|
|
const ctx = canvas.getContext('2d');
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
|
|
const circle = {
|
|
centerX: canvas.width / 2,
|
|
centerY: canvas.height / 2,
|
|
radius: 150,
|
|
rotationSpeed: 0.10,
|
|
angle: 0,
|
|
linePath: [],
|
|
maxPathLength: 350
|
|
};
|
|
|
|
function drawCircularPath() {
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
const pathX = circle.centerX + circle.radius * Math.cos(circle.angle);
|
|
const pathY = circle.centerY + circle.radius * Math.sin(circle.angle);
|
|
circle.linePath.push({ x: pathX, y: pathY });
|
|
|
|
ctx.beginPath();
|
|
circle.linePath.forEach((point, i) => {
|
|
if (i > 0) {
|
|
ctx.moveTo(circle.linePath[i - 1].x, circle.linePath[i - 1].y);
|
|
ctx.lineTo(point.x, point.y);
|
|
}
|
|
});
|
|
ctx.strokeStyle = '#22c0a3';
|
|
ctx.lineWidth = 10;
|
|
ctx.stroke();
|
|
|
|
if (circle.linePath.length > circle.maxPathLength) {
|
|
circle.linePath.shift();
|
|
if (circle.angle >= Math.PI * 2) {
|
|
circle.angle = 0;
|
|
circle.linePath = [];
|
|
}
|
|
}
|
|
}
|
|
|
|
function animate() {
|
|
circle.angle += circle.rotationSpeed;
|
|
drawCircularPath();
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
animate();
|
|
|
|
window.addEventListener('resize', () => {
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
circle.centerX = canvas.width / 2;
|
|
circle.centerY = canvas.height / 2;
|
|
});
|
|
}
|
|
|
|
// Executa verificarAmbiente apenas uma vez após o carregamento total da página
|
|
window.addEventListener('load', verificarAmbiente);
|