From f1d44e7dbe32b87b95d491c85d57911069eb31a1 Mon Sep 17 00:00:00 2001 From: sansenhoshi Date: Wed, 1 Jul 2026 11:50:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A3=8E=E5=90=91=E8=AE=A1=E7=AE=97=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- weather-data-ui/src/utils/windDirection.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 weather-data-ui/src/utils/windDirection.ts diff --git a/weather-data-ui/src/utils/windDirection.ts b/weather-data-ui/src/utils/windDirection.ts new file mode 100644 index 0000000..3c7315d --- /dev/null +++ b/weather-data-ui/src/utils/windDirection.ts @@ -0,0 +1,22 @@ +/** + * 风向角度 -> 风向代码(N/NE/E/SE/S/SW/W/NW) + */ +export function windDirectionCode(deg: number | null | string): string | null { + if (deg == null || deg === "" || isNaN(Number(deg))) return null; + const d = Number(deg); + if (d < 0 || d > 360) return null; + return ["N", "NE", "E", "SE", "S", "SW", "W", "NW"][Math.floor((d + 22.5) / 45) % 8]; +} + +/** + * 风向角度 -> 风向中文标签(通过字典 wind_direction_type 映射) + * @param deg 风向角度 + * @param dicts 字典列表 + */ +export function windDirectionLabel(deg: number | null | string, dicts: any[]): string { + const code = windDirectionCode(deg); + if (!code) return "—"; // em dash + const type = dicts.find((d: any) => d.dictType === "wind_direction_type"); + const entry = type?.dataList?.find((e: any) => e.dictValue === code); + return entry?.dictLabel || code; +}