feat: add scan dashboard components and local development configuration

This commit is contained in:
2569718930@qq.com
2026-04-24 02:14:20 +08:00
parent 79b58a8b98
commit a1faacb302
5 changed files with 82 additions and 8 deletions
+36
View File
@@ -45,6 +45,42 @@ function containsCjk(text: string) {
return /[\u3400-\u9fff]/.test(text);
}
export function normalizeTemperatureSymbol(value?: string | null) {
return String(value || "").toUpperCase().includes("F") ? "°F" : "°C";
}
export function formatTemperatureValue(
value: number | null | undefined,
symbol?: string | null,
options?: { signed?: boolean; digits?: number },
) {
const numeric = Number(value);
if (!Number.isFinite(numeric)) return "--";
const digits = options?.digits ?? 0;
const sign = options?.signed && numeric >= 0 ? "+" : "";
return `${sign}${numeric.toFixed(digits)}${normalizeTemperatureSymbol(symbol)}`;
}
export function normalizeTemperatureLabel(
label?: string | null,
fallbackSymbol?: string | null,
) {
const raw = String(label || "").trim();
if (!raw) return "";
const normalizedSymbol = normalizeTemperatureSymbol(fallbackSymbol);
let next = raw.replace(/℃/gi, "°C");
next = next.replace(/°?([CF])\b/gi, (_, unit: string) => `°${unit.toUpperCase()}`);
if (!/[°][CF]/.test(next) && /\d/.test(next)) {
next = `${next}${normalizedSymbol}`;
}
if (normalizedSymbol === "°F") {
next = next.replace(/°C/g, "°F");
} else {
next = next.replace(/°F/g, "°C");
}
return next;
}
function getLocalizedDynamicCommentary(
detail: CityDetail,
locale: Locale,