116 lines
3.6 KiB
JavaScript
116 lines
3.6 KiB
JavaScript
|
|
// Função para verificar o ambiente do usuário
|
|
async function verificarAmbiente() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const { response } = await Autenticao(); // Recebe o objeto com response e apiUrl
|
|
const data = await response.json(); // Faz o parse do JSON retornado
|
|
|
|
// Verifica se data.usuario.nome existe
|
|
const nameuser = data?.usuario?.nome;
|
|
|
|
const main = document.getElementById("entrada_1");
|
|
const tela_laod = document.getElementById('entrada_2');
|
|
|
|
let elemento_1;
|
|
let elemento_2;
|
|
|
|
if (main.innerHTML.trim() === "") {
|
|
// Verificação para saber se o nome existe
|
|
if (nameuser) {
|
|
elemento_1 = 'Seja bem-vindo, ' + nameuser; // Se o nome estiver disponível
|
|
} else {
|
|
elemento_1 = 'Carregando....'; // Caso o nome seja nulo ou indefinido
|
|
}
|
|
}
|
|
|
|
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 interval = setInterval(() => {
|
|
const tela_laod = document.getElementById('entrada_2');
|
|
const carregou = localStorage.getItem('Carregou');
|
|
|
|
if (carregou === 'true') {
|
|
tela_laod.innerHTML = ''; // Limpa o conteúdo do elemento
|
|
localStorage.removeItem('Carregou'); // Remove o item do localStorage
|
|
clearInterval(interval); // Para de verificar
|
|
}
|
|
}, 3500); // Verifica a cada 500ms
|
|
}
|
|
|
|
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);
|