import React, { useState, useEffect } from 'react' import { Tag, Spin, Tooltip } from 'antd' import { CloudOutlined, SunOutlined, CloudRain, ThunderboltOutlined } from '@ant-design/icons' import axios from 'axios' function Weather() { const [weather, setWeather] = useState(null) const [loading, setLoading] = useState(true) useEffect(() => { fetchWeather() }, []) const fetchWeather = async () => { try { const res = await axios.get('/api/weather/current?city=beijing') if (res.data.success) { setWeather(res.data.data) } } catch (err) { console.error('获取天气失败:', err) } finally { setLoading(false) } } const getWeatherIcon = (code) => { if (code === 0) return if ([95, 96, 99].includes(code)) return if ([61, 63, 65, 80, 81, 82].includes(code)) return return } if (loading) { return } if (!weather) { return null } return ( {weather.city} {weather.current.temp}°C {weather.current.weather} H:{weather.daily.maxTemp}° L:{weather.daily.minTemp}° ) } export default Weather