天气 动图 接入
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user