fix: 处理 banner配置页面相关问题
This commit is contained in:
@@ -131,3 +131,73 @@ export function parseAreaToCascaderPath(area: string): string[] {
|
||||
if (!area) return [];
|
||||
return area.split('-');
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 城市级别选项(仅市名,加"全国")
|
||||
// ============================================================
|
||||
|
||||
/** 城市 Select 选项 */
|
||||
export interface CityOption {
|
||||
value: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取仅城市名的选项列表,第一项为"全国"
|
||||
* 用于 Banner 弹窗中"所属区域"下拉选择
|
||||
* - 直辖市:直接取市名(如"北京市")
|
||||
* - 普通省份:取市名(如"深圳市")
|
||||
*/
|
||||
export function getCityOnlyOptions(): CityOption[] {
|
||||
const options: CityOption[] = [{ value: '全国', label: '全国' }];
|
||||
const provinces = areaData['86'];
|
||||
if (!provinces) return options;
|
||||
|
||||
for (const [provinceCode, provinceName] of Object.entries(provinces)) {
|
||||
if (MUNICIPALITY_CODES.includes(provinceCode)) {
|
||||
options.push({ value: provinceName as string, label: provinceName as string });
|
||||
} else {
|
||||
const cities = areaData[provinceCode];
|
||||
if (cities) {
|
||||
for (const [, cityName] of Object.entries(cities)) {
|
||||
options.push({ value: cityName as string, label: cityName as string });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据城市名反查 Cascader 路径数组
|
||||
* "深圳市" → ["广东省", "深圳市"]
|
||||
* "北京市" → ["北京市"]
|
||||
* "全国" → ["全国"]
|
||||
*/
|
||||
export function cityNameToCascaderPath(cityName: string): string[] {
|
||||
if (!cityName || cityName === '全国') return ['全国'];
|
||||
|
||||
const provinces = areaData['86'];
|
||||
if (!provinces) return [cityName];
|
||||
|
||||
for (const [provinceCode, provinceName] of Object.entries(provinces)) {
|
||||
const pname = provinceName as string;
|
||||
|
||||
if (MUNICIPALITY_CODES.includes(provinceCode)) {
|
||||
if (pname === cityName) return [pname];
|
||||
} else {
|
||||
const cities = areaData[provinceCode];
|
||||
if (cities) {
|
||||
for (const [, cname] of Object.entries(cities)) {
|
||||
if ((cname as string) === cityName) {
|
||||
return [pname, cname as string];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 兜底:找不到省份隶属,直接用市名
|
||||
return [cityName];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user