add cadastro
This commit is contained in:
183
main.js
Executable file
183
main.js
Executable file
@@ -0,0 +1,183 @@
|
||||
// main.js
|
||||
|
||||
// Garantir que CookieManager está disponível
|
||||
if (typeof CookieManager === 'undefined') {
|
||||
console.error('CookieManager não encontrado. Verifique se cookie.js está incluído.');
|
||||
}
|
||||
|
||||
// // Garantir que PhoneMask está disponível
|
||||
// if (typeof PhoneMask === 'undefined') {
|
||||
// console.error('PhoneMask não encontrado. Verifique se mask.js está incluído.');
|
||||
// }
|
||||
|
||||
// cheque se existe form no body
|
||||
try {
|
||||
var currApp = document.body.getAttribute('app')
|
||||
} catch (error) {
|
||||
var currApp = null
|
||||
}
|
||||
|
||||
if (currApp == 'form') {
|
||||
|
||||
// Aguarda o carregamento completo do DOM
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
// Função para obter um item aleatório de um array
|
||||
function getRandomItem(array) {
|
||||
return array[Math.floor(Math.random() * array.length)];
|
||||
}
|
||||
|
||||
// Função para gerar um número de telefone aleatório
|
||||
function getRandomPhone() {
|
||||
let ddd = ["11", "21", "31", "41", "51", "61", "71", "81", "91"];
|
||||
let prefixo = Math.floor(90000 + Math.random() * 10000);
|
||||
let sufixo = Math.floor(1000 + Math.random() * 9000);
|
||||
return `(${getRandomItem(ddd)}) ${prefixo}-${sufixo}`;
|
||||
}
|
||||
|
||||
// Arrays com dados fictícios
|
||||
const nomes = ["Carlos Silva", "Ana Pereira", "João Souza", "Mariana Lima", "Felipe Alves"];
|
||||
const empresas = ["TechCorp", "InovaWeb", "BrasilSoft", "SmartSolutions", "EcoTech"];
|
||||
const cargos = ["Analista", "Gerente", "Coordenador", "Desenvolvedor", "Consultor"];
|
||||
|
||||
// // Preenche os campos do formulário com dados aleatórios
|
||||
// document.querySelector('[name="nome"]').value = getRandomItem(nomes);
|
||||
// document.querySelector('[name="empresa"]').value = getRandomItem(empresas);
|
||||
// document.querySelector('[name="cargo"]').value = getRandomItem(cargos);
|
||||
// document.querySelector('[name="telefone"]').value = getRandomPhone();
|
||||
// document.querySelector('[name="cliente_xcmg"]').checked = Math.random() > 0.5;
|
||||
// document.querySelector('[name="usa_banco_xcmg"]').checked = Math.random() > 0.5;
|
||||
});
|
||||
|
||||
// Função para aplicar a máscara de telefone
|
||||
function maskPhone(element) {
|
||||
PhoneMask.apply(element);
|
||||
|
||||
element.addEventListener("input", function () {
|
||||
var phone = this.value.replace(/\D/g, '');
|
||||
if (phone.length < 10 || phone.length > 11) {
|
||||
this.setCustomValidity('Telefone inválido');
|
||||
} else {
|
||||
this.setCustomValidity('');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Aplica a máscara ao campo de telefone após o carregamento do DOM
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var phoneInput = document.getElementById('telefone');
|
||||
maskPhone(phoneInput);
|
||||
});
|
||||
|
||||
// Validação do formulário antes do envio
|
||||
document.getElementById('registrationForm').addEventListener('submit', function (e) {
|
||||
var phoneInput = document.getElementById('telefone');
|
||||
var phone = phoneInput.value.replace(/\D/g, '');
|
||||
|
||||
if (phone.length < 10 || phone.length > 11) {
|
||||
e.preventDefault();
|
||||
alert('Por favor, insira um número de telefone válido (DDD + número)');
|
||||
}
|
||||
});
|
||||
// Salva o cookie após o envio do formulário (quando o cadastro for completado)
|
||||
// document.getElementById('registrationForm').addEventListener('submit', function (e) {
|
||||
// e.preventDefault(); // Impede o envio padrão do formulário
|
||||
|
||||
// // Supondo que a validação do formulário foi bem-sucedida
|
||||
// setCadastroCookie();
|
||||
|
||||
// // Redireciona para play.php após salvar o cookie
|
||||
// window.location.href = "salvar.php";
|
||||
// });
|
||||
}
|
||||
|
||||
// Função para embaralhar um código
|
||||
function embaralharCodigo(codigo) {
|
||||
const alpha = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
|
||||
// Embaralha a ordem dos caracteres
|
||||
let embaralhado = codigo.split('').map((char, index) => {
|
||||
if (index % 2 === 0) {
|
||||
let charIndex = alpha.indexOf(char);
|
||||
return alpha[alpha.length - 1 - charIndex]; // Inverte o caractere de acordo com a sequência Alpha
|
||||
}
|
||||
return char; // Mantém o caractere original
|
||||
}).join('');
|
||||
|
||||
// Troca a ordem dos caracteres
|
||||
return embaralhado.split('').reverse().join('');
|
||||
}
|
||||
|
||||
// Funções de Cookie
|
||||
function setCadastroCookie() {
|
||||
// Usa CookieManager em vez de cookies
|
||||
CookieManager.setCookie('cadastro_completado', 'true', 30);
|
||||
}
|
||||
|
||||
function setCodigoCookie(codigo) {
|
||||
// Usa CookieManager em vez de cookies
|
||||
CookieManager.setCookie('index', codigo, 30);
|
||||
}
|
||||
|
||||
function checkCadastroCookie() {
|
||||
return CookieManager.getCookie('cadastro') === 'true';
|
||||
}
|
||||
|
||||
// Redirecionamento por Cookie
|
||||
if (checkCadastroCookie()) {
|
||||
if (currApp == 'form') {
|
||||
window.location.href = "play.php";
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Máscara para telefone
|
||||
const telefoneInput = document.getElementById('telefone');
|
||||
if (telefoneInput) {
|
||||
telefoneInput.addEventListener('input', maskPhone);
|
||||
}
|
||||
|
||||
// Melhorando a experiência do datepicker
|
||||
const dateInput = document.getElementById('ultima_compra');
|
||||
if (dateInput) {
|
||||
// Configurando data máxima como hoje
|
||||
const today = new Date().toISOString().split('T')[0];
|
||||
dateInput.setAttribute('max', today);
|
||||
|
||||
// Adicionando placeholder mais amigável
|
||||
dateInput.setAttribute('placeholder', 'Selecione a data');
|
||||
}
|
||||
|
||||
// Tornando os checkboxes mais responsivos ao toque
|
||||
document.querySelectorAll('.touch-checkbox').forEach(checkbox => {
|
||||
checkbox.addEventListener('click', function(e) {
|
||||
if (e.target.tagName !== 'INPUT') {
|
||||
const input = this.querySelector('input[type="checkbox"]');
|
||||
input.checked = !input.checked;
|
||||
input.dispatchEvent(new Event('change'));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Melhoria da interatividade dos checkboxes
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const touchCheckboxes = document.querySelectorAll('.touch-checkbox');
|
||||
|
||||
touchCheckboxes.forEach(checkbox => {
|
||||
checkbox.addEventListener('click', function(e) {
|
||||
const input = this.querySelector('input[type="checkbox"]');
|
||||
if (e.target.tagName.toLowerCase() !== 'input') {
|
||||
input.checked = !input.checked;
|
||||
input.dispatchEvent(new Event('change'));
|
||||
}
|
||||
});
|
||||
|
||||
// Prevenir duplo toque em dispositivos móveis
|
||||
checkbox.addEventListener('touchend', function(e) {
|
||||
e.preventDefault();
|
||||
const input = this.querySelector('input[type="checkbox"]');
|
||||
input.checked = !input.checked;
|
||||
input.dispatchEvent(new Event('change'));
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user