|
@ -6,7 +6,7 @@ import { WEATHERArr, WEATHERMARGIN, ICONSMAP } from '../constants/weather' |
|
|
function Weather() { |
|
|
function Weather() { |
|
|
const [time, setTime] = useState(new Date().toLocaleTimeString()); |
|
|
const [time, setTime] = useState(new Date().toLocaleTimeString()); |
|
|
const [weather, setWeather] = useState(''); |
|
|
const [weather, setWeather] = useState(''); |
|
|
const [temp, setTemp] = useState(0); |
|
|
const [temp, setTemp] = useState([0, 0]); |
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
const timeUpdate = setInterval(() => { |
|
|
const timeUpdate = setInterval(() => { |
|
@ -18,12 +18,11 @@ function Weather() { |
|
|
}, []); |
|
|
}, []); |
|
|
|
|
|
|
|
|
const queryWeather = () => { |
|
|
const queryWeather = () => { |
|
|
RouteRequest.get(`/query/weather?cname=南昌市`).then((doc) => { |
|
|
RouteRequest.get(`/query/weather/3d?location=101240101`).then((res) => { |
|
|
console.log(doc, 'weather'); |
|
|
if (res?.daily?.length === 3) { |
|
|
const w = doc?.text || '未知'; |
|
|
setWeather(res.daily[0].textDay || '未知') |
|
|
const temp = doc?.temp || 0; |
|
|
setTemp([res.daily[0].tempMin, res.daily[0].tempMax]); |
|
|
setWeather(w); |
|
|
} |
|
|
setTemp(temp); |
|
|
|
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -58,7 +57,7 @@ function Weather() { |
|
|
<img src={iconSrc} alt="icon" style={{ width: 43, height: 38, margin: '0 5px' }} /> |
|
|
<img src={iconSrc} alt="icon" style={{ width: 43, height: 38, margin: '0 5px' }} /> |
|
|
<div className='column2'> |
|
|
<div className='column2'> |
|
|
<div>{weather}</div> |
|
|
<div>{weather}</div> |
|
|
<div style={{ fontSize: 14 }}>{temp}℃</div> |
|
|
<div style={{ fontSize: 14 }}>{temp[0]}℃-{temp[1]}℃</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
} |
|
|
} |
|
|