341 lines
11 KiB
JavaScript
341 lines
11 KiB
JavaScript
|
|
|
|
|
|
// Função para obter a URL base da API
|
|
async function getApiUrl() {
|
|
try {
|
|
const response = await fetch('../../../Sites/Site_ItGuys/php/config_url.php'); // Solicita a URL base do PHP
|
|
if (!response.ok) {
|
|
throw new Error('Network response was not ok');
|
|
}
|
|
const data = await response.json();
|
|
return data.apiUrl; // Retorna a URL base
|
|
} 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');
|
|
}
|
|
|
|
|
|
const Permissoes = {
|
|
visuMonitor: true,
|
|
};
|
|
|
|
|
|
|
|
// Função para carregar uma imagem protegida com token JWT e exibi-la
|
|
|
|
// Função para carregar e exibir as imagens protegidas
|
|
async function criarBlocos() {
|
|
try {
|
|
const apiUrl = await getApiUrl(); // Obtém a URL da API a partir do PHP
|
|
const token = getAuthToken(); // Obtém o token JWT do localStorage
|
|
|
|
// Faz uma requisição para obter os dados da rota /mounting
|
|
const response = await fetch(`${apiUrl}/mounting`, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'x-access-token': token ? token : ''
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Erro na requisição: ' + response.statusText);
|
|
|
|
}
|
|
|
|
const data = await response.json();
|
|
|
|
// Agora acessa as propriedades do objeto
|
|
const nomeCompleto = data.usuario.nome; // Nome completo do usuário
|
|
const primeiroNome = nomeCompleto.split(' ')[0].substring(0, 10); // Pega o primeiro nome e limita a 10 caracteres // Limita a 10 caracteres;
|
|
const Empresa = data.empresa.nome;
|
|
const ImagemUser = `${apiUrl}${data.usuario.img_perfil}`;
|
|
//const ImagemUser2 = `${apiUrl}${data.usuario.img_perfil}`;
|
|
const logoEmpresa = `${apiUrl}${data.empresa.logo}`;
|
|
|
|
|
|
|
|
|
|
// Exibe as imagens protegidas usando os URLs retornados pela API
|
|
loadImage(ImagemUser, 'profileImage');
|
|
//loadImage(ImagemUser2, 'profileImage'); // Imagem de perfil do usuário
|
|
loadImage(logoEmpresa, 'companyLogo'); // Logo da empresa
|
|
|
|
// Acessando o primeiro objeto do array retornado
|
|
|
|
console.log(data);
|
|
console.log(primeiroNome);
|
|
console.log(Empresa);
|
|
console.log(ImagemUser);
|
|
console.log(logoEmpresa);
|
|
|
|
|
|
//var visuMonitor = usuarioInfo.Permissoes_Monitor;
|
|
|
|
|
|
//constante que controla o estilo css que está estilizando todo o ambiente do usuário.
|
|
const estilos = document.getElementById('conexao');
|
|
estilos.href = './Css/global/Estrutura.css';
|
|
|
|
|
|
const construtor_primario = document.getElementById('entrada_1');
|
|
|
|
construtor_primario.innerHTML =
|
|
'<section class="menu">'
|
|
+
|
|
'<header class="cabecario_1">'
|
|
+
|
|
'<div class="Bloco_subcab1_1"><img alt="" class="icon_subcab1_1 companyLogo"></div>'
|
|
+
|
|
'<div class="Bloco_subcab1_2"><a href="https://dev.itguys.com.br/"><button>Logout</button></a></div>'
|
|
+
|
|
'</header>'
|
|
+
|
|
'</section>'
|
|
+
|
|
'<main class="matriz">'
|
|
+
|
|
'<section class="capitulo_1">'
|
|
+
|
|
'<div class="Corpo_1">'
|
|
+
|
|
'<div class="Colunas_1">'
|
|
+
|
|
'<div class="seguimentos_1"><button><img id="menu" src="../Acessts/Imagens/Iconis/seta-direita.png" alt=""></button></div>'
|
|
+
|
|
'<div class="seguimentos_2">'
|
|
+
|
|
'<div class="user_1">'
|
|
+
|
|
'<img alt="" class="icon_subcab2_2 profileImage">'
|
|
+
|
|
'<img alt="" class="icon_subcab2_1 profileImage">'
|
|
+
|
|
'</div>'
|
|
+
|
|
'<div class="user_2"><p> <div id="User">' + primeiroNome + '</div><div id="Empresa">' + Empresa + '</div></p></div>'
|
|
+
|
|
'</div>'
|
|
+
|
|
'</div>'
|
|
+
|
|
'<div class="Colunas_2">'
|
|
+
|
|
'<div class="seguimentos_1"></div>'
|
|
+
|
|
'<div class="seguimentos_2"><div class="sessao_1"><a href="./Home.html" target="frame">'
|
|
+
|
|
'<div class="item_menu"><img src="../Acessts/Imagens/Iconis/home.png" alt=""><p>Home</p></div></a>'
|
|
+
|
|
'<section class="forg">'
|
|
+
|
|
//Estrutura vaizia dedicada para aparesentação do painel de monitoramento caso o usuário tenha permissão para o visualizar.
|
|
'<div id="sub_entrada"></div>'
|
|
+
|
|
'</section>'
|
|
+
|
|
'<a href="http://10.10.253.111/"><div class="item_menu"><img src="../Acessts/Imagens/Iconis/technical-support.png" alt=""><p>Servicedesk</p></div></a>'
|
|
+
|
|
'</div>'
|
|
+
|
|
'<div class="sessao_2">'
|
|
+
|
|
'<a href="https://api.whatsapp.com/send?phone=5521966344698"><div class="item_menu"><img src="../Acessts/Imagens/Iconis/central-de-atendimento.png" alt=""><p>Suporte</p></div></a>'
|
|
+
|
|
'<a href="./Config.html" ><div class="item_menu"><img src="../Acessts/Imagens/Iconis/engrenagem - Copia.png" alt=""><p>Configuracões</p></div></a>'
|
|
+
|
|
' </div>'
|
|
+
|
|
'</section>'
|
|
+
|
|
'<section class="capitulo_2">'
|
|
+
|
|
'<div class="Corpo_2">'
|
|
+
|
|
'<div class="Colunas_1"><iframe id = "test1" name = "frame" class="transmissão" src = "./Home.html"frameborder = "0" ></iframe ></div>'
|
|
+
|
|
'</div>'
|
|
+
|
|
'</main>'
|
|
;
|
|
|
|
|
|
|
|
|
|
//Construtores responsavels sobre a construção de alguns scripts que não são default, que só atendem o ambiente do usuário.
|
|
|
|
//construtor da reação do menu sobre as interações do usuário
|
|
const script1 = document.createElement('script');
|
|
script1.src = './js/Ambiente/Estrutura/Reacao_menu.js';
|
|
document.body.appendChild(script1);
|
|
|
|
|
|
if (Permissoes.visuMonitor) {
|
|
const script2 = document.createElement('script');
|
|
script2.src = './js/Ambiente/Monitoramento/Estrutura_Secundaria_Monitor.js';
|
|
script2.setAttribute // Acessando a propriedade corretamente
|
|
document.body.appendChild(script2);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
//Constante de controle sobre estilos css do painel de erro.
|
|
const estilos = document.getElementById('conexao');
|
|
estilos.href = '../Css/page/Telas_acao/erro_404.css';
|
|
|
|
//variaveis de conexão de informações, possuindo informações algumas informaçõe sendo elas:
|
|
//o Status do erro
|
|
//Mensagem do erro
|
|
//Um mensagem complementar sobre o erro
|
|
var Status = 'Erro 404';
|
|
var mensagem = 'Desculpe mas sua página não foi encontrada';
|
|
var sub_mensagem = 'Tente fazer seu, login novamente';
|
|
|
|
//Constante usada para a criação da estrutura, sendo usada para apresentar todo o painel
|
|
const erro = document.getElementById('entrada_1');
|
|
|
|
erro.innerHTML = '<section class="matriz_404" id="cap">'
|
|
+
|
|
'<section class="paineis_1"><div class="cap"><h1>' + Status + '</h1></div></section>'
|
|
+
|
|
'<section class="paineis_2">'
|
|
+
|
|
'<div class="cap"><h2>' + mensagem + '</h2><p>' + sub_mensagem + '</p></div>'
|
|
+
|
|
'<div class="cap_2"><a href="/Sites/Site_ItGuys/ambiente_do_usu%C3%A1rio/login.html"><button>Retornar</button></a></div>'
|
|
+
|
|
'</section>'
|
|
+
|
|
'<div class="wave wave_1"></div>'
|
|
+
|
|
'<div class="wave wave_2"></div>'
|
|
+
|
|
'<div class="wave wave_3"></div>'
|
|
+
|
|
'<div class="wave wave_4"></div>'
|
|
+
|
|
'</section>'
|
|
;
|
|
|
|
|
|
|
|
|
|
console.error('Erro ao criar blocos:', error);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Função para carregar uma imagem protegida com token JWT e exibi-la
|
|
|
|
async function loadImage(url, imgElementClass) {
|
|
try {
|
|
const token = getAuthToken();
|
|
console.log('Token:', token);
|
|
console.log('URL da imagem:', url);
|
|
|
|
const response = await fetch(url, {
|
|
method: 'GET',
|
|
headers: {
|
|
'x-access-token': token ? token : ''
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Erro ao carregar a imagem: ' + response.statusText);
|
|
}
|
|
|
|
const blob = await response.blob();
|
|
const imageUrl = URL.createObjectURL(blob);
|
|
|
|
// Seleciona todos os elementos com a classe
|
|
const imgElements = document.getElementsByClassName(imgElementClass);
|
|
if (imgElements.length > 0) {
|
|
for (let i = 0; i < imgElements.length; i++) {
|
|
imgElements[i].src = imageUrl;
|
|
}
|
|
} else {
|
|
console.warn('Nenhum elemento encontrado com a classe:', imgElementClass);
|
|
}
|
|
|
|
return imageUrl; // Retorna a URL da imagem carregada
|
|
} catch (error) {
|
|
console.error('Erro ao carregar a imagem:', error);
|
|
console.log('Classe do elemento:', imgElementClass);
|
|
return null; // Retorna null em caso de erro
|
|
}
|
|
}
|
|
// Função para carregar a imagem de fundo
|
|
async function loadBackgroundAndUpdateStyle() {
|
|
try {
|
|
const apiUrl = await getApiUrl();
|
|
const token = getAuthToken();
|
|
const response = await fetch(`${apiUrl}/mounting`, {
|
|
method: 'GET',
|
|
headers: {
|
|
'x-access-token': token ? token : ''
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Erro ao carregar os dados: ' + response.statusText);
|
|
}
|
|
|
|
const data = await response.json();
|
|
const imagemFun = `${apiUrl}${data.usuario.img_fundo}`;
|
|
|
|
const fundoResponse = await fetch(imagemFun, {
|
|
method: 'GET',
|
|
headers: {
|
|
'x-access-token': token ? token : ''
|
|
}
|
|
});
|
|
|
|
if (!fundoResponse.ok) {
|
|
throw new Error('Erro ao carregar a imagem de fundo: ' + fundoResponse.statusText);
|
|
}
|
|
|
|
const blob = await fundoResponse.blob();
|
|
const fundoUserUrl = URL.createObjectURL(blob);
|
|
|
|
const fundouser = document.getElementById('fundouser');
|
|
fundouser.innerHTML =
|
|
'.Corpo_1 .Colunas_1 {' +
|
|
'display: flex;' +
|
|
'flex-direction: row;' +
|
|
'background-image: url("' + fundoUserUrl + '");' +
|
|
'background-position: center;' +
|
|
'background-size: cover;' +
|
|
'width: 15vw;' +
|
|
'height: 10vh;' +
|
|
'overflow: hidden;' +
|
|
'transition: 1s ease;' +
|
|
'}';
|
|
|
|
console.log('Imagem de fundo carregada e estilo aplicado com sucesso.');
|
|
} catch (error) {
|
|
console.error('Erro ao carregar a imagem de fundo:', error);
|
|
}
|
|
}
|
|
|
|
// Inicia o carregamento das imagens quando o script for carregado
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
await criarBlocos();
|
|
await loadBackgroundAndUpdateStyle();
|
|
});
|