From 7c485dc7112b4d02917ccd5ecdcd18f5ecd50d93 Mon Sep 17 00:00:00 2001 From: yoon Date: Mon, 31 Mar 2025 13:14:09 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9C=84=EC=B9=98=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95,=20=ED=87=B4=EA=B7=BC=EC=9C=84=EC=B9=98=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/commuters/CommuterBtn.vue | 60 +++++++++++++++++++++--- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/src/components/commuters/CommuterBtn.vue b/src/components/commuters/CommuterBtn.vue index 026cf08..96d08e9 100644 --- a/src/components/commuters/CommuterBtn.vue +++ b/src/components/commuters/CommuterBtn.vue @@ -57,20 +57,46 @@ const { coords, isSupported, error } = useGeolocation({ }); // 주소 변환 함수 -const getAddress = (lat, lng) => { +const getAddress = async (lat, lng) => { return new Promise((resolve, reject) => { + if (typeof kakao === 'undefined' || !kakao.maps) { + reject('Kakao Maps API가 로드되지 않았습니다.'); + return; + } + const geocoder = new kakao.maps.services.Geocoder(); - geocoder.coord2Address(lat, lng, (result, status) => { + + geocoder.coord2Address(lng, lat, (result, status) => { + if (status === kakao.maps.services.Status.OK) { - const address = result[0].address.address_name; - resolve(address); + if (result && result.length > 0 && result[0].address) { + const address = result[0].address.address_name; + resolve(address); + } else { + // 결과가 있지만 주소가 없는 경우 + reject('주소 정보가 없습니다.'); + } + } else if (status === kakao.maps.services.Status.ZERO_RESULT) { + // ZERO_RESULT 상태 처리 + // 좌표로 주소를 찾지 못했을 때 도로명 주소로 시도 + geocoder.coord2RegionCode(lng, lat, (regionResult, regionStatus) => { + if (regionStatus === kakao.maps.services.Status.OK && regionResult.length > 0) { + // 행정구역 정보로 대체 + const region = regionResult[0].address_name; + resolve(`[대략적 위치] ${region}`); + } else { + // 행정구역 정보도 없는 경우 좌표 자체를 반환 + resolve(`위도: ${lat}, 경도: ${lng} (주소 정보 없음)`); + } + }); } else { - reject('주소를 가져올 수 없습니다.'); + reject(`주소를 가져올 수 없습니다. 상태: ${status}`); } }); }); }; + // 위치 정보 가져오기 함수 const getLocation = async () => { if (!isSupported.value) { @@ -128,11 +154,20 @@ const setWorkTime = async () => { // 현재 위치 주소 가져오기 const address = await getLocation(); + if (!address) { + // 주소를 가져오지 못했을 때도 계속 진행할지 사용자에게 확인 + if (!confirm('위치 정보를 가져오지 못했습니다. 위치 없이 출근 처리하시겠습니까?')) { + return; + } + } + + $api.post('commuters/insert', { memberSeq: props.userId, projctSeq: props.checkedInProject.PROJCTSEQ, commutLve: null, commutArr: address, + commutOut: null, }).then(res => { if (res.status === 200) { todayCommuterInfo(); @@ -143,11 +178,22 @@ const setWorkTime = async () => { }; // 퇴근 -const setLeaveTime = () => { +const setLeaveTime = async () => { + // 현재 위치 주소 가져오기 + const address = await getLocation(); + + if (!address) { + // 주소를 가져오지 못했을 때도 계속 진행할지 사용자에게 확인 + if (!confirm('위치 정보를 가져오지 못했습니다. 위치 없이 퇴근 처리하시겠습니까?')) { + return; + } + } + $api.patch('commuters/updateLve', { memberSeq: props.userId, commutLve: leaveTime.value || null, - projctLve: props.pendingProjectChange ? props.pendingProjectChange.projctSeq : props.checkedInProject.PROJCTSEQ + projctLve: props.pendingProjectChange ? props.pendingProjectChange.projctSeq : props.checkedInProject.PROJCTSEQ, + commutOut: address, }).then(res => { if (res.status === 200) { todayCommuterInfo();