天气 动图 接入

This commit is contained in:
mmc
2026-05-12 14:13:54 +08:00
parent 5c15215a99
commit 78ee2d5c09
10 changed files with 2588 additions and 18 deletions

View File

@@ -0,0 +1,23 @@
.cloud-group {
height: 80px;
}
.cloud {
font-size: 45px;
position: absolute;
}
.cloud1 {
left: 10px;
animation: floatCloud 3s ease-in-out infinite;
}
.cloud2 {
left: 60px;
animation: floatCloud 4s ease-in-out infinite;
}
@keyframes floatCloud {
0%, 100% { transform: translateX(0); }
50% { transform: translateX(10px); }
}

View File

@@ -0,0 +1,11 @@
import "./WeatherCloudy.css";
export default function WeatherCloudy() {
return (
<div className="weather-box cloudy">
<div className="cloud-group">
<span className="cloud cloud1">☁️</span>
</div>
</div>
);
}

View File

@@ -0,0 +1,23 @@
.cloud {
font-size: 50px;
position: absolute;
top: 70px;
}
.rain span {
display: inline-block;
width: 4px;
height: 20px;
background: #4A90E2;
margin: 0 2px;
animation: rainDrop 1s linear infinite;
}
@keyframes rainDrop {
0% { transform: translateY(-10px); opacity: 0; }
50% { opacity: 1; }
100% { transform: translateY(30px); opacity: 0; }
}

View File

@@ -0,0 +1,14 @@
import "./WeatherRainy.css";
export default function WeatherRainy() {
return (
<div className="weather-box rainy">
<div className="cloud">☁️</div>
<div className="rain">
{[...Array(6)].map((_, i) => (
<span key={i} style={{ animationDelay: `${i * 0.2}s` }}></span>
))}
</div>
</div>
);
}

View File

@@ -0,0 +1,58 @@
.weather-sunny {
text-align: center;
font-size: 18px;
}
.sun {
position: relative;
width: 200px;
height: 200px;
margin: 0 auto;
}
/* 太阳核心 */
.core {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 50px;
height: 50px;
background: radial-gradient(circle, #FFEB3B, #FF9800);
border-radius: 50%;
box-shadow:
0 0 30px #FFEB3B,
0 0 60px rgba(255, 193, 7, 0.6);
}
/* 光芒 */
.ray {
position: absolute;
top: 50%;
left: 50%;
width: 6px;
height: 40px;
background: linear-gradient(to top, #FFEB3B, transparent);
transform-origin: center bottom;
animation: rayPulse 1.5s ease-in-out infinite;
}
/* 错开动画,形成波浪感 */
.ray:nth-child(odd) {
animation-delay: 0.75s;
}
@keyframes rayPulse {
0% {
opacity: 0.3;
transform: var(--transform) scaleY(0.8);
}
50% {
opacity: 1;
transform: var(--transform) scaleY(1.2);
}
100% {
opacity: 0.3;
transform: var(--transform) scaleY(0.8);
}
}

View File

@@ -0,0 +1,25 @@
import "./WeatherSunny.css";
export default function WeatherSunny() {
const rays = Array.from({ length: 12 }).map((_, i) => {
const angle = i * 30; // 每根 30°
return (
<span
key={i}
className="ray"
style={{
transform: `rotate(${angle}deg) translateY(-120px)`
}}
/>
);
});
return (
<div className="weather-sunny">
<div className="sun">
{/*{rays}*/}
<div className="core"></div>
</div>
</div>
);
}

View File

@@ -0,0 +1,23 @@
import React from "react";
import PropTypes from "prop-types";
import WeatherSunny from "./WeatherSunny";
import WeatherRainy from "./WeatherRainy";
import WeatherCloudy from "./WeatherCloudy";
export default function WeatherDisplay({ type }) {
const map = {
sunny: <WeatherSunny />,
rainy: <WeatherRainy />,
cloudy: <WeatherCloudy />
};
return (
<div className="weather-icon-wrapper">
{map[type] || null}
</div>
);
}
WeatherDisplay.propTypes = {
type: PropTypes.oneOf(["sunny", "rainy", "cloudy"])
};

File diff suppressed because it is too large Load Diff

View File

@@ -95,3 +95,38 @@ export async function getWeatherData(options = {}) {
throw new Error(`天气接口调用失败:${error.message}`);
}
}
/**
* 根据天气文字返回组件用的 type
* 支持:晴 / 晴天 / 晴转多云
* 雨 / 小雨 / 中雨 / 大雨 / 雷阵雨
* 多云 / 阴
*/
export function getWeatherType(weatherText = "") {
if (!weatherText) return "cloudy"; // 兜底
const text = weatherText.trim();
// 晴天
if (text.includes("晴")) {
return "sunny";
}
// 雨天
if (
text.includes("雨") ||
text.includes("雷") ||
text.includes("暴雨")
) {
return "rainy";
}
// 多云 / 阴
if (text.includes("云") || text.includes("阴")) {
return "cloudy";
}
// 兜底
return "cloudy";
}

View File

@@ -8,7 +8,8 @@ import {
DashboardOutlined
} from '@ant-design/icons';
import { Line, Bar, Pie } from '@ant-design/charts';
import { getWeatherData } from '../lib/utils';
import { getWeatherData, getWeatherType } from '../lib/utils';
import WeatherDisplay from '../components/Weather';
@@ -29,6 +30,7 @@ export default function StationDashboard() {
humidity: 53,
report_time: "2026-03-27 12:35:08"
});
const weatherType = getWeatherType(weatherdata.weather);
// 请求天气接口
useEffect(() => {
@@ -638,27 +640,48 @@ export default function StationDashboard() {
style={{
borderRadius: 8,
boxShadow: '0 1px 2px rgba(0,0,0,0.05)',
padding: '4px 8px'
padding: '8px',
}}
bodyStyle={{ padding: 4 }}
bodyStyle={{ padding: 8 }}
>
<div style={{ display: 'flex', alignItems: 'center', position: 'relative', }}>
{/* 右侧文字 */}
<div style={{ display: 'flex', flexDirection: 'row', gap: 24, alignItems: 'center', width: "100%" }}>
<div>
<div style={{ fontSize: 24, fontWeight: 800, color: '#1890ff' }}>{weatherdata.temperature}℃</div>
<div style={{ fontSize: 14, color: '#666' }}>{weatherdata.weather}</div>
</div>
<div>
<div style={{ fontSize: 11, color: '#999' }}>湿度 {weatherdata.humidity}%</div>
<div style={{ fontSize: 11, color: '#999' }}>{weatherdata.wind_direction} {weatherdata.wind_power}</div>
<div style={{ fontSize: 11, color: '#999' }}>{weatherdata.city} | {weatherdata.district}</div>
</div>
<div
style={{
display: 'flex',
alignItems: 'center',
gap: 24,
height: '100%'
}}
>
{/* 左侧:动态天气图标 */}
<div
style={{
width: 60,
height: 60,
display: 'flex',
alignItems: 'center',
justifyContent: 'center'
}}
>
<WeatherDisplay type={weatherType} />
</div>
{/* 右侧:天气信息 */}
<div style={{ flex: 1, flexDirection: "row" }}>
<div style={{ fontSize: 28, fontWeight: 800, color: '#1890ff' }}>
{weatherdata.temperature}℃
</div>
<div>
<div style={{ fontSize: 14, color: '#333', marginBottom: 6 }}>
{weatherdata.weather}
</div>
<div style={{ fontSize: 12, color: '#666', lineHeight: 1.6 }}>
<div>湿度 {weatherdata.humidity}%</div>
<div>{weatherdata.wind_direction} {weatherdata.wind_power}</div>
<div>{weatherdata.city} · {weatherdata.district}</div>
</div>
</div>
</div>
</div>
</Card>
{/* 清洗建议 */}