휴가 수정

This commit is contained in:
dyhj625 2025-03-10 12:52:23 +09:00
parent 3ac834dd4a
commit d5a62f832c
3 changed files with 37 additions and 25 deletions

View File

@ -58,19 +58,15 @@ const emit = defineEmits(["close"]);
// (,) // (,)
let globalCounter = 0; let globalCounter = 0;
const usedVacations = computed(() => { const usedVacations = computed(() => {
const result = []; return props.myVacations.flatMap((v) => {
props.myVacations.forEach((v) => {
const count = v.used_quota || 1; const count = v.used_quota || 1;
for (let i = 0; i < count; i++) { return Array.from({ length: count }, (_, i) => ({
result.push({ ...v,
...v, category: "used",
category: "used", code: v.LOCVACTYP,
code: v.LOCVACTYP, _expandIndex: globalCounter++,
_expandIndex: globalCounter++, }));
});
}
}); });
return result;
}); });
// //

View File

@ -100,11 +100,11 @@ if (windowWidth.value >= 1650) {
if (totalUsers <= 15) return "30px"; if (totalUsers <= 15) return "30px";
return "20px"; return "20px";
} else if (windowWidth.value >= 1024) { } else if (windowWidth.value >= 1024) {
if (totalUsers <= 10) return "35px"; if (totalUsers <= 10) return "40px";
if (totalUsers <= 15) return "30px"; if (totalUsers <= 15) return "30px";
return "20px"; return "20px";
} else { } else {
return "20px"; return "30px";
} }
}); });

View File

@ -323,13 +323,10 @@ const filteredReceivedVacations = computed(() => {
// //
async function saveVacationChanges() { async function saveVacationChanges() {
if (!hasChanges.value) return; if (!hasChanges.value) return;
const selectedDatesArray = Array.from(selectedDates.value); const selectedDatesArray = Array.from(selectedDates.value);
const vacationChangesByYear = selectedDatesArray.reduce((acc, [date, type]) => { const vacationChangesByYear = selectedDatesArray.reduce((acc, [date, type]) => {
const year = date.split("-")[0]; // YYYY-MM-DD YYYY const year = date.split("-")[0]; // YYYY-MM-DD YYYY
if (!acc[year]) acc[year] = { add: [], delete: [] }; if (!acc[year]) acc[year] = { add: [], delete: [] };
if (type !== "delete") { if (type !== "delete") {
acc[year].add.push({ date, type }); acc[year].add.push({ date, type });
} else { } else {
@ -340,23 +337,28 @@ async function saveVacationChanges() {
try { try {
for (const year of Object.keys(vacationChangesByYear)) { for (const year of Object.keys(vacationChangesByYear)) {
const vacationsToAdd = vacationChangesByYear[year].add; const vacationsToAdd = vacationChangesByYear[year].add;
// id
const vacationsToDeleteForYear = myVacations.value const vacationsToDeleteForYear = myVacations.value
.filter(vac => { .filter(vac => {
if (!vac.date) return false; if (!vac.date) return false;
const vacDate = vac.date.split("T")[0]; const vacDate = vac.date.split("T")[0];
return vacationChangesByYear[year].delete.includes(vacDate); return vacationChangesByYear[year].delete.includes(vacDate);
}) });
.map(vac => vac.id); const vacationIdsToDelete = vacationsToDeleteForYear.map(vac => vac.id);
if (vacationsToAdd.length > 0 || vacationsToDeleteForYear.length > 0) { if (vacationsToAdd.length > 0 || vacationIdsToDelete.length > 0) {
const response = await axios.post("vacation/batchUpdate", { const response = await axios.post("vacation/batchUpdate", {
add: vacationsToAdd, add: vacationsToAdd,
delete: vacationsToDeleteForYear, delete: vacationIdsToDelete,
}); });
if (response.data && response.data.status === "OK") { if (response.data && response.data.status === "OK") {
toastStore.onToast(`휴가 변경 사항이 저장되었습니다.`, 's'); toastStore.onToast(`휴가 변경 사항이 저장되었습니다.`, 's');
await fetchVacationHistory(year); // : myVacations ID
myVacations.value = myVacations.value.filter(vac => !vacationIdsToDelete.includes(vac.id));
//
const updatedVacations = await fetchVacationHistory(year);
if (updatedVacations) {
myVacations.value = updatedVacations; //
}
} else { } else {
toastStore.onToast(`휴가 변경 중 오류가 발생했습니다.`, 'e'); toastStore.onToast(`휴가 변경 중 오류가 발생했습니다.`, 'e');
} }
@ -365,6 +367,7 @@ async function saveVacationChanges() {
await fetchRemainingVacation(); await fetchRemainingVacation();
selectedDates.value.clear(); selectedDates.value.clear();
updateCalendarEvents(); updateCalendarEvents();
//
const currentDate = fullCalendarRef.value.getApi().getDate(); const currentDate = fullCalendarRef.value.getApi().getDate();
await loadCalendarData(currentDate.getFullYear(), currentDate.getMonth() + 1); await loadCalendarData(currentDate.getFullYear(), currentDate.getMonth() + 1);
} catch (error) { } catch (error) {
@ -379,8 +382,14 @@ async function fetchVacationHistory(year) {
try { try {
const response = await axios.get(`vacation/history?year=${year}`); const response = await axios.get(`vacation/history?year=${year}`);
if (response.status === 200 && response.data) { if (response.status === 200 && response.data) {
// + const newVacations = response.data.data.usedVacations || [];
myVacations.value = [...myVacations.value, ...response.data.data.usedVacations || []];
const uniqueVacations = Array.from(
new Map([...myVacations.value, ...newVacations].map(v => [`${v.date}-${v.type}`, v]))
.values()
);
myVacations.value = uniqueVacations;
} }
} catch (error) { } catch (error) {
console.error(`🚨 ${year}년 휴가 데이터 불러오기 실패:`, error); console.error(`🚨 ${year}년 휴가 데이터 불러오기 실패:`, error);
@ -474,16 +483,20 @@ function toggleHalfDay(type) {
/* 페이지 이동 시 변경 사항 확인 */ /* 페이지 이동 시 변경 사항 확인 */
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
if (hasChanges.value) { if (hasChanges.value) {
console.log('휴가!!!!!');
const answer = window.confirm("저장하지 않은 변경 사항이 있습니다. 이동하시겠습니까?"); const answer = window.confirm("저장하지 않은 변경 사항이 있습니다. 이동하시겠습니까?");
if (!answer) { if (!answer) {
return next(false); return next(false);
} }
} }
selectedDates.value.clear();
next(); next();
}); });
onBeforeUnmount(() => { onBeforeUnmount(() => {
window.removeEventListener("beforeunload", preventUnsavedChanges); window.removeEventListener("beforeunload", preventUnsavedChanges);
}); });
/* 새로고침 또는 페이지 종료 시 알림 */
function preventUnsavedChanges(event) { function preventUnsavedChanges(event) {
if (hasChanges.value) { if (hasChanges.value) {
event.preventDefault(); event.preventDefault();
@ -547,6 +560,9 @@ onMounted(async () => {
altFormat: "F Y" altFormat: "F Y"
}) })
], ],
onOpen: function() {
document.querySelector('.flatpickr-input').style.visibility = 'hidden';
},
onChange: function(selectedDatesArr, dateStr) { onChange: function(selectedDatesArr, dateStr) {
// //
fullCalendarRef.value.getApi().gotoDate(dateStr + "-01"); fullCalendarRef.value.getApi().gotoDate(dateStr + "-01");