feat: 对接用户管理相关接口字段
This commit is contained in:
@@ -31,3 +31,103 @@ function buildTree(parentCode: string): CascadeOption[] {
|
||||
|
||||
/** 省市区三级联动数据 */
|
||||
export const regionOptions: CascadeOption[] = buildTree('86');
|
||||
|
||||
// ============================================================
|
||||
// 省市选项(精确到市,直辖市仅市名)
|
||||
// ============================================================
|
||||
|
||||
/** 直辖市代码 */
|
||||
const MUNICIPALITY_CODES = ['110000', '120000', '310000', '500000'];
|
||||
|
||||
/** 省市选项 */
|
||||
export interface ProvinceCityOption {
|
||||
value: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取"省-市"格式的选项列表
|
||||
* - 普通省份:格式为 "省名-市名",如 "广东省-深圳市"
|
||||
* - 直辖市:直接使用市名,如 "北京市"
|
||||
*/
|
||||
export function getProvinceCityOptions(): ProvinceCityOption[] {
|
||||
const options: ProvinceCityOption[] = [];
|
||||
const provinces = areaData['86'];
|
||||
if (!provinces) return options;
|
||||
|
||||
for (const [provinceCode, provinceName] of Object.entries(provinces)) {
|
||||
const pname = provinceName as string;
|
||||
|
||||
if (MUNICIPALITY_CODES.includes(provinceCode)) {
|
||||
options.push({ value: pname, label: pname });
|
||||
} else {
|
||||
const cities = areaData[provinceCode];
|
||||
if (cities) {
|
||||
for (const [, cityName] of Object.entries(cities)) {
|
||||
const fullName = `${pname}-${cityName}`;
|
||||
options.push({ value: fullName, label: fullName });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/** Cascader 节点 */
|
||||
export interface CascaderNode {
|
||||
value: string;
|
||||
label: string;
|
||||
children?: CascaderNode[];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取省市两级 Cascader 选项
|
||||
* - 普通省份:省 → 市,选中值 ["省名", "市名"]
|
||||
* - 直辖市:直接叶子节点,选中值 ["市名"]
|
||||
*/
|
||||
export function getProvinceCityCascaderOptions(): CascaderNode[] {
|
||||
const nodes: CascaderNode[] = [];
|
||||
const provinces = areaData['86'];
|
||||
if (!provinces) return nodes;
|
||||
|
||||
for (const [provinceCode, provinceName] of Object.entries(provinces)) {
|
||||
const pname = provinceName as string;
|
||||
|
||||
if (MUNICIPALITY_CODES.includes(provinceCode)) {
|
||||
// 直辖市:直接作为叶子节点
|
||||
nodes.push({ value: pname, label: pname });
|
||||
} else {
|
||||
const cities = areaData[provinceCode];
|
||||
if (cities) {
|
||||
const cityNodes: CascaderNode[] = Object.entries(cities).map(([, cname]) => ({
|
||||
value: cname as string,
|
||||
label: cname as string,
|
||||
}));
|
||||
nodes.push({ value: pname, label: pname, children: cityNodes });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 Cascader 选中的路径数组转为存储用的区域字符串
|
||||
* ["广东省", "深圳市"] → "广东省-深圳市"
|
||||
* ["北京市"] → "北京市"
|
||||
*/
|
||||
export function formatCascaderArea(path: string[]): string {
|
||||
if (!path || path.length === 0) return '';
|
||||
return path.join('-');
|
||||
}
|
||||
|
||||
/**
|
||||
* 将存储的区域字符串反向解析为 Cascader 路径数组
|
||||
* "广东省-深圳市" → ["广东省", "深圳市"]
|
||||
* "北京市" → ["北京市"]
|
||||
*/
|
||||
export function parseAreaToCascaderPath(area: string): string[] {
|
||||
if (!area) return [];
|
||||
return area.split('-');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user