bimland/test.js

362 lines
9.3 KiB
JavaScript

const aa = [
{
id: 'ff8080818698fe5001869af6e4a40ada',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: '',
name: '完善、改造和维护安全防护设施设备支出',
code: 'A1',
indexs: 1,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: true,
iconSkin: 'defalut',
description: '',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40ae9',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: '',
name: '配备、维护、保养应急救援器材、设备支出和应急演练',
code: 'A2',
indexs: 2,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: true,
iconSkin: 'defalut',
description: '0',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40af7',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: '',
name: '重大危险源和事故隐患评估、监控和整改支出',
code: 'A3',
indexs: 3,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: true,
iconSkin: 'defalut',
description: 'null',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40afe',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: '',
name: '安全生产检查、评价、咨询和标准化建设支出',
code: 'A4',
indexs: 4,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: true,
iconSkin: 'defalut',
description: '0',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40b01',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: '',
name: '配备和更新现场作业人员安全防护用品支出',
code: 'A5',
indexs: 5,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: true,
iconSkin: 'defalut',
description: 'null',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40b03',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: '',
name: '安全生产宣传、教育、培训支出',
code: 'A6',
indexs: 6,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: true,
iconSkin: 'defalut',
description: 'null',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40b05',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: '',
name: '安全生产使用的新技术、新标准、新工艺、新装备的推广应用支出',
code: 'A7',
indexs: 7,
products: [],
amount: 0.0,
percentage: 0.04,
isChild: true,
iconSkin: 'defalut',
description: 'null',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40b07',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: '',
name: '安全设施及特种设备检测检验支出',
code: 'A8',
indexs: 8,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: true,
iconSkin: 'defalut',
description: '',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40b09',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: '',
name: '其他安全生产费用支出',
code: 'A9',
indexs: 9,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: true,
iconSkin: 'defalut',
description: 'null',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40adb',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: 'ff8080818698fe5001869af6e4a40ada',
name: '安全标志',
code: 'A1.1',
indexs: 1,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: false,
iconSkin: 'defalut',
description: 'null',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40aea',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: 'ff8080818698fe5001869af6e4a40ada',
name: '警示灯具',
code: 'A1.2',
indexs: 2,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: false,
iconSkin: 'defalut',
description: 'null',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40af8',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: 'ff8080818698fe5001869af6e4a40ada',
name: '防护栏杆',
code: 'A1.3',
indexs: 3,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: false,
iconSkin: 'defalut',
description: 'null',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40aff',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: 'ff8080818698fe5001869af6e4a40ada',
name: '防护围栏、围挡',
code: 'A1.4',
indexs: 4,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: false,
iconSkin: 'defalut',
description: 'null',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40b02',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: 'ff8080818698fe5001869af6e4a40ada',
name: '安全通道',
code: 'A1.5',
indexs: 5,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: false,
iconSkin: 'defalut',
description: 'null',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40b04',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: 'ff8080818698fe5001869af6e4a40ada',
name: '安全防护网',
code: 'A1.6',
indexs: 6,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: false,
iconSkin: 'defalut',
description: 'null',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40b06',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: 'ff8080818698fe5001869af6e4a40ada',
name: '隧道逃生管道、救生管道',
code: 'A1.7',
indexs: 7,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: false,
iconSkin: 'defalut',
description: 'null',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40b08',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: 'ff8080818698fe5001869af6e4a40ada',
name: '有毒有害气体检测仪',
code: 'A1.8',
indexs: 8,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: false,
iconSkin: 'defalut',
description: 'null',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40b0a',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: 'ff8080818698fe5001869af6e4a40ada',
name: '爆炸物专用存储箱',
code: 'A1.9',
indexs: 9,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: false,
iconSkin: 'defalut',
description: 'null',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40b0b',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: 'ff8080818698fe5001869af6e4a40ada',
name: '供配电及临时用电安全保护措施',
code: 'A1.10',
indexs: 10,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: false,
iconSkin: 'defalut',
description: 'null',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40b0c',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: 'ff8080818698fe5001869af6e4a40ada',
name: '防地质灾害设施设备',
code: 'A1.11',
indexs: 11,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: false,
iconSkin: 'defalut',
description: 'null',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
{
id: 'ff8080818698fe5001869af6e4a40b0d',
planId: 'ff8080818698fe5001869af6e4a20ad9',
parentId: 'ff8080818698fe5001869af6e4a40ada',
name: '其他临时的安全防护设施设备',
code: 'A1.12',
indexs: 12,
products: [],
amount: 0.0,
percentage: 0.0,
isChild: false,
iconSkin: 'defalut',
description: 'null',
createDate: '2023-03-01 10:18:37',
updateDate: '2023-03-01 10:18:37',
},
];
function arrayToTree(data) {
let map = {};
debugger;
for (let item of data) {
map[item.id] = item;
}
let result = []; //存放数组
for (let item of data) {
item.children = []; //给每个数组添加一个空children
if (!item.parentId) {
result.push(item); //最上级的标签
} else {
//相当于用这个 parentId 当做父Id去查找对比查找数据
let parent = map[item.parentId];
//添加到刚刚定义 children 数组中去
parent.children.push(item);
}
}
return result;
}
console.log(JSON.stringify(arrayToTree(aa)));