feat: 优化路由 搭建赛事管理页面基础 处理部分样式问题 完成赛事列表页面搭建
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import areaData from 'china-area-data';
|
||||
|
||||
export interface CascadeOption {
|
||||
value: string;
|
||||
label: string;
|
||||
children?: CascadeOption[];
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 china-area-data 原始数据转换为 antd Cascader 所需的 options 格式
|
||||
*
|
||||
* 原始数据格式: { '86': { '110000': '北京' }, '110000': { '110100': '市辖区' }, ... }
|
||||
* 目标格式: [{ value: '110000', label: '北京', children: [...] }]
|
||||
*/
|
||||
function buildTree(parentCode: string): CascadeOption[] {
|
||||
const nodes = areaData[parentCode];
|
||||
if (!nodes) return [];
|
||||
|
||||
return Object.entries(nodes).map(([code, name]) => {
|
||||
const node: CascadeOption = {
|
||||
value: code,
|
||||
label: name as string,
|
||||
};
|
||||
const children = buildTree(code);
|
||||
if (children.length > 0) {
|
||||
node.children = children;
|
||||
}
|
||||
return node;
|
||||
});
|
||||
}
|
||||
|
||||
/** 省市区三级联动数据 */
|
||||
export const regionOptions: CascadeOption[] = buildTree('86');
|
||||
Reference in New Issue
Block a user