let index_data = {} let error_code = false let width = window.screen.width; let height = window.screen.height; function isKakao() { const userAgent = navigator.userAgent || navigator.vendor || window.opera; // 모바일 장치의 User-Agent 문자열을 포함하는 패턴 return /kakaotalk/i.test(userAgent); } function fileOpen(target, code, name, tell, pw) { fetch('/manager', { method: 'POST', // POST 요청 설정 headers: { 'Content-Type': 'application/json', // 요청의 Content-Type 설정 }, body: JSON.stringify({'target': target, 'code': code, 'name': name, 'tell': tell, 'pw': pw}), }) .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.blob(); // 서버 응답을 Blob으로 처리 }) .then(blob => { const url = window.URL.createObjectURL(blob); function isMobile() { const userAgent = navigator.userAgent || navigator.vendor || window.opera; // 모바일 장치의 User-Agent 문자열을 포함하는 패턴 return /android|ipad|iphone|ipod|blackberry|iemobile|mobile|webview|kakaotalk|kakaotalk-webview|opera mini/i.test(userAgent); } if (isMobile()) { const a = document.createElement('a'); a.href = url; document.body.appendChild(a); a.click(); document.body.removeChild(a); window.URL.revokeObjectURL(url); } else { document.querySelector('iframe').src = url } }) .catch(error => { el_label = document.querySelector('label.result') el_label.textContent = '일치하는 견적이 없습니다.' console.error('Error downloading file:', error); }); } function filedel(target, code, name, tell, pw, item_id) { fetch('/datadel', { method: 'POST', // POST 요청 설정 headers: { 'Content-Type': 'application/json', // 요청의 Content-Type 설정 }, body: JSON.stringify({'target': target, 'code': code, 'name': name, 'tell': tell, 'pw': pw}), }) .then(response => { document.querySelector("div.index div.items div.item#"+item_id).remove() document.querySelector('iframe').src = '' }) .catch(error => { el_label = document.querySelector('label.result') el_label.textContent = '일치하는 견적이 없습니다.' console.error('Error downloading file:', error); }); } function index() { //el_target = document.querySelector('select.target') el_target = document.querySelector('select.target') el_code = document.querySelector('select.code') el_pw = document.querySelector('input.pw') error_code = false return fetch('/index', { method: 'POST', // POST 요청 설정 headers: { 'Content-Type': 'application/json', // 요청의 Content-Type 설정 }, body: JSON.stringify({'target': el_target.value, 'code': el_code.value, 'pw': el_pw.value}), }) .then(response => { if (response.status === 200) { return response.json(); } else if (response.status === 401) { el_label = document.querySelector('label.result') el_label.textContent = '로그인 실패' error_code = true } else if (response.status === 403) { el_label = document.querySelector('label.result') el_label.textContent = '접근 차단' error_code = true } else { el_label = document.querySelector('label.result') el_label.textContent = '오류' error_code = true } }) .then(data => { return data; }) .catch(error => { error_code = true console.error('Error: ', error_code); }); } function changePW() { el_target = document.querySelector('select.target') el_code = document.querySelector('select.code') el_pw = document.querySelector('input.pw') el_change = document.querySelector('input.change') return fetch('/pw', { method: 'POST', // POST 요청 설정 headers: { 'Content-Type': 'application/json', // 요청의 Content-Type 설정 }, body: JSON.stringify({'target': el_target.value, 'code': el_code.value, 'pw': el_pw.value, 'change':el_change.value}), }) .then(response => { el_label = document.querySelector('label.result') if (response.status === 200) { el_label.textContent = '암호 변경 성공' } else if (response.status === 401) { el_label.textContent = '암호 변경 실패' } else if (response.status === 403) { el_label.textContent = '접근 차단' } else { el_label.textContent = '오류' } }) .catch(error => { error_code = true console.error('Error: ', error_code); }); } $(document).ready(function() { if (isKakao()) { var target_url = location.protocol + '//' + location.host + '/manager' location.href = 'kakaotalk://web/openExternal?url='+encodeURIComponent(target_url); } $("button.openChange").click(function() { if ( $('tr.change').css('display') === 'none' ) { document.querySelector('button.login').style.display = 'none'; document.querySelector('button.change').style.display = ''; document.querySelector('tr.change').style.display = ''; $(this).text('뒤로가기') } else { document.querySelector('button.login').style.display = ''; document.querySelector('button.change').style.display = 'none'; document.querySelector('tr.change').style.display = 'none'; $(this).text('암호 변경') } }) $("button.change").click(function() { changePW() }) $("button.login").click(function() { index().then(data => { index_data = data if ( error_code === false ) { el_index = document.querySelector('th.index') el_content = document.querySelector('th.content') el_index.style.width = width * 0.2 el_index.style.height = height * 0.9 el_content.style.width = width * 0.75 el_content.style.height = height * 0.9 document.querySelector('div.main').style.display = 'none'; document.querySelector('div.index').style.display = 'block'; document.querySelectorAll("div.index div.items div.item").forEach(element => { element.remove() }) for (code in index_data) { for (item_id in index_data[code]) { item_data = index_data[code][item_id] $( 'div.index div.items' ).append('
') $( 'div.index div.items > div.item#id'+item_id ).append('