Browse Source

大屏天气改为和风接口

master
liujiangyong 1 year ago
parent
commit
9289c31e3d
  1. 15
      super-screen/client/src/sections/water-prevention/components/weather.js

15
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() {
<img src={iconSrc} alt="icon" style={{ width: 43, height: 38, margin: '0 5px' }} />
<div className='column2'>
<div>{weather}</div>
<div style={{ fontSize: 14 }}>{temp}</div>
<div style={{ fontSize: 14 }}>{temp[0]}-{temp[1]}</div>
</div>
</div>
}

Loading…
Cancel
Save