You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

29 lines
1.2 KiB

// 部署区域:一个应用只有「国内 / 海外」两套环境,后台一切区域选择都用这两个值。
//
// 历史遗留:部署表单早期把中文名('中国'/'美国'/'东亚'…)直接存进 app_registry.region,
// 统计表 stats_global_day.region 存的则是细分短代码(cn/us/ea/…,见 services/comm/region.go)。
// 这里统一归一:cn/中国/国内 → 国内,其余非空值 → 海外。后端收到 'hw' 会展开成「除 cn 外的全部码」。
export const REGION_CN = 'cn'
export const REGION_OVERSEAS = 'hw'
export const REGION_OPTIONS: { value: string; label: string }[] = [
{ value: REGION_CN, label: '国内' },
{ value: REGION_OVERSEAS, label: '海外' },
]
const CN_ALIASES = new Set(['cn', 'china', '中国', '国内'])
/** 把任意历史区域值归一为 'cn' | 'hw';空值返回 ''(未指定)。 */
export function normalizeRegion(r?: string): string {
const v = (r || '').trim()
if (!v) return ''
return CN_ALIASES.has(v.toLowerCase()) ? REGION_CN : REGION_OVERSEAS
}
/** 区域显示名:国内 / 海外 / 未指定。 */
export function regionLabel(r?: string): string {
const n = normalizeRegion(r)
if (!n) return '未指定'
return n === REGION_CN ? '国内' : '海外'
}