const res = {
"result":[
{
"logType":2,
"logFinishTime":1676797638000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676797598000,
"sort":1,
"logStartTimeFormat":"2023-02-19 17:06:38",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十六信息维护1",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:07:18",
"branchNo":null
},
{
"logType":1,
"logFinishTime":1676797692000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676797638000,
"sort":2,
"logStartTimeFormat":"2023-02-19 17:07:18",
"isBranch":0,
"logTypeDesc":"流程",
"logName":"发起流程-任务中心路由规划类",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:08:12",
"branchNo":null
},
{
"logType":2,
"logFinishTime":1676797658000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676797639000,
"sort":2,
"logStartTimeFormat":"2023-02-19 17:07:19",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十六信息维护2",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:07:38",
"branchNo":null
},
{
"logType":1,
"logFinishTime":1676797768000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676797639000,
"sort":2,
"logStartTimeFormat":"2023-02-19 17:07:19",
"isBranch":0,
"logTypeDesc":"流程",
"logName":"十六流程提交1.1欠票",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:09:28",
"branchNo":null
},
{
"logType":1,
"logFinishTime":null,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676797768000,
"sort":3,
"logStartTimeFormat":"2023-02-19 17:09:28",
"isBranch":1,
"logTypeDesc":"流程",
"logName":"十九流程关联多个",
"applyNo":"EDBG2302190000002",
"detailList":[
{
"logType":1,
"logFinishTime":null,
"logStatus":2,
"logStatusDesc":"待办进行中",
"logStartTime":1676797768000,
"sort":3,
"logStartTimeFormat":"2023-02-19 17:09:28",
"isBranch":1,
"logTypeDesc":"流程",
"logName":"十九流程关联多个",
"applyNo":"EDBG2302190000002",
"detailList":[
{
"logType":2,
"logFinishTime":null,
"logStatus":1,
"logStatusDesc":"未开始",
"logStartTime":1676797598000,
"sort":4,
"logStartTimeFormat":"2023-02-19 17:06:38",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十六信息维护1.1",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":null,
"branchNo":1
}],
"logFinishTimeFormat":null,
"branchNo":1
},
{
"logType":1,
"logFinishTime":null,
"logStatus":2,
"logStatusDesc":"待办进行中",
"logStartTime":1676797768000,
"sort":3,
"logStartTimeFormat":"2023-02-19 17:09:28",
"isBranch":1,
"logTypeDesc":"流程",
"logName":"十九流程关联多个",
"applyNo":"EDBG2302190000002",
"detailList":[
{
"logType":2,
"logFinishTime":null,
"logStatus":1,
"logStatusDesc":"未开始",
"logStartTime":1676797598000,
"sort":4,
"logStartTimeFormat":"2023-02-19 17:06:38",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十六信息维护1.2",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":null,
"branchNo":2
}],
"logFinishTimeFormat":null,
"branchNo":2
},
{
"logType":1,
"logFinishTime":null,
"logStatus":2,
"logStatusDesc":"待办进行中",
"logStartTime":1676797768000,
"sort":3,
"logStartTimeFormat":"2023-02-19 17:09:28",
"isBranch":1,
"logTypeDesc":"流程",
"logName":"十九流程关联多个",
"applyNo":"EDBG2302190000002",
"detailList":[
{
"logType":2,
"logFinishTime":null,
"logStatus":1,
"logStatusDesc":"未开始",
"logStartTime":1676797598000,
"sort":4,
"logStartTimeFormat":"2023-02-19 17:06:38",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十六信息维护1.3",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":null,
"branchNo":3
}],
"logFinishTimeFormat":null,
"branchNo":3
},
{
"logType":1,
"logFinishTime":null,
"logStatus":2,
"logStatusDesc":"待办进行中",
"logStartTime":1676797768000,
"sort":3,
"logStartTimeFormat":"2023-02-19 17:09:28",
"isBranch":1,
"logTypeDesc":"流程",
"logName":"十九流程关联多个",
"applyNo":"EDBG2302190000002",
"detailList":[
{
"logType":2,
"logFinishTime":null,
"logStatus":1,
"logStatusDesc":"未开始",
"logStartTime":1676797598000,
"sort":4,
"logStartTimeFormat":"2023-02-19 17:06:38",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十六信息维护2.1",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":null,
"branchNo":4
}],
"logFinishTimeFormat":null,
"branchNo":4
},
{
"logType":1,
"logFinishTime":1676797828000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676797768000,
"sort":3,
"logStartTimeFormat":"2023-02-19 17:09:28",
"isBranch":1,
"logTypeDesc":"流程",
"logName":"十九流程关联多个",
"applyNo":"EDBG2302190000002",
"detailList":[
{
"logType":2,
"logFinishTime":1676797987000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676797829000,
"sort":4,
"logStartTimeFormat":"2023-02-19 17:10:29",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十六信息维护2.2",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:13:07",
"branchNo":5
},
{
"logType":2,
"logFinishTime":1676798078000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676797988000,
"sort":5,
"logStartTimeFormat":"2023-02-19 17:13:08",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十六信息维护3.1",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:14:38",
"branchNo":5
},
{
"logType":2,
"logFinishTime":1676798138000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676798078000,
"sort":6,
"logStartTimeFormat":"2023-02-19 17:14:38",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十六信息维护3.2",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:15:38",
"branchNo":5
},
{
"logType":2,
"logFinishTime":1676798152000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676798138000,
"sort":7,
"logStartTimeFormat":"2023-02-19 17:15:38",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十六信息维护3.3",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:15:52",
"branchNo":5
},
{
"logType":2,
"logFinishTime":1676798167000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676798152000,
"sort":8,
"logStartTimeFormat":"2023-02-19 17:15:52",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十六信息维护3.4",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:16:07",
"branchNo":5
},
{
"logType":2,
"logFinishTime":1676798370000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676798167000,
"sort":9,
"logStartTimeFormat":"2023-02-19 17:16:07",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十九信息维护1",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:19:30",
"branchNo":5
},
{
"logType":2,
"logFinishTime":1676798385000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676798370000,
"sort":10,
"logStartTimeFormat":"2023-02-19 17:19:30",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十九信息维护2",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:19:45",
"branchNo":5
},
{
"logType":2,
"logFinishTime":1676798397000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676798385000,
"sort":11,
"logStartTimeFormat":"2023-02-19 17:19:45",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十九信息维护3",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:19:57",
"branchNo":5
},
{
"logType":2,
"logFinishTime":1676798413000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676798397000,
"sort":12,
"logStartTimeFormat":"2023-02-19 17:19:57",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十九信息维护4",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:20:13",
"branchNo":5
},
{
"logType":2,
"logFinishTime":1676798427000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676798413000,
"sort":13,
"logStartTimeFormat":"2023-02-19 17:20:13",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十九信息维护5",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:20:27",
"branchNo":5
},
{
"logType":2,
"logFinishTime":1676798442000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676798427000,
"sort":14,
"logStartTimeFormat":"2023-02-19 17:20:27",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十九线下任务1",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:20:42",
"branchNo":5
},
{
"logType":2,
"logFinishTime":1676798457000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676798442000,
"sort":15,
"logStartTimeFormat":"2023-02-19 17:20:42",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十九线下任务2",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:20:57",
"branchNo":5
},
{
"logType":2,
"logFinishTime":1676798471000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676798457000,
"sort":16,
"logStartTimeFormat":"2023-02-19 17:20:57",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十九线下任务3",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:21:11",
"branchNo":5
},
{
"logType":1,
"logFinishTime":1676798501000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676798472000,
"sort":17,
"logStartTimeFormat":"2023-02-19 17:21:12",
"isBranch":0,
"logTypeDesc":"流程",
"logName":"十七任务中心中转部盘古",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:21:41",
"branchNo":5
},
{
"logType":2,
"logFinishTime":1676798486000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676798472000,
"sort":17,
"logStartTimeFormat":"2023-02-19 17:21:12",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十九线下任务4",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:21:26",
"branchNo":5
},
{
"logType":2,
"logFinishTime":1676798515000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676798502000,
"sort":18,
"logStartTimeFormat":"2023-02-19 17:21:42",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十九线下任务5",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:21:55",
"branchNo":5
},
{
"logType":1,
"logFinishTime":1676798597000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676798515000,
"sort":19,
"logStartTimeFormat":"2023-02-19 17:21:55",
"isBranch":0,
"logTypeDesc":"流程",
"logName":"十六流程提交2.1限发、测试、管控",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:23:17",
"branchNo":5
},
{
"logType":2,
"logFinishTime":1676798529000,
"logStatus":4,
"logStatusDesc":"已完成",
"logStartTime":1676798515000,
"sort":19,
"logStartTimeFormat":"2023-02-19 17:21:55",
"isBranch":0,
"logTypeDesc":"待办",
"logName":"十六线下任务2",
"applyNo":"EDBG2302190000002",
"detailList":null,
"logFinishTimeFormat":"2023-02-19 17:22:09",
"branchNo":5
}],
"logFinishTimeFormat":"2023-02-19 17:10:28",
"branchNo":5
}],
"logFinishTimeFormat":null,
"branchNo":null
}],
"message":"操作成功",
"statusCode":"SYS000",
"status":true
}
const data = res.result;
// 第一层合并相同的sort,有detailList的代表分支块,如果分支块有logStatus为4的(索引找到一个为4的),其他隐藏,否则全部展示
// 数组按sort排序
const arrSort = data.sort((a, b) => a.sort - b.sort);
// 分组使用
const map = Array.from(new Set(data.map(v => v.sort)));
function handleDetailList(arr){
// 有detailList的代表分支块,如果分支块有logStatus为4的(索引找到一个为4的),其他隐藏,否则全部展示
const overIndex = arr.findIndex(v=>v.logStatus === 4);
const list = overIndex!==-1 ? arr.slice(overIndex,overIndex+1) : arr;
const result = list.map(v=>{
const {detailList,logName,...other} = v;
return {
...other,
logName:`分支${v.branchNo}`,
list:detailList
}
})
return result
}
function assembleDeep(arr, i = 1) {
/**
* flat 组装 树结构
* 1个根节点对象,多个list同级,多个children节点
*/
// arr有几个值,则deep几次
const deepLen = arr.length;
const filter = arrSort.filter(v => v.sort === i).map(v=>{
const {detailList,...other} = v;
const children = detailList && detailList.length ? handleDetailList(detailList) : [];
return {
...other,
children
}
})
const len = filter.length;
const {children} = filter[0]
return {
...filter[0],
list: len > 1 ? filter.slice(1) : [],
children: i < deepLen ? assembleDeep(arr,i+1) : children && children.length ? children : []
}
}
const obj = assembleDeep(map)
console.log(obj);
console