위치 로직 수정, 퇴근위치 설정
This commit is contained in:
parent
09fd2df838
commit
7c485dc711
@ -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();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user