달력 날씨인데 안쓸듯..

This commit is contained in:
nevermoregb 2025-04-07 12:42:39 +09:00
parent fc32aba4ab
commit b047436e32

View File

@ -60,7 +60,7 @@
</template>
<script setup>
import { inject, onMounted, reactive, ref, watch } from 'vue';
import { inject, onMounted, reactive, ref, watch, computed } from 'vue';
import { fetchHolidays } from '@c/calendar/holiday';
import { useUserInfoStore } from '@/stores/useUserInfoStore';
import { useProjectStore } from '@/stores/useProjectStore';
@ -437,18 +437,49 @@
showModal.value = false;
};
//
// URL
const getWeatherIconUrl = iconCode => {
if (iconCode === '01d' || iconCode === '01n') {
return '/img/icons/sunny-custom.png';
}
// @2x
return `https://openweathermap.org/img/wn/${iconCode}.png`;
};
//
const getWeatherIconClass = iconCode => {
if (iconCode === '01d' || iconCode === '01n') {
return 'custom-sunny-icon';
}
return 'weather-icon';
};
// handleEventContent
const handleEventContent = item => {
if (!item.event) return null;
//
//
if (item.event.classNames?.includes('weather-event')) {
const weather = item.event.extendedProps;
return {
html: `
<div class="weather-info">
<img src="${weather.iconUrl}"
class="${weather.iconClass}"
style="width: 20px; height: 20px; display: block;" />
</div>
`,
};
}
//
if (item.event.classNames?.includes('holiday-event')) {
return {
html: `<div class="holiday-text" style="color: white;">${item.event.title}</div>`,
};
}
//
// ...
const eventType = item.event.extendedProps.type;
if (!eventType) return null;
@ -481,7 +512,40 @@
};
};
//
//
const addWeatherEvent = (date, weatherInfo) => {
calendarEvents.value.push({
start: date,
type: 'weather',
classNames: ['weather-event'],
extendedProps: {
weatherIcon: weatherInfo.icon,
iconUrl: getWeatherIconUrl(weatherInfo.icon),
iconClass: getWeatherIconClass(weatherInfo.icon),
},
});
};
// dailyWeatherList
watch(
dailyWeatherList,
newWeatherList => {
if (!newWeatherList?.length) return;
console.log(123);
//
calendarEvents.value = calendarEvents.value.filter(event => !event.classNames?.includes('weather-event'));
//
newWeatherList.forEach(weatherInfo => {
const date = $common.dateFormatter(weatherInfo.date, 'YMD');
addWeatherEvent(date, weatherInfo);
});
},
{ immediate: true },
);
// eventContent
const calendarOptions = reactive({
plugins: [dayGridPlugin, interactionPlugin],
initialView: 'dayGridMonth',
@ -500,10 +564,26 @@
dateClick: handleDateClick,
dayCellDidMount: arg => {
const dateCell = arg.el;
//
dateCell.addEventListener('mousedown', e => {
const date = $common.dateFormatter(arg.date, 'YMD');
//
const dateCellNumber = dateCell.querySelector('.fc-daygrid-day-number');
//
const weatherEvent = calendarEvents.value.find(
event => event.classNames?.includes('weather-event') && $common.dateFormatter(event.start, 'YMD') === date,
);
//
if (weatherEvent && dateCellNumber) {
const weatherIcon = document.createElement('img');
weatherIcon.src = weatherEvent.extendedProps.iconUrl;
weatherIcon.className = 'date-weather-icon';
dateCellNumber.appendChild(weatherIcon);
}
//
dateCell.addEventListener('mousedown', e => {
handleMouseDown(date, e);
});
dateCell.addEventListener('mouseup', handleMouseUp);
@ -562,7 +642,7 @@
if (!weatherStore.dailyWeatherList?.length) {
await weatherStore.getWeatherInfo();
//dailyWeatherList.value = weatherStore.dailyWeatherList;
console.log('dailyWeatherList.value: ', dailyWeatherList.value);
//console.log('dailyWeatherList.value: ', dailyWeatherList.value);
}
//
@ -607,4 +687,77 @@
::v-deep(.fc-daygrid-event-harness:has(.holiday-event)) {
width: 100% !important;
}
/* 날씨 정보 스타일 */
.weather-info {
position: absolute;
right: 4px;
top: 4px;
width: 20px;
height: 20px;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
.weather-info img,
.weather-icon,
.custom-sunny-icon {
width: 20px !important;
height: 20px !important;
min-width: 20px !important;
min-height: 20px !important;
max-width: 20px !important;
max-height: 20px !important;
object-fit: contain !important;
display: block !important;
padding: 0 !important;
margin: 0 !important;
}
/* 날씨 이벤트가 있는 셀의 스타일 조정 */
.fc-daygrid-day-events .weather-event {
position: absolute;
right: 0;
top: 0;
width: 20px !important;
height: 20px !important;
background: transparent !important;
border: none !important;
z-index: 1;
padding: 0 !important;
margin: 0 !important;
}
/* 추가적인 제어를 위한 스타일 */
.weather-event * {
max-width: 20px !important;
max-height: 20px !important;
}
/* 다른 이벤트와의 겹침 방지 */
.fc-daygrid-day-events {
position: relative;
}
/* 기존 날씨 관련 스타일은 제거하고 새로운 스타일 추가 */
.fc-daygrid-day-number {
display: flex !important;
align-items: center !important;
gap: 4px !important;
}
.date-weather-icon {
width: 16px !important;
height: 16px !important;
object-fit: contain !important;
display: inline-block !important;
vertical-align: middle !important;
}
/* 날씨 이벤트 숨기기 (이제 날짜 옆에 표시되므로) */
.weather-event {
display: none !important;
}
</style>