fff77dac3f
Add liuyao/bazi/combined flows with shared calc and AI infrastructure, 64-gua learn routes, and update Ubuntu PM2 deployment docs for port 3130. Co-authored-by: Cursor <cursoragent@cursor.com>
51 lines
1.1 KiB
TypeScript
51 lines
1.1 KiB
TypeScript
import regionsData from "@/lib/data/regions.json";
|
|
|
|
export interface RegionNode {
|
|
name: string;
|
|
longitude: number;
|
|
children?: Record<string, RegionNode>;
|
|
}
|
|
|
|
export type RegionsData = Record<string, RegionNode>;
|
|
|
|
export const regions = regionsData as RegionsData;
|
|
|
|
export function getProvinces(): { code: string; name: string }[] {
|
|
return Object.entries(regions).map(([code, node]) => ({
|
|
code,
|
|
name: node.name,
|
|
}));
|
|
}
|
|
|
|
export function getCities(provinceCode: string): { code: string; name: string }[] {
|
|
const province = regions[provinceCode];
|
|
if (!province?.children) {
|
|
return [];
|
|
}
|
|
return Object.entries(province.children).map(([code, node]) => ({
|
|
code,
|
|
name: node.name,
|
|
}));
|
|
}
|
|
|
|
export function getRegionLocation(
|
|
provinceCode: string,
|
|
cityCode: string,
|
|
): { name: string; longitude: number } | null {
|
|
const province = regions[provinceCode];
|
|
if (!province) {
|
|
return null;
|
|
}
|
|
const city = province.children?.[cityCode];
|
|
if (city) {
|
|
return {
|
|
name: `${province.name}${city.name}`,
|
|
longitude: city.longitude,
|
|
};
|
|
}
|
|
return {
|
|
name: province.name,
|
|
longitude: province.longitude,
|
|
};
|
|
}
|