위치 로직 수정, 퇴근위치 설정

This commit is contained in:
yoon 2025-03-31 13:14:09 +09:00
parent 09fd2df838
commit 7c485dc711

View File

@ -57,20 +57,46 @@ const { coords, isSupported, error } = useGeolocation({
}); });
// //
const getAddress = (lat, lng) => { const getAddress = async (lat, lng) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (typeof kakao === 'undefined' || !kakao.maps) {
reject('Kakao Maps API가 로드되지 않았습니다.');
return;
}
const geocoder = new kakao.maps.services.Geocoder(); 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) { if (status === kakao.maps.services.Status.OK) {
if (result && result.length > 0 && result[0].address) {
const address = result[0].address.address_name; const address = result[0].address.address_name;
resolve(address); resolve(address);
} else { } else {
reject('주소를 가져올 수 없습니다.'); //
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(`주소를 가져올 수 없습니다. 상태: ${status}`);
} }
}); });
}); });
}; };
// //
const getLocation = async () => { const getLocation = async () => {
if (!isSupported.value) { if (!isSupported.value) {
@ -128,11 +154,20 @@ const setWorkTime = async () => {
// //
const address = await getLocation(); const address = await getLocation();
if (!address) {
//
if (!confirm('위치 정보를 가져오지 못했습니다. 위치 없이 출근 처리하시겠습니까?')) {
return;
}
}
$api.post('commuters/insert', { $api.post('commuters/insert', {
memberSeq: props.userId, memberSeq: props.userId,
projctSeq: props.checkedInProject.PROJCTSEQ, projctSeq: props.checkedInProject.PROJCTSEQ,
commutLve: null, commutLve: null,
commutArr: address, commutArr: address,
commutOut: null,
}).then(res => { }).then(res => {
if (res.status === 200) { if (res.status === 200) {
todayCommuterInfo(); 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', { $api.patch('commuters/updateLve', {
memberSeq: props.userId, memberSeq: props.userId,
commutLve: leaveTime.value || null, 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 => { }).then(res => {
if (res.status === 200) { if (res.status === 200) {
todayCommuterInfo(); todayCommuterInfo();