终端与时区分组逻辑微调
This commit is contained in:
@@ -31,6 +31,7 @@ import {
|
|||||||
getSignalState,
|
getSignalState,
|
||||||
resolveTradingRegionKey,
|
resolveTradingRegionKey,
|
||||||
TRADING_REGIONS,
|
TRADING_REGIONS,
|
||||||
|
detectLocalRegion,
|
||||||
} from "@/components/dashboard/scan-terminal/continent-grouping";
|
} from "@/components/dashboard/scan-terminal/continent-grouping";
|
||||||
import { MobileCityCard } from "@/components/dashboard/scan-terminal/MobileCityCard";
|
import { MobileCityCard } from "@/components/dashboard/scan-terminal/MobileCityCard";
|
||||||
import { MobileRegionTabs } from "@/components/dashboard/scan-terminal/MobileRegionTabs";
|
import { MobileRegionTabs } from "@/components/dashboard/scan-terminal/MobileRegionTabs";
|
||||||
@@ -470,6 +471,10 @@ function PolyWeatherTerminal({
|
|||||||
const [activeNavKey, setActiveNavKey] = useState<string>("contracts");
|
const [activeNavKey, setActiveNavKey] = useState<string>("contracts");
|
||||||
const [selectedRegionKey, setSelectedRegionKey] = useState<string>("east_asia");
|
const [selectedRegionKey, setSelectedRegionKey] = useState<string>("east_asia");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setSelectedRegionKey(detectLocalRegion());
|
||||||
|
}, []);
|
||||||
|
|
||||||
const NAV_ITEMS = [
|
const NAV_ITEMS = [
|
||||||
{ key: "contracts", Icon: Table2, labelEn: "Contracts", labelZh: "天气合约" },
|
{ key: "contracts", Icon: Table2, labelEn: "Contracts", labelZh: "天气合约" },
|
||||||
{ key: "markets", Icon: Activity, labelEn: "Markets", labelZh: "市场概览" },
|
{ key: "markets", Icon: Activity, labelEn: "Markets", labelZh: "市场概览" },
|
||||||
|
|||||||
@@ -12,6 +12,18 @@ export const TRADING_REGIONS = [
|
|||||||
|
|
||||||
export type TradingRegionKey = (typeof TRADING_REGIONS)[number]["key"];
|
export type TradingRegionKey = (typeof TRADING_REGIONS)[number]["key"];
|
||||||
|
|
||||||
|
/** Map browser timezone offset (hours) to the closest trading region. */
|
||||||
|
export function detectLocalRegion(): TradingRegionKey {
|
||||||
|
const offset = -new Date().getTimezoneOffset() / 60; // UTC offset in hours
|
||||||
|
if (offset >= 8) return "east_asia";
|
||||||
|
if (offset >= 7) return "southeast_asia";
|
||||||
|
if (offset >= 4.5) return "central_asia";
|
||||||
|
if (offset >= 2) return "west_asia";
|
||||||
|
if (offset >= -2) return "europe_africa";
|
||||||
|
if (offset >= -7) return "north_america";
|
||||||
|
return "south_america";
|
||||||
|
}
|
||||||
|
|
||||||
const TRADING_REGION_KEYS = new Set<string>(TRADING_REGIONS.map((region) => region.key));
|
const TRADING_REGION_KEYS = new Set<string>(TRADING_REGIONS.map((region) => region.key));
|
||||||
|
|
||||||
const CITY_REGION_FALLBACK: Record<string, TradingRegionKey> = {
|
const CITY_REGION_FALLBACK: Record<string, TradingRegionKey> = {
|
||||||
|
|||||||
Reference in New Issue
Block a user