feat: 天气的映射
This commit is contained in:
@@ -59,7 +59,7 @@ const getLocalWeatherData = async () => {
|
|||||||
const res = await getLocalWeather();
|
const res = await getLocalWeather();
|
||||||
if (res && res.code === 0) {
|
if (res && res.code === 0) {
|
||||||
const { temperature, weather } = res.data;
|
const { temperature, weather } = res.data;
|
||||||
weatherText.value = `${temperature}°C ${weather}`;
|
weatherText.value = `${temperature}°C ${getWeatherEmoji(weather)}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +67,86 @@ onMounted(() => {
|
|||||||
getLocalWeatherData();
|
getLocalWeatherData();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const getWeatherEmoji = (text) => {
|
||||||
|
if (weatherTextMap[text]) return weatherTextMap[text];
|
||||||
|
if (text.includes("晴")) return "☀️";
|
||||||
|
if (text.includes("云")) return "☁️";
|
||||||
|
if (text.includes("雨")) return "🌧️";
|
||||||
|
if (text.includes("雷")) return "⛈️";
|
||||||
|
if (text.includes("雪")) return "🌨️";
|
||||||
|
if (text.includes("雾") || text.includes("霾")) return "🌫️";
|
||||||
|
if (text.includes("风")) return "🌬️";
|
||||||
|
if (text.includes("沙")) return "🌪️";
|
||||||
|
return "❓";
|
||||||
|
}
|
||||||
|
|
||||||
|
const weatherTextMap = {
|
||||||
|
// 晴 / 云
|
||||||
|
"晴": "☀️",
|
||||||
|
"少云": "🌤️",
|
||||||
|
"晴间多云": "⛅",
|
||||||
|
"多云": "☁️",
|
||||||
|
"阴": "☁️",
|
||||||
|
|
||||||
|
// 风
|
||||||
|
"有风": "🌬️",
|
||||||
|
"平静": "🍃",
|
||||||
|
"微风": "🌬️",
|
||||||
|
"和风": "🌬️",
|
||||||
|
"清风": "🌬️",
|
||||||
|
"强风/劲风": "💨",
|
||||||
|
"疾风": "💨",
|
||||||
|
"大风": "💨",
|
||||||
|
"烈风": "💨",
|
||||||
|
"风暴": "🌪️",
|
||||||
|
"狂爆风": "🌪️",
|
||||||
|
"飓风": "🌀",
|
||||||
|
"龙卷风": "🌪️",
|
||||||
|
|
||||||
|
// 雨
|
||||||
|
"阵雨": "🌦️",
|
||||||
|
"雷阵雨": "⛈️",
|
||||||
|
"雷阵雨并伴有冰雹": "⛈️",
|
||||||
|
"小雨": "🌧️",
|
||||||
|
"中雨": "🌧️",
|
||||||
|
"大雨": "🌧️",
|
||||||
|
"暴雨": "🌧️",
|
||||||
|
"大暴雨": "🌧️",
|
||||||
|
"特大暴雨": "🌧️",
|
||||||
|
"强阵雨": "🌦️",
|
||||||
|
"毛毛雨/细雨": "🌦️",
|
||||||
|
|
||||||
|
// 雪
|
||||||
|
"小雪": "🌨️",
|
||||||
|
"中雪": "🌨️",
|
||||||
|
"大雪": "❄️",
|
||||||
|
"暴雪": "❄️",
|
||||||
|
"雨夹雪": "🌨️",
|
||||||
|
"阵雪": "🌨️",
|
||||||
|
|
||||||
|
// 雾霾 / 沙尘
|
||||||
|
"雾": "🌫️",
|
||||||
|
"浓雾": "🌫️",
|
||||||
|
"强浓雾": "🌫️",
|
||||||
|
"轻雾": "🌫️",
|
||||||
|
"大雾": "🌫️",
|
||||||
|
"特强浓雾": "🌫️",
|
||||||
|
|
||||||
|
"霾": "🌫️",
|
||||||
|
"中度霾": "🌫️",
|
||||||
|
"重度霾": "🌫️",
|
||||||
|
"严重霾": "🌫️",
|
||||||
|
|
||||||
|
"扬沙": "🌪️",
|
||||||
|
"浮尘": "🌪️",
|
||||||
|
"沙尘暴": "🌪️",
|
||||||
|
"强沙尘暴": "🌪️",
|
||||||
|
|
||||||
|
// 特殊
|
||||||
|
"热": "🔥",
|
||||||
|
"冷": "🥶"
|
||||||
|
};
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
|||||||
Reference in New Issue
Block a user