diff --git a/app/Http/Controllers/Juil/PlanningController.php b/app/Http/Controllers/Juil/PlanningController.php index 153dbec1..cba356ba 100644 --- a/app/Http/Controllers/Juil/PlanningController.php +++ b/app/Http/Controllers/Juil/PlanningController.php @@ -3,6 +3,8 @@ namespace App\Http\Controllers\Juil; use App\Http\Controllers\Controller; +use App\Services\WeatherService; +use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\View\View; @@ -44,4 +46,11 @@ public function constructionPmis(Request $request): View|Response return view('juil.construction-pmis'); } + + public function pmisWeather(WeatherService $weatherService): JsonResponse + { + $forecasts = $weatherService->getWeeklyForecast(); + + return response()->json(['forecasts' => array_slice($forecasts, 0, 2)]); + } } diff --git a/resources/views/juil/construction-pmis.blade.php b/resources/views/juil/construction-pmis.blade.php index fe99b7de..ae3d5057 100644 --- a/resources/views/juil/construction-pmis.blade.php +++ b/resources/views/juil/construction-pmis.blade.php @@ -407,59 +407,126 @@ function FlowSafety() { 대시보드 위젯 ════════════════════════════════════════════════ */ -/* ─── 날씨 위젯 ─── */ +/* ─── 날씨 아이콘 (WeatherService 아이콘명 매핑) ─── */ +function WeatherIcon({ icon, size = 40 }) { + const s = size; + if (icon === 'sun') return ( + + + + + + + + + + ); + if (icon === 'cloud-sun') return ( + + + + + + + + + + ); + if (icon === 'rain') return ( + + + + + + + ); + if (icon === 'snow') return ( + + + + + + + ); + if (icon === 'sleet') return ( + + + + + + + + ); + // cloud (default) + return ( + + + + ); +} + +/* ─── 날씨 위젯 (WeatherService API 연동) ─── */ function WeatherWidget() { + const [forecasts, setForecasts] = useState(null); + const [loading, setLoading] = useState(true); + const today = new Date(); const dateStr = `${today.getFullYear()}.${String(today.getMonth()+1).padStart(2,'0')}.${String(today.getDate()).padStart(2,'0')}`; const dayNames = ['일','월','화','수','목','금','토']; const dayStr = dayNames[today.getDay()]; + React.useEffect(() => { + fetch('/juil/construction-pmis/weather', { headers: { 'Accept': 'application/json' } }) + .then(r => r.json()) + .then(data => { setForecasts(data.forecasts || []); setLoading(false); }) + .catch(() => setLoading(false)); + }, []); + + const labels = ['오늘', '내일']; + return (

현장 날씨

{dateStr} ({dayStr})
-
- {/* 오늘 */} -
-
오늘
-
- - - - - - - - - - - - - -
-
- 최고 - - 최저 - -
-
강수 -% / 풍속 -m/s
+ {loading ? ( +
+ + + + 날씨 불러오는 중...
- {/* 내일 */} -
-
내일
-
- - - -
-
- 최고 - - 최저 - -
-
강수 -%
+ ) : !forecasts || forecasts.length === 0 ? ( +
+ 날씨 정보를 불러올 수 없습니다
-
+ ) : ( +
+ {forecasts.map((fc, idx) => ( +
+
+ {labels[idx] || ''} +
+
+ {fc.icon ? :
} +
+ {fc.weather_text && ( +
{fc.weather_text}
+ )} +
+ 최고 {fc.tmx !== null ? `${fc.tmx}°` : '-'} + 최저 {fc.tmn !== null ? `${fc.tmn}°` : '-'} +
+ {fc.pop > 0 && ( +
+ 강수 {fc.pop}% +
+ )} +
+ ))} +
+ )}
); } diff --git a/routes/web.php b/routes/web.php index 09eeac93..f181b424 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1725,6 +1725,7 @@ Route::get('/project', [PlanningController::class, 'project'])->name('project'); Route::get('/workflow', [PlanningController::class, 'workflow'])->name('workflow'); Route::get('/construction-pmis', [PlanningController::class, 'constructionPmis'])->name('construction-pmis'); + Route::get('/construction-pmis/weather', [PlanningController::class, 'pmisWeather'])->name('construction-pmis.weather'); // 공사현장 사진대지 Route::prefix('construction-photos')->name('construction-photos.')->group(function () {