You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.3 KiB
JavaScript

5 months ago
// WeatherUtils.js
const WeatherEnum = {
0: '晴',
4: '多云',
5: '晴间多云',
6: '晴间多云',
7: '大部多云',
8: '大部多云',
9: '阴',
10: '阵雨',
11: '雷阵雨',
12: '雷阵雨伴有冰雹',
13: '小雨',
14: '中雨',
15: '大雨',
16: '暴雨',
17: '大暴雨',
18: '特大暴雨',
19: '冻雨',
20: '雨夹雪',
21: '阵雪',
22: '小雪',
23: '中雪',
24: '大雪',
25: '暴雪',
26: '浮尘',
27: '扬沙',
28: '沙尘暴',
29: '强沙尘暴',
30: '雾',
31: '霾',
32: '风',
33: '大风',
34: '飓风',
35: '热带风暴',
36: '龙卷风',
37: '冷',
38: '热',
// 0xfe: '查询更新时间',
0x99: '未知'
};
class WeatherUtils {
// 根据描述获取对应的天气编码
static getWeatherCode(description) {
for (const [code, desc] of Object.entries(WeatherEnum)) {
if (desc === description) {
return parseInt(code); // 返回对应的编码
}
}
return null; // 如果没有找到,返回 null
}
// 根据编码获取对应的天气描述
static getWeatherDescription(code) {
return WeatherEnum[code] || '未知'; // 返回对应的描述,如果没有找到返回 '未知'
}
}
// 导出工具类
module.exports = WeatherUtils;