From c1ccf0064cdf23a6e6c44588dfeda1f2e4b53b19 Mon Sep 17 00:00:00 2001 From: Li1304553726 <1304553726@qq.com> Date: Fri, 14 Nov 2025 18:55:21 +0800 Subject: [PATCH 1/2] 1 --- .../app/components/weather/WeatherDisplay.tsx | 53 +++++++++++++------ 1114/app/store/weatherStore.ts | 4 +- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/1114/app/components/weather/WeatherDisplay.tsx b/1114/app/components/weather/WeatherDisplay.tsx index c064a93..92eb7f0 100644 --- a/1114/app/components/weather/WeatherDisplay.tsx +++ b/1114/app/components/weather/WeatherDisplay.tsx @@ -1,5 +1,6 @@ import { useWeatherStore } from "@/store/weatherStore"; -import { Cloud, CloudDrizzle, CloudFog, CloudLightning, CloudMoon, CloudRain, CloudSnow, CloudSun, MapPin, Moon, Sun } from "lucide-react"; +import { Cloud, CloudDrizzle, CloudFog, CloudLightning, CloudMoon, CloudRain, CloudSnow, CloudSun, MapPin, Moon, Sun, ThermometerSun } from "lucide-react"; +import { formatTemperature } from "../lib/utils"; interface WeatherIconProps { description: string; @@ -31,23 +32,41 @@ export function WeatherDisplay(){ if (!currentWeather) return null; return ( -
-
-
-
-
-
-

{currentWeather.location.name}

-
- -
{currentWeather.location.country}
-
-
-
- {/* */} -
-
+
+
+
+ +
+
+
+

{currentWeather.location.name}

+
+ + {currentWeather.location.country}
+
+
+ +
+ +
+ + {formatTemperature(currentWeather.current.temperature)} + + °C +
+

+ {currentWeather.current.weather_descriptions[0]} +

+
+ + 体感 {formatTemperature(currentWeather.current.feelslike)}°C +
+
+
) } \ No newline at end of file diff --git a/1114/app/store/weatherStore.ts b/1114/app/store/weatherStore.ts index a12ab9e..c827f36 100644 --- a/1114/app/store/weatherStore.ts +++ b/1114/app/store/weatherStore.ts @@ -102,7 +102,7 @@ export const useWeatherStore = create()( set({currentWeather:cachedWeather.data,isLoading:false}); return; } - const weatherData = await WeatherAPI.getWeather(city); + const weatherData = await WeatherAPI.getCurrentWeather(city); set({currentWeather:weatherData,isLoading:false}); get().cacheWeather(city,weatherData); }catch(error){ @@ -115,7 +115,7 @@ export const useWeatherStore = create()( try{ set({isLoading:true,error:null}); const city = currentWeather.location.name; - const weatherData = await WeatherAPI.getWeather(city); + const weatherData = await WeatherAPI.getCurrentWeather(city); set({currentWeather:weatherData,isLoading:false}); get().cacheWeather(currentWeather.location.name,weatherData); }catch(error){ From 8b94b16caab33304718a2715ed87327382c46e11 Mon Sep 17 00:00:00 2001 From: qiuchenfan <2035024011@qq.com> Date: Fri, 14 Nov 2025 19:07:37 +0800 Subject: [PATCH 2/2] 222 --- 1114/app/components/weather/WeatherCard.tsx | 6 +++--- .../{WeatherDetailsCrid.tsx => WeatherDetailsGrid.tsx} | 5 ++++- 1114/app/components/weather/WeatherSearchForm.tsx | 4 ++-- 1114/app/routes/weather.tsx | 10 +++++----- 1114/app/services/weatherApi.ts | 2 +- 5 files changed, 15 insertions(+), 12 deletions(-) rename 1114/app/components/weather/{WeatherDetailsCrid.tsx => WeatherDetailsGrid.tsx} (94%) diff --git a/1114/app/components/weather/WeatherCard.tsx b/1114/app/components/weather/WeatherCard.tsx index a44ccc8..1f8b3af 100644 --- a/1114/app/components/weather/WeatherCard.tsx +++ b/1114/app/components/weather/WeatherCard.tsx @@ -1,6 +1,6 @@ -import { WeathersearchForm } from "@/components/weather/WeatherSearchForm"; +import { WeatherSearchForm } from "@/components/weather/WeatherSearchForm"; import { WeatherDisplay } from "@/components/weather/WeatherDisplay"; -import { WeatherDetailsGrid } from "@/components/weather/WeatherDetailsCrid"; +import { WeatherDetailsGrid } from "@/components/weather/WeatherDetailsGrid"; import { useWeatherStore } from "@/store/weatherStore"; import Cloud from "../../../assets/cloud.svg"; @@ -9,7 +9,7 @@ export function WeatherCard() { return (
- + {currentWeather ? (
diff --git a/1114/app/components/weather/WeatherDetailsCrid.tsx b/1114/app/components/weather/WeatherDetailsGrid.tsx similarity index 94% rename from 1114/app/components/weather/WeatherDetailsCrid.tsx rename to 1114/app/components/weather/WeatherDetailsGrid.tsx index 837db65..d3cbb85 100644 --- a/1114/app/components/weather/WeatherDetailsCrid.tsx +++ b/1114/app/components/weather/WeatherDetailsGrid.tsx @@ -10,7 +10,8 @@ interface WeatherInfoItemProps { subtitle?: string; } -function WeatherInfoItem({ icon, label, value, subtitle }: WeatherInfoItemProps) { +export function WeatherInfoItem({ icon, label, value, subtitle }: WeatherInfoItemProps) { + return (
@@ -28,6 +29,8 @@ function WeatherInfoItem({ icon, label, value, subtitle }: WeatherInfoItemProps) export function WeatherDetailsGrid() { + const {currentWeather} = useWeatherStore(); + if (!currentWeather) return null; <>
{ if (error) { toast.error(error) - seterror("") + setError("") } - }, [error, seterror]) + }, [error, setError]) return (
diff --git a/1114/app/services/weatherApi.ts b/1114/app/services/weatherApi.ts index e40a53a..0f2a275 100644 --- a/1114/app/services/weatherApi.ts +++ b/1114/app/services/weatherApi.ts @@ -1,5 +1,5 @@ import axios, {type AxiosInstance,AxiosError} from 'axios'; -import {WeatherData} from "@/store/weatherStore"; +import {type WeatherData} from "@/store/weatherStore"; //配置常量 const API_KEY = '5097cc3212ea9c460b01e2be936c94d5';