天气 动图 接入

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

@@ -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";
}