From 9289c31e3d5202c09988cd4ebc726c9698871708 Mon Sep 17 00:00:00 2001 From: liujiangyong Date: Fri, 4 Aug 2023 08:44:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E5=B1=8F=E5=A4=A9=E6=B0=94=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E5=92=8C=E9=A3=8E=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../water-prevention/components/weather.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/super-screen/client/src/sections/water-prevention/components/weather.js b/super-screen/client/src/sections/water-prevention/components/weather.js index 26c6dc7..9b01823 100644 --- a/super-screen/client/src/sections/water-prevention/components/weather.js +++ b/super-screen/client/src/sections/water-prevention/components/weather.js @@ -6,7 +6,7 @@ import { WEATHERArr, WEATHERMARGIN, ICONSMAP } from '../constants/weather' function Weather() { const [time, setTime] = useState(new Date().toLocaleTimeString()); const [weather, setWeather] = useState(''); - const [temp, setTemp] = useState(0); + const [temp, setTemp] = useState([0, 0]); useEffect(() => { const timeUpdate = setInterval(() => { @@ -18,12 +18,11 @@ function Weather() { }, []); const queryWeather = () => { - RouteRequest.get(`/query/weather?cname=南昌市`).then((doc) => { - console.log(doc, 'weather'); - const w = doc?.text || '未知'; - const temp = doc?.temp || 0; - setWeather(w); - setTemp(temp); + RouteRequest.get(`/query/weather/3d?location=101240101`).then((res) => { + if (res?.daily?.length === 3) { + setWeather(res.daily[0].textDay || '未知') + setTemp([res.daily[0].tempMin, res.daily[0].tempMax]); + } }); }; @@ -58,7 +57,7 @@ function Weather() { icon
{weather}
-
{temp}℃
+
{temp[0]}℃-{temp[1]}℃
}